Git pre-commit hook prevents AI coding agents from committing with stale documentation

Problem: AI coding agents commit code with outdated documentation
When working with AI coding assistants like Claude Code over multiple sessions, developers encounter a specific issue: the AI makes code changes (adding routes, refactoring components, renaming things) but doesn't update documentation files like ARCHITECTURE.md and README. This causes subsequent sessions to start with the AI reading documentation that describes code from weeks ago.
The consequences include:
- Claude hallucinating function names that no longer exist
- Referencing API endpoints that were renamed
- Suggesting patterns that contradict the current architecture
Advisory warnings don't work because when Claude is committing, nobody sees stderr output.
Solution: A blocking pre-commit hook
The developer created a Git pre-commit hook with this workflow:
- The hook knows which file changes should trigger documentation updates (configurable patterns per project)
- When Claude Code commits, the hook detects it via environment variables
- The hook skips trying to auto-fix documentation (which would cause a deadlock from spawning Claude from inside Claude)
- Instead, it exits with code 1 and displays a clear message: "docs are stale, update these files, then retry"
- Claude reads the error, updates the documentation, retries the commit, and the commit goes through
For human commits, the hook calls the Anthropic API directly and patches the relevant sections (taking approximately 20 seconds).
Every commit generates a session-context.md file with a summary of recent activity so the next session has continuity.
Implementation details
The tool is available as an npm package: @mossrussell/agent-guard
Key characteristics:
- Works with Claude Code, Cursor, Windsurf, and Copilot
- Zero dependencies
- Available at: https://www.npmjs.com/package/@mossrussell/agent-guard
📖 Read the full source: r/ClaudeAI
👀 See Also

MemAware Benchmark Tests AI Memory Beyond Keyword Search
MemAware is a benchmark with 900 questions across 3 difficulty levels that tests whether AI assistants with memory can surface relevant context when queries don't hint at it. Results show BM25 search scored 2.8% vs 0.8% with no memory, while vector search drops to 0.7% on cross-domain connections.

Multi-Agent Debate Approach Improves LLM Reasoning Quality
A developer experimented with a multi-agent debate approach using CyrcloAI, where different AI agents take on roles like analyst, critic, and synthesizer to critique each other's responses before producing a final answer, resulting in more structured and deliberate outputs.

OpenTrace: Self-Hosted Observability Server with 75+ MCP Tools
OpenTrace is a self-hosted observability server that provides logs, user analytics, and database introspection through 75+ MCP tools, running on a $4 VPS with SQLite storage and read-only Postgres connections.

Cortex: A Local Memory Layer for OpenClaw Agents with Ebbinghaus Decay
Cortex is an open-source memory tool built to solve context compaction issues in OpenClaw agents. It implements Ebbinghaus forgetting curves for fact decay, imports from files first, and runs as a single 19MB Go binary with SQLite.