claude-optimizer
A small, opinionated Claude Code plugin that fixes the four things that go wrong in long sessions:
- Lost context — Claude forgets what was decided 20 messages ago.
- Token bloat — boilerplate preamble/postamble eats budget without adding value.
- Drift — Claude wanders off the original task into related-but-unrequested work.
- False completions — "done" before tests, types, or lints pass.
It does this with nine skills, eight hook scripts, two slash commands, and four plain-text state files. Local-only. No daemon, no database, no network calls.
What's inside
claude-optimizer/
├── .claude-plugin/plugin.json
├── skills/
│ ├── cm-checkpoint/ # write-side: PROGRESS/TASKS/DECISIONS/MEMORY + task ledger
│ ├── cm-session-resume/ # read-side: what to do at session start
│ ├── cm-token-discipline/ # output-bloat rules
│ ├── cm-quality-gate/ # checks before "done"
│ ├── cm-secret-hygiene/ # what files Claude must never read or log
│ └── … # cm-issue-driven-workflow, cm-multi-plan, cm-research-first, cm-decompose
├── hooks/hooks.json # SessionStart, PostToolUse, Stop, SessionEnd
├── scripts/
│ ├── init_state.sh # creates .claude/state/ safely
│ ├── scan_secrets.sh # detects leaked credentials in state files
│ ├── session_start.sh, post_edit.sh, stop.sh, session_end.sh
├── commands/ # /cm:status, /cm:checkpoint
├── templates/gitignore-snippet.txt
├── docs/
│ ├── ARCHITECTURE.md
│ └── UPSTREAM.md
├── LICENSE # MIT
├── SECURITY.md
└── .gitignore
State files (created on first session)
your-project/.claude/state/
├── MEMORY.md # stable project facts
├── DECISIONS.md # one-liner architectural decisions, dated
├── PROGRESS.md # rolling work log, newest first
├── TASKS.md # explicit task ledger with status + steps
├── archive/ # auto-rotated old TASKS-YYYY-MM.md
└── .gitignore # auto-created, keeps .edit_count and archive/ out of git
These live inside the project. They never leave the repo. They're meant to be diff-able, human-editable, and committable — except the bits the auto-.gitignore excludes.
Local-first guarantees
- All state lives under
<your-project>/.claude/state/. Nothing in ~/, nothing in /tmp permanently, nothing on a network.
- The
init_state.sh script refuses to run if the project root resolves to /, $HOME, or empty — so it can't accidentally scribble into your home dir.
- No script in this kit ever calls
curl, wget, or any network tool.
- No telemetry. No analytics. No "phone home" of any kind.
Install
Option A — drop into a single project (no GitHub needed)
cd your-project
git clone https://github.com/<you>/claude-optimizer .claude-optimizer-tmp
mkdir -p .claude
cp -r .claude-optimizer-tmp/skills .claude/
cp -r .claude-optimizer-tmp/hooks .claude/
cp -r .claude-optimizer-tmp/scripts .claude/
cp -r .claude-optimizer-tmp/commands .claude/
chmod +x .claude/scripts/*.sh
rm -rf .claude-optimizer-tmp
# IMPORTANT: edit .claude/hooks/hooks.json and replace ${CLAUDE_PLUGIN_ROOT}
# with ${CLAUDE_PROJECT_DIR}/.claude (the plugin-root variable only exists
# when installed via the plugin marketplace).
Then add the suggested lines from templates/gitignore-snippet.txt to your project's top-level .gitignore if you want extra paranoia.
Option B — install as a plugin (recommended once you've pushed to GitHub)
/plugin marketplace add <your-username>/claude-optimizer
/plugin install claude-optimizer@claude-optimizer
No edits needed — ${CLAUDE_PLUGIN_ROOT} resolves correctly when installed this way. Active in every project automatically.
Per-project setup (one-time)
To keep the per-session counter and archive folder out of commits, run the bundled helper from any project once:
# in any project where you want optimizer state out of commits
bash ~/path/to/claude-optimizer/scripts/install_to_project.sh
It appends the lines from templates/gitignore-snippet.txt to that project's .gitignore. Idempotent — re-running does nothing if the snippet is already there.
Disabling per-project
Some repos shouldn't accumulate memory or progress logs. To opt out:
touch .claude/optimizer-disabled
init_state.sh exits silently when that file is present, so no .claude/state/ directory is created and no hooks write anything for that project.
What you'll notice