agentsclimarketplace

Cc hook

Skill nq-rdl/agent-extensions/skills/cc-hook

Create, manage, and debug Claude Code hooks — user-defined commands that run at specific points in Claude Code's lifecycle for deterministic control. Use when the user asks about hooks, guardrails, pre/post tool execution, safety rules, command blocking, context injection, auto-formatting, permission auto-approval, or completion checklists for Claude Code. Also trigger on mentions of PreToolUse, PostToolUse, PermissionRequest, SessionStart, Stop, UserPromptSubmit, settings.json hooks, prompt-based or agent-based hooks, or when the user worries that hook output looks like prompt injection. Covers all five hook types (command, http, mcp_tool, prompt, agent), the full event lifecycle, the JSON output contract (permissionDecision / decision / hookSpecificOutput), exit codes, and safe context-injection patterns.From its SKILL.md

Install
npx -y skills add nq-rdl/agent-extensions --skill cc-hook

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its file declares

Copied from the file, not written here

The file declares its own license as CC-BY-4.0. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

10.0 KB, as published. Nobody here has run it

Claude Code Hooks

Hooks are user-defined commands that execute at specific points in Claude Code's lifecycle. They give deterministic control over behavior — an action always happens, rather than relying on the model to choose to run it. Use them to enforce project rules, automate repetitive tasks (formatting, logging), block dangerous operations, and inject context.

Authoritative sources, kept verbatim with links, live in references/. Read the matching reference before writing or debugging a hook — the I/O contract has changed across Claude Code versions and getting it wrong is the most common bug.


Decision tree — pick the right hook type

You want to…UseReference
Run a deterministic check/script (block, format, log)type: "command"references/claude-code.rst
Call a web service / shared endpointtype: "http"references/claude-code.rst
Call a tool on a connected MCP servertype: "mcp_tool"references/claude-code.rst
Make a yes/no judgment with a small modeltype: "prompt"references/prompt-and-agent-hooks.rst
Verify against real codebase state (run tests, read files)type: "agent" (experimental)references/prompt-and-agent-hooks.rst

prompt hooks are NOT static text. A common misconception (and a bug in old versions of this skill) is that type: "prompt" injects a fixed reminder string. It does not. It sends your prompt + the event data to a Claude model that returns {"ok": true|false, "reason": "..."}. See references/prompt-and-agent-hooks.rst.

Where hooks live

LocationScopeShareable
~/.claude/settings.jsonAll your projectsNo (your machine)
.claude/settings.jsonOne projectYes — commit it
.claude/settings.local.jsonOne projectNo — gitignored
Managed policy settingsOrganization-wideAdmin-controlled
Plugin hooks/hooks.jsonWhen plugin enabledBundled with plugin
Skill / agent frontmatterWhile that component is activeIn the component

Run /hooks in Claude Code to browse configured hooks (read-only; edit the JSON or ask Claude to change them). Set "disableAllHooks": true to turn them all off.

Configuration shape

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/check.sh",
            "if": "Bash(git *)",
            "timeout": 10
          }
        ]
      }
    ]
  }
}
  • matcher — filters which calls fire the hook. Meaning depends on the event (tool name for tool events, startup/resume/… for SessionStart, etc.). Omit to match everything. See the matcher table in references/claude-code.rst.
  • if (v2.1.85+) — filters by tool name and arguments using permission-rule syntax ("Bash(git *)", "Edit(*.ts)"). Tool events only.
  • type — command (default), http, mcp_tool, prompt, or agent.
  • timeout — seconds. Defaults: command/http/mcp_tool 10 min (30 s under UserPromptSubmit), prompt 30 s, agent 60 s.

The I/O contract (read this before writing output)

A hook reads event JSON on stdin and replies through stdout + exit code.

Exit codes (command hooks):

CodeMeaning
0No objection. stdout is parsed as JSON for structured control. For UserPromptSubmit, UserPromptExpansion, SessionStart, plain stdout is added to context.
2Blocking error. stdout/JSON ignored; stderr is fed to Claude as feedback. Effect depends on event (blocks PreToolUse, rejects a prompt, continues Stop, …). Not all events can block.
otherNon-blocking error. Transcript shows <hook> hook error + first stderr line; action proceeds.

Don't mix the two: use exit 2 + stderr or exit 0 + JSON. Claude Code ignores JSON when you exit 2.

Structured JSON output — PreToolUse permission control (current canonical form):

{
  "hookSpecificOutput": {
    "hookEventName": "PreToolUse",
    "permissionDecision": "deny",
    "permissionDecisionReason": "Use rg instead of grep"
  }
}

permissionDecision is one of allow / deny / ask (and defer in -p mode). Other events use different shapes — PostToolUse/Stop use top-level {"decision": "block", "reason": "..."}; PermissionRequest uses hookSpecificOutput.decision.behavior. The full per-event matrix is in references/output.rst. The legacy {"decision":"approve"} form for PreToolUse is superseded by permissionDecision — don't use it for new hooks.

⚠️ Hook output vs. prompt injection

This is the concern most people hit. Text returned via additionalContext (or plain stdout on SessionStart/UserPromptSubmit) is injected as a system reminder that Claude reads as plain text. If you phrase it as imperative, "out-of-band system commands," Claude's prompt-injection defenses can fire and it may surface the text to the user instead of acting on it.

  • ✅ Factual, declarative: "The deployment target is production."
  • ❌ Imperative/authoritative: "SYSTEM: You must never deploy to production."

Keep context short and factual, prefer additionalContext over raw stdout, use suppressOutput to hide noisy stdout, and never echo untrusted data unescaped. Full guidance + the strings>10k-chars behavior + terminalSequence allowlist are in references/prompt-injection.rst. Read it before writing any context-injecting hook.


Workflows

Three focused procedures live in references/workflows.rst. Load it and follow the matching one; each step points at the reference to read. These headings are stable entrypoints — a downstream Claude Code plugin maps them to /cc-hook:create, /cc-hook:debug, and /cc-hook:audit.

WorkflowUse whenAnchor
Create a hookGoing from "I want X to always happen" to a registered, tested hookworkflow-create
Debug a hookA hook doesn't fire, fires wrong, or its output is ignoredworkflow-debug
Audit hooksReviewing every hook that can run for correctness, safety, portabilityworkflow-audit

Common patterns

GoalEventExample
Block destructive shell commandsPreToolUse (Bash)assets/block-rm-rf.json
Protect sensitive filesPreToolUse (Edit/Write)assets/protect-env-files.json
Continue until tasks done (judgment)Stop (prompt)assets/prompt-hook-stop.json
Require tests/lint before stoppingStop (command)assets/stop-checklist.json
Inject safe project contextSessionStartassets/safe-context-injection.json
Auto-format edited filesPostToolUse (Edit/Write)assets/auto-format.json
Auto-approve a known promptPermissionRequestassets/auto-approve-exit-plan.json

Reference files

FileContents
references/workflows.rstThe create / debug / audit procedures, with stable anchors for plugin lenses
references/claude-code.rstCore reference — config, hook types, matchers, if, env vars, full event table
references/lifecycle.rstThe lifecycle: every event, firing order, and which events can block
references/output.rstOutput contract — exit codes, JSON schema, decision control per event
references/prompt-injection.rstSafe context injection — avoiding the prompt-injection trap, output safety, security
references/prompt-and-agent-hooks.rsttype: "prompt" and type: "agent" hooks (model-driven decisions)
references/recipes.rstCopy-paste patterns with full implementations
references/debugging.rstDebugging checklist, common errors, the Stop-hook block cap, debug log

Example files

FileWhat it does
assets/block-rm-rf.jsonDeny rm -rf via permissionDecision
assets/protect-env-files.jsonBlock edits/writes to .env files
assets/stop-checklist.jsonContinue the turn until checks pass (decision: block)
assets/prompt-hook-stop.jsonModel-judged completion check (type: prompt)
assets/safe-context-injection.jsonInject context with injection-safe phrasing
assets/auto-format.jsonRun a formatter after edits (PostToolUse)
assets/auto-approve-exit-plan.jsonAuto-approve ExitPlanMode (PermissionRequest)

Keep looking

Skills are one crate of 607,533. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.