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 checkWhat 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
| Event | Stop |
| Scope | project |
| Platforms | macos, linux |
| Timeout | 10s |
| Requires | jq |
| Failure mode | observe |
| Verified against | Claude Code hooks reference, event/matcher schema checked 2026-09-10 |
| Test status | needs 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
- Save the script to .claude/hooks/compact-audit-trail.sh and chmod +x it.
- Add .claude/stop-audit.jsonl to .gitignore if you do not want it committed.
- Add the config fragment to .claude/settings.json.
Test it
- Positive: run one turn, then check .claude/stop-audit.jsonl has a new JSON line.
- Negative: the file should contain no prompts or tool inputs - verify the line shape.
Sources
- Claude Code hooks reference (checked 2026-09-10)
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 checkPro Pack (later)
Framework bundles, cross-platform scripts, tested blocking policies, and a test harness. Free recipes and the generator stay free.
Waitlist opens soon.