Fix: auto-heal respects install mode
If you installed Token Optimizer via install.sh and later switched to the marketplace plugin (or ran both side-by-side), every hook was firing twice per event — settings.json had a copy of what the plugin already provides. v5.0.2 fixes this.
What is new
ensure-healthnow branches on install mode. Plugin users get a cleanup pass that removes duplicate hooks from settings.json. Script-install users keep the existing add-missing-hooks behavior.measure.py cleanup-duplicate-hooks— new manual command (with--dry-run) so you can trigger the cleanup yourself anytime.- Dedup preserves customizations. Only hook commands whose
(event, matcher, identity)tuple exactly match an entry in pluginhooks.jsonare removed. Custom flags, wrapper scripts, and third-party hooks in the same group are left untouched.
Safety
- Atomic writes via the existing
_write_settings_atomic(file lock + tempfile + rename) - Refuses to run unless the marketplace plugin is actually installed
- Refuses to write when
settings.jsonappears corrupted - 24h throttle on the SessionStart path so auto-heal stays quiet
- Isinstance guards on every walk — malformed hooks.json cannot crash the cleanup
Upgrade path
Plugin users get the fix automatically via /plugin update. The cleanup runs once on the next SessionStart after the throttle window and prints [Token Optimizer] Removed N duplicate hook(s) when it clears legacy state. Restart Claude Code once afterward to fully apply.
Version alignment
.claude-plugin/plugin.json→ 5.0.2.claude-plugin/marketplace.json→ 5.0.2- Tag
v5.0.2