mirror of
https://github.com/benjitaylor/agentation.git
synced 2026-09-14 20:06:45 +08:00
Agentation Hook for Claude Code
This hook automatically injects pending UI annotations into Claude's context on every user message.
Quick Setup
Option 1: One-liner (recommended)
Add to your project's .claude/settings.json:
{
"hooks": {
"UserPromptSubmit": [
{
"type": "command",
"command": "curl -sf --connect-timeout 1 http://localhost:4747/pending 2>/dev/null | python3 -c \"import sys,json;d=json.load(sys.stdin);c=d['count'];exit(0)if c==0 else[print(f'\\n=== AGENTATION: {c} UI annotations ===\\n'),*[print(f\\\"[{i+1}] {a['element']}\\n {a['comment']}\\n\\\")for i,a in enumerate(d['annotations'])],print('=== END ===\\n')]\" 2>/dev/null;exit 0"
}
]
}
}
Option 2: Shell Script (more detailed output)
- Copy
check-agentation.shto your project or a location in your PATH - Add to
.claude/settings.json:
{
"hooks": {
"UserPromptSubmit": [
{
"type": "command",
"command": "/path/to/check-agentation.sh"
}
]
}
}
Option 3: Global Settings
Add to ~/.claude/settings.json to enable for all projects:
{
"hooks": {
"UserPromptSubmit": [
{
"type": "command",
"command": "curl -sf --connect-timeout 1 http://localhost:4747/pending 2>/dev/null | python3 -c \"import sys,json;d=json.load(sys.stdin);c=d['count'];exit(0)if c==0 else[print(f'\\n=== AGENTATION: {c} UI annotations ===\\n'),*[print(f\\\"[{i+1}] {a['element']}\\n {a['comment']}\\n\\\")for i,a in enumerate(d['annotations'])],print('=== END ===\\n')]\" 2>/dev/null;exit 0"
}
]
}
}
How It Works
- On every user message, the hook runs
- It calls
http://localhost:4747/pending(the agentation server) - If there are pending annotations (count > 0), it formats and outputs them
- If no pending annotations or server not running, outputs nothing (silent)
Requirements
- Agentation server running (
npx agentation-mcp serveror integrated in your app) - Python 3 (for JSON parsing - comes with macOS/most Linux)
- curl (standard on most systems)
Example Output
When there are pending annotations, Claude sees:
=== AGENTATION FEEDBACK (2 pending) ===
[1] button.submit-btn
Comment: This button should be disabled during loading
[2] div.error-message
Comment: Error text is hard to read, needs more contrast
Address these UI issues.
=== END ===
When no annotations are pending, the hook outputs nothing.