Skip to content

Add hooks-based real-time waste monitor#26

Merged
lgriffin merged 1 commit into
mainfrom
hooks-waste-guidance
May 20, 2026
Merged

Add hooks-based real-time waste monitor#26
lgriffin merged 1 commit into
mainfrom
hooks-waste-guidance

Conversation

@lgriffin

Copy link
Copy Markdown
Owner

Summary

  • Adds ter hook monitor CLI subcommand that acts as a Claude Code PostToolUse hook handler
  • Detects 5 waste patterns in real-time (bash antipatterns, repetitive reads, edit fragmentation, duplicate tool calls, repeated commands) using pure stdlib — no embeddings, starts in milliseconds
  • Returns additionalContext (guidance for Claude) and systemMessage (notification for the user) when waste is detected
  • Includes SessionStart hook example so users see "TER Waste Monitor active" on launch
  • 61 unit tests, all passing

How to use

Add to any project's .claude/settings.json:

{
  "hooks": {
    "SessionStart": [{"hooks": [{"type": "command", "command": "python -c \"import json; print(json.dumps({'systemMessage': 'TER Waste Monitor active'}))\"", "timeout": 5}]}],
    "PostToolUse": [{"matcher": "Bash|Read|Edit|Write|Glob|Grep", "hooks": [{"type": "command", "command": "ter hook monitor", "timeout": 15, "statusMessage": "TER checking for waste..."}]}]
  }
}

See docs/hooks-guide.md for full setup, threshold tuning, and troubleshooting.

Test plan

  • pytest tests/unit/test_hook_monitor.py — 61 tests passing
  • ruff check — clean
  • Manual end-to-end: pipe hook JSON through ter hook monitor, verify output
  • Tested in live Claude Code session on separate project (eveomni) — SessionStart message confirmed visible

🤖 Generated with Claude Code

Adds `ter hook monitor` CLI subcommand that runs as a Claude Code
PostToolUse hook, detecting waste patterns (bash antipatterns,
repetitive reads, edit fragmentation, duplicate tool calls, repeated
commands) and injecting guidance back into Claude's context via
additionalContext + user-visible systemMessage notifications.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@lgriffin lgriffin merged commit b429449 into main May 20, 2026
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant