When you write code with autonomous agents like Claude Code or Cursor, instructions in AGENTS.md quickly erode due to context drift. Inevitably, the model starts slipping in banned calls like console.log instead of using your project's logging wrappers.
Geoffrey Huntley proposed replacing polite text requests with deterministic git pre-commit hooks. The script scans git diff --cached, blocks the commit, and throws a strict fix instruction back at the agent:
#!/usr/bin/env bash
VIOLATIONS=$(git diff --cached -U0 | grep -E "^\+[^+]" | grep -E "(import.*(winston|pino)|console\.log)" || true)
if [ -n "$VIOLATIONS" ]; then
echo "❌ ERROR: Forbidden call! Use import { logger } from \"@/lib/diagnostics\"" >&2
exit 1
fi
The hook installation is wired right into the project manifest:
{
"scripts": {
"prepare": "husky install || cp scripts/pre-commit .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit"
}
}
When a compiler or git hook rejects a change, the agent treats it as a hard environment contract and immediately rewrites the diff with zero human intervention.
