Skip to main content
Hooks are JavaScript scripts that run at specific Claude Code lifecycle events — before a tool executes, after it completes, when the context is about to compact, and when a session ends. CCC ships 25 hooks that handle safety checks, cost monitoring, knowledge extraction, and session coaching without any wiring on your part. The installer copies all hooks to ~/.claude/hooks/ and registers them in your settings.json automatically.

Lifecycle events

Claude Code fires hooks at these events:
EventWhen it fires
PreToolUseBefore any tool call executes
PostToolUseAfter a tool call completes
PreCompactBefore the context window is compacted
SessionStartWhen a new Claude Code session begins
StopWhen Claude finishes a response turn
SessionEndWhen the session terminates
PostToolUseFailureWhen a tool call fails

The 25 kit-native hooks

Safety hooks (PreToolUse)

Blocks destructive commands before they run — rm -rf, DROP TABLE, force push, and other irreversible operations. Uses regex pattern matching as a best-effort safety net. Combine with your settings.json deny list for stronger protection.
Runs a TypeScript check (tsc) before every git commit. Blocks the commit if type errors exist, preventing broken code from entering your history.
Warns before multi-file bash operations — sed -i on globs, find -exec, and similar broad-scope commands — giving you a chance to review before Claude touches many files at once.

Monitoring hooks (PostToolUse)

Tracks context window usage after every tool call. Warns at approximately 70% usage and auto-saves the session so you can resume cleanly after compaction.
Creates a git stash checkpoint automatically every 10 file edits. If a session goes sideways, you have a recent rollback point.
Monitors estimated session cost. Fires alerts at approximately 0.50(around30toolcalls)and0.50 (around 30 tool calls) and 2.00 (around 60 tool calls) so you are never surprised at the end of a long session.
Captures errors and corrections during the session and appends them to tasks/lessons.md in your project. Builds a running log of what went wrong and how it was fixed.
Tracks the tool call rate across the session and predicts when you are likely to hit Claude’s rate limit. Surfaces a timing estimate so you can plan breaks.
Runs a post-edit verification pass on changed files, checking for drift between what Claude said it would do and what it actually wrote.
Logs every tool call — tool name, inputs, and timing — to a local file for cost analysis and debugging after the session.
Sends a notification when significant events occur during a session, such as a deploy completing or a long-running test suite finishing.
Generates progress updates during long-running sessions so you can see what Claude has done without scrolling through the full transcript.

Context hooks (PreCompact)

Saves session state — current working directory, git branch, modified files list, and active tasks — immediately before context compaction. After compaction, Claude resumes with the right context rather than starting blind.

Session end hooks (Stop)

Fires periodic coaching nudges at session end: skill suggestions based on what you built, workflow tips, and checkpoint reminders. Toggleable — set CC_COACH_DISABLE=1 to turn it off.
Renders a status summary at session end — what was built, files modified, cost incurred, and time elapsed.
Runs an end-of-session checklist: verifies modified files, checks for leftover console.log statements, and flags uncommitted changes.

Additional hooks

Monitors context window fill level with tiered warnings at 60%, 75%, 85%, and 90%. Disable with CC_CONTEXT_ROT_DISABLE=1.
Alerts you when any of CCC’s 19 vendor packages have published updates, so your tool set stays current.
Checks whether your CLAUDE.md is out of date compared to the latest CCC template and nudges you to refresh it.
Forwards tool use events to the OpenClaw gateway for multi-agent coordination when OpenClaw is detected.
Syncs session state bidirectionally with the OpenClaw platform after edits, writes, and bash operations.
Scans the CCC ecosystem for new techniques and improvements, feeds findings into the continuous improvement pipeline.
Automatically tracks progress against Linear issues when a Linear integration is configured.
Enforces phase gates on Linear issues — blocks advancement until defined criteria are met.

Hook configuration structure

Hooks are registered in your settings.json as entries under their lifecycle event. Here is what the structure looks like (key fields only):
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [{ "type": "command", "command": "node ~/.claude/hooks/careful-guard.js" }],
        "description": "Block destructive commands"
      }
    ],
    "PostToolUse": [
      {
        "matcher": "*",
        "hooks": [{ "type": "command", "command": "node ~/.claude/hooks/context-guard.js" }],
        "description": "Track context usage — warns at ~70%"
      },
      {
        "matcher": "Edit|Write",
        "hooks": [{ "type": "command", "command": "node ~/.claude/hooks/auto-checkpoint.js" }],
        "description": "Auto git-stash checkpoint every 10 file edits"
      }
    ],
    "PreCompact": [
      {
        "hooks": [{ "type": "command", "command": "node ~/.claude/hooks/pre-compact.js" }],
        "description": "Save session state before compaction"
      }
    ],
    "Stop": [
      {
        "hooks": [{ "type": "command", "command": "node ~/.claude/hooks/session-coach.js" }],
        "description": "Periodic coaching nudges"
      }
    ]
  }
}
The matcher field controls which tools trigger the hook. "*" fires on every tool call; "Bash" fires only on shell commands; "Edit|Write" fires on file writes.

Two hook configurations

CCC ships two ready-to-use hook configurations:
FileUse when
hooks.jsonYou have Everything Claude Code (ECC) installed — includes 34 hooks (15 kit-native + 19 ECC-inherited)
hooks-standalone.jsonYou do not have ECC — includes the 15 kit-native hooks only
The installer selects the right file automatically based on whether it detects ECC in your environment.

Environment variable controls

VariableEffect
CC_COACH_DISABLE=1Disable the session-coach nudges entirely
CC_COACH_INTERVALSet the coaching nudge interval (number of responses between nudges)
CC_NO_COLOR=1Strip all color output from hook messages
CC_NO_ANIMATION=1Disable animation effects in hook output
CC_CONTEXT_ROT_DISABLE=1Disable the context-rot-monitor tiered warnings

Writing your own hook

Hooks receive session data as JSON on stdin and must write JSON to stdout. A PreToolUse hook can block the tool call by exiting with code 2.
let data = '';
process.stdin.on('data', chunk => data += chunk);
process.stdin.on('end', () => {
  const input = JSON.parse(data);
  // your logic here
  console.log(data); // pass through unchanged
});
To activate a custom hook, add it to the appropriate lifecycle event in ~/.claude/settings.json using the same structure shown above.
The careful-guard hook is a best-effort safety net, not a security boundary. Its regex-based blocking can be bypassed. Always combine it with a settings.json deny list and OS-level file permissions for production environments.