Sitemap

Documentation is a Snapshot, Code is a River

3 min readApr 11, 2026

--

The End of Stale Documentation: Building Agentic Pre-commit Hooks with GitHub Copilot

Press enter or click to view image in full size
Documentation is a Snapshot, Code is a River

The Problem: Documentation is a Snapshot, Code is a River

We’ve all been there. You submit a pull request with a beautiful new feature, but you forget to update the README.md.

Traditional linters are great for syntax, but they are “blind” to intent. They can tell you if you missed a semicolon, but they can’t tell you if your README’s “Quick Start” guide is now a “Quick Path to a 404 Error.”

The Solution: Agentic Pre-commit Hooks

In my latest project, Agentic Pre-commit, I decided to move beyond static analysis. Instead of just checking if a file exists, we use GitHub Copilot’s CLI to perform “Agentic Audits” on every commit.

What makes it “Agentic”?

Unlike a generic script, an agentic hook doesn’t just look for patterns. It:

1. Gathers Context: It captures the actual Git diff of your staged changes.

2. Reasons Over Intent: It compares the behavior of the code changes against the *promises* made in the documentation.

3. Decides/Acts: It makes a reasoned judgment (MATCHED vs. MISMATCHED) and can even automatically patch files to fix discrepancies.

The “Smarter” README Sync

Get Benjamin Greene’s stories in your inbox

Join Medium for free to get updates from this writer.

The crown jewel of this toolkit is the `agentic-readme-sync` hook. Here is the workflow:

1. Diff Capture: The hook runs `git diff — cached` to see exactly what you’re trying to commit.

2. The Prompt: We feed that diff into Copilot with a mission: *”Does this README still accurately reflect these code changes? Focus on usage examples and architectural shifts.”*

3. Structured Response: Using the Copilot CLI’s JSON output, we parse the AI’s reasoning.

# A sneak peek at the logic
if "MATCHED" in ai_verdict and "MISMATCHED" not in ai_verdict:
print("✅ Documentation is in sync.")
else:
print(f"❌ Mismatch detected: {ai_reasoning}")

Lessons from the Trenches: The “Echo” Problem

Building this wasn’t without its challenges. One interesting hurdle was the “Echo Effect.” When calling the Copilot CLI, the tool often echoes back your prompt instructions. If your prompt says ”Reply with MATCHED or MISMATCHED,” a naive script will see both words in the response and fail.

We solved this by implementing recursive JSON parsing and a heuristic to strip the input prompt from the AI’s response before the logic gates hit. It’s a perfect example of the “glue code” required when moving from pure text to agentic pipelines.

Why This Matters

By moving the agent to the pre-commit phase, we shift-left the validation. You don’t wait for a human reviewer to point out a documentation gap in a PR; the AI catches it before the code even leaves your laptop.

Get Started

You can integrate these agentic hooks into your own workflow today. The project is open-source and leverages the standard pre-commit framework:

repos:
- repo: https://github.com/polecatworks/Agentic-pre-commit
rev: v0.1.0
hooks:
- id: agentic-readme-sync # The smarter AI sync check
- id: agentic-api-spec-check # Validates code vs. API spec

Documentation doesn’t have to be a chore — it can be an automated, AI-verified guarantee.

Built with ❤️ by the team at PolecatWorks.

--

--