I Built a Tool That Forces AI Coding Agents to Keep Documentation in Sync
Second commit passes because docs are now staged alongside code. The hook doesn't need to call any AI — it just checks whether the right files are included. The self-invocation guard is critical: i...

Source: DEV Community
Second commit passes because docs are now staged alongside code. The hook doesn't need to call any AI — it just checks whether the right files are included. The self-invocation guard is critical: if the hook tried to spawn Claude Code as a subprocess while Claude Code is already running, you'd get a deadlock. By detecting the CLAUDECODE env var and skipping all engines, the hook avoids this entirely. API Auto-Fix for Human Commits When you commit from the terminal (no CLAUDECODE env var), the hook calls the Anthropic API directly to update your docs: "autoFix": { "hook": { "mode": "blocking" }, "narrative": { "engine": "api", "model": "claude-sonnet-4-20250514" } } It reads your staged source files, reads the current ARCHITECTURE.md, sends both to the API, and writes back the updated sections. About 20 seconds and ~$0.10 per commit. The hook stages the updated docs and the commit proceeds without you doing anything. If the API is down or your key is missing, the hook degrades to adviso