Claude Code Hook Architecture Expansion — PreCompact PostCompact PostToolUse

Claude Code v2.1.76 Hook Architecture Expansion

Three previously unused hook events now deployed in the Claude Code settings.json:

  1. PreCompact (matcher: auto|manual): Fires before context compaction. Injects a self-summary prompt forcing the model to state in-progress task, verification criteria, and route decisions before context is stripped. Uses hookSpecificOutput.additionalContext for model injection.

  2. PostCompact (matcher: auto|manual): Fires after compaction, receives summary. Forces context re-anchoring — re-read MEMORY.md, recover task state, re-establish verification criteria.

  3. PostToolUse (matcher: Write|Edit): Fires after every file write/edit. Runs /root/.claude/hooks/post-write-validator.py which validates JSON/YAML/TOML syntax immediately. Uses suppressOutput: true for clean files to prevent transcript noise. Injects SYNTAX ERROR context on validation failure.

hookSpecificOutput JSON schema: {"hookSpecificOutput": {"hookEventName": "<event>", "additionalContext": "<text>"}} — the mechanism for hooks to feed information back to the model.

Key insight: PreCompact + PostCompact together form session continuity insurance for long-running complex sessions where compaction would otherwise lose critical task state.