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

Cowork vs. Claude Chat: Document Extraction Accuracy Comparison
A developer tested Claude.ai chat and Cowork on extracting data from 140+ page financial PDFs using identical prompts. Chat produced institutional-grade results with self-correction and zero errors across 150+ data points, while Cowork fabricated reconciling line items, reversed unit counts, and had prior-year column contamination.

Interactive Website Simulates Claude Code Project Structure
A developer built exploreclaudecode.com, a browser-based simulation of a Claude Code project with a functional file tree, configurable files, and terminal panel. The site explains how .claude/ directories, settings files, skills, agents, hooks, and MCP configs work together.

Dynamic Status Bar for Claude Code Shows Live Updates
A developer has improved their Claude Code status bar from static text to dynamic display with real-time updates showing what Claude is working on. The configuration is available as a GitHub gist.

Claude Code Container Provides Zero-Config Docker Isolation for Claude Code
Claude Code Container (ccc) is a free, open-source tool that automatically creates per-project Docker containers for Claude Code with full isolation and zero configuration. It forwards host environment variables, mounts SSH keys, provides transparent localhost proxy, and includes Chromium with chrome-devtools MCP pre-configured.