Dev.to
7/26/2026

How Claude Code Detects Its Own Weekly Rot and Repairs Itself
Short summary
A developer shares a three-layer weekly self-audit script (cc-self-audit.sh) that detects quiet degradation in a Claude Code environment — context bloat from rules/MEMORY.md, unarchived agent files, hook spam, frustration signals, and tool failures. When any of five metrics crosses a threshold, the script pipes a repair prompt into claude -p with restricted tools, then independently re-measures to verify the fix rather than trusting self-reporting. The system runs via launchd on a weekly schedule, logs every change with revert instructions, and escalates to a human via Discord when auto-repair leaves residual issues.
- •Five-metric weekly audit detects Claude Code context bloat, agent file accumulation, hook spam, frustration words, and tool errors
- •Auto-repair delegates to claude -p with narrowed tool permissions, then independently re-verifies metrics instead of trusting self-report
- •Every change is logged with revert instructions; unresolved violations escalate to human via Discord notification
Generated with AI, which can make mistakes.
Is this a good recommendation for you?



