Claude Hookbook

Hooks / workflow

Compact audit trail on stop

Appends a one-line JSON record to a local audit log every time Claude finishes a turn.

Stoplow riskneeds manual check

What it does

Fires on Stop and appends {timestamp, session_id, cwd} to .claude/stop-audit.jsonl. Enough to reconstruct when sessions happened and where, without parsing the transcript (which lags during the Stop event - do not read it for the final answer). Redact-minded: no prompts, no tool inputs, nothing sensitive.

When it runs

EventStop
Scopeproject
Platformsmacos, linux
Timeout10s
Requiresjq
Failure modeobserve
Verified againstClaude Code hooks reference, event/matcher schema checked 2026-09-10
Test statusneeds manual check - run the test steps below before relying on it

Config

Merge this into .claude/settings.json - or use the generator to combine hooks.

{
  "hooks": {
    "Stop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/compact-audit-trail.sh",
            "timeout": 10
          }
        ]
      }
    ]
  }
}

Script

Save as .claude/hooks/compact-audit-trail.sh and chmod +x it.

#!/bin/bash
# compact-audit-trail: one JSON line per completed turn.
set -u
input=$(cat)
session=$(printf '%s' "$input" | jq -r '.session_id // "unknown"')
cwd=$(printf '%s' "$input" | jq -r '.cwd // "unknown"')
log="${CLAUDE_PROJECT_DIR:-.}/.claude/stop-audit.jsonl"
mkdir -p "$(dirname "$log")"
jq -n --arg ts "$(date -u +%Y-%m-%dT%H:%M:%SZ)" --arg s "$session" --arg c "$cwd"   '{ts: $ts, session: $s, cwd: $c}' >> "$log"
exit 0

Install

  1. Save the script to .claude/hooks/compact-audit-trail.sh and chmod +x it.
  2. Add .claude/stop-audit.jsonl to .gitignore if you do not want it committed.
  3. Add the config fragment to .claude/settings.json.

Test it

Sources

Related hooks

Log tool failures for debugging

Writes a structured JSONL record whenever a Bash, Edit, or Write call fails - the debugging trail you wish you had last week.

PostToolUseFailureBash|Edit|Writelow riskneeds manual check

Pro Pack (later)

Framework bundles, cross-platform scripts, tested blocking policies, and a test harness. Free recipes and the generator stay free.

Waitlist opens soon.