hook-authoring

hook-authoring is a skill for Claude Code from kouroshez/coding-os. It costs 105 tokens per session (2,913 once invoked), scanned A, original, Apache-2.0.

Project guidance for creating coding-agent hooks: scripts that run when particular agent events occur. It covers Bash hooks, Python helpers, registration, environment variables, and event matching.

In plain words
What is it for?
Use it when adding or changing hook scripts, hook helper programs, hook registrations, or adapter hook capabilities.
Why use it?
It helps hooks work across different coding agents and projects instead of relying on one agent's private folder layout. Consistent registration also reduces the risk of breaking several projects at once.

Skill for Claude Code

Written for Claude Code: PreToolUse hook event. Also seen: positional $N argument; mentions Codex.

Needs its repository: it runs a file that does not travel with it, so clone the repository first. The line is bash src/core/hooks/write-state.sh "$COS_AGENT_DIR/.thinking_os-gate" "COMPLICATED 3".

Good fit Use it when adding or changing hook scripts, hook helper programs, hook registrations, or adapter hook capabilities.

Compare 6 skills from other repositories ↓
Install

Getting it into your agent

It runs from inside its repository, so the clone comes first — what it calls does not travel with the file alone.

Clone the repo
git clone --depth 1 https://github.com/kouroshez/coding-os
agentmods
npx agentmods add skills/kouroshez/coding-os/hook-authoring

Made for: Claude Code.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for hook-authoring

README.md
[![agentmods](https://agentmods.dev/badge/skills/kouroshez/coding-os/hook-authoring/github.svg)](https://agentmods.dev/skills/kouroshez/coding-os/hook-authoring)
Your own site
<a href="https://agentmods.dev/skills/kouroshez/coding-os/hook-authoring"><img src="https://agentmods.dev/badge/skills/kouroshez/coding-os/hook-authoring/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for hook-authoring

Your own site · 80×15
<a href="https://agentmods.dev/skills/kouroshez/coding-os/hook-authoring"><img src="https://agentmods.dev/badge/skills/kouroshez/coding-os/hook-authoring.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 105 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,913 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00105 $0.02913
Opus 5.5 $0.00042 $0.01165
Sonnet 5.5 $0.00021 $0.00583
Haiku 4.5 $0.00011 $0.00291

Measured 28d ago against content hash cc502cb29c04, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

hook-authoring scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 28d ago.

The scan reads SKILL.md. This mod also ships 1 executable file (scripts/new_hook.sh), listed below but not scanned — reading those needs a real analyzer, not pattern matching.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Runs shell commandslowCapability

Expected in a hook, worth knowing in a rule or an instructions file.

proc = subprocess.run(
src/templates/meta/skills/hook-authoring/SKILL.md · 293 lines

How it starts

The opening of the file, as written. The whole thing — 293 lines — stays where its author put it; the contents beside it link to each section on GitHub.

hook-authoring

Purpose: Every hook in src/core/hooks/ propagates via live symlinks to every consumer project that registers any adapter. A buggy hook breaks N projects at once. The same shape, every time, keeps the ~50 hooks coherent.

Read when: editing files matching:

  • src/core/hooks/*.sh — hook scripts.
  • src/core/hooks/_helpers/*.py — Python helpers invoked by hooks.
  • src/core/hooks/registry.yaml — the SSOT for hook registration.
  • src/adapters/<id>/adapter.yaml (hook_capabilities block) — runtime capability filter.

Skip when: editing hook tests, runtime presence files in .coding-os/, generated adapter templates.

The Three Hard Contracts

Every hook MUST satisfy:

1. Source cos-env.sh (Rule 3)

The first non-comment lines of every hook:

#!/usr/bin/env bash
# What this hook does, one line.
set -euo pipefail

source "$(dirname "$0")/cos-env.sh" 2>/dev/null || true

cos-env.sh exports $COS_STATE_DIR, $COS_AGENT, $COS_AGENT_DIR, $COS_DB_PATH, etc. Without it, the hook will reach for hardcoded .claude/ paths and break on Codex/Cursor.

2. Never hardcode .claude/ (Rule 1, P2)

# WRONG
state_file=".claude/state/something"

# RIGHT
state_file="$COS_AGENT_DIR/something"
# or, if it's session-shared across agents:
state_file="$COS_STATE_DIR/something"

The block-hardcoded-literals.sh hook audits the diff and blocks .claude/ literals in src/core/**.

3. Register in registry.yaml (Rule 10, SSOT)

A new hook file is invisible until registered. Add an entry to src/core/hooks/registry.yaml:

- id: my-new-hook
  script: my-new-hook.sh
  event: PreToolUse        # PreToolUse | PostToolUse | UserPromptSubmit | Stop | SessionStart | PostToolUseFailure | SubagentStart | SubagentStop
  matcher: "Write|Edit"    # tool matcher (event-specific) — empty = match-all where allowed
  phase: gate              # gate | observation | enforcement | telemetry
  category: governance     # documentation | governance | safety | telemetry | task | skill | graph | ...
  description: "One line — what the hook does."
  blocking: true           # exit 2 blocks the tool call; false = soft warn only
  adapters: ["claude", "codex", "cursor"]  # which adapters to render this hook into

Read the full file on GitHub · 293 lines

Files

What ships with it

2 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 28d ago Changed cc502cb29c04
  2. 3mo ago First seen · 293 lines · 105 tokens per session scan A fbe1ef3853db

Subscribe to this mod's changes

hook-authoring is a skill published in the GitHub repository kouroshez/coding-os (7 stars, last pushed 4d ago), licensed Apache-2.0. It adds 105 tokens to every session and 2,913 once invoked, about $0.0004 per session on Opus 5.5. A static security scan graded it A with 1 finding (runs shell commands). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.

Related

hook-authoring compared with skills from other repositories

hook-authoring next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
hook-authoringkouroshez/coding-osSkill74d agoApache-2.0A105Claude Code
graphifyGraphify-Labs/graphifySkill157kyesterdayApache-2.0B76Claude Code
graph-mutation-planpotpie-ai/potpieSkill5.8kyesterdayApache-2.0A22Claude Code, Codex
write-a-speczj-unicom-ai/UniEmployeeSkill920yesterdayMITA62OpenCode
tencent-ima-wikizj-unicom-ai/UniEmployeeSkill920yesterdayMITA127Claude Code, Codex
hr-assistantzj-unicom-ai/UniEmployeeSkill920yesterdayMITA45Claude Code, Codex
neural-memorynhadaututtheky/neural-memorySkill2464d agoMITA125Claude Code