Oscillation detector hook
Coined hereA Claude Code PostToolUse hook that detects edit-thrashing — the agent flipping the same lines back and forth across iterations — by hashing recent diffs in a sliding window and stopping the session when oscillation is detected.
Edit-thrashing is the failure mode where an agent’s last three edits cancel each other out — A → B → A again, often because two test fixtures disagree and the agent cannot pick a side. The oscillation detector hook hashes diffs in a sliding window over the last N PostToolUse events and emits a Stop signal when the same hash recurs.
Placeholder body. Replace with the full glossary entry per playbook §9. Note: as of April 2026, no public prior art exists for this exact pattern in the Claude Code ecosystem — this is a moat-keyword entry.
When to use
- Long agentic sessions where token budget is at risk of being burned in a thrash loop.
- Test-first workflows where conflicting fixtures expose the agent to oscillation.
Distinguish from
A simple step-count guardrail caps total iterations regardless of usefulness. The oscillation detector specifically catches non-converging iteration — the agent making changes but not progressing.