feat: add PostToolUse hook to auto-trigger readme-documentarian

Adds a Bash PostToolUse hook that detects the prek documentation audit
warning and injects additionalContext into Claude's session, prompting
it to invoke the readme-documentarian agent automatically.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Justin Bollinger
2026-02-20 16:33:12 -05:00
parent d51158c1d3
commit 61494c2721
2 changed files with 38 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
#!/bin/bash
# PostToolUse hook: detects the documentation audit warning from prek post-commit
# hooks and injects a prompt for Claude to invoke the readme-documentarian agent.
set -euo pipefail
input=$(cat)
stdout=$(echo "$input" | python3 -c "
import sys, json
try:
d = json.load(sys.stdin)
resp = d.get('tool_response', {})
if isinstance(resp, dict):
print(resp.get('stdout', ''))
else:
print(str(resp))
except Exception:
pass
")
if echo "$stdout" | grep -q '\[Documentation Audit\].*documentation was not updated'; then
printf '{"additionalContext": "The post-commit documentation audit flagged that code changed but README.md was not updated. Invoke the readme-documentarian agent now to review the recent changes and update the documentation."}\n'
fi

15
.claude/settings.json Normal file
View File

@@ -0,0 +1,15 @@
{
"hooks": {
"PostToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": ".claude/hooks/doc-audit-trigger.sh"
}
]
}
]
}
}