Stop Claude Code from burning through your quota in 20 minutes. Auto-rotates oversized sessions and preserves context.
$ npx -y skills add IyadhKhalfallah/clauditor --agent claude-code
Run the curl in your terminal, the rest in Claude Code.
Repo: IyadhKhalfallah/clauditor
What's inside
Every turn in a Claude Code session re-sends your entire conversation history to the API. A fresh session sends ~20k tokens per turn. A 200-turn session sends ~200k per turn. Same work, 10x more quota.
Turn 1: โโ 20k tokens
Turn 50: โโโโโโโโโโ 100k tokens
Turn 200: โโโโโโโโโโโโโโโโโโโโ 200k tokens
Turn 500: โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 400k tokens
This is why your session limit gets hit in 20 minutes. Not because of a bug โ because sessions grow linearly and nobody tells you to start fresh.
clauditor monitors your session size and blocks Claude when you're wasting quota, saving your progress so you can start fresh without losing context.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ clauditor: Session using 9x more quota than necessary โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
This session is burning 9x more quota per turn (170k vs ~20k tokens/turn).
Your progress has been saved and won't be lost.
Run `claude` to start a fresh session at ~20k tokens/turn instead of 170k.
In the new session, just say "continue where I left off".
When you type "continue" in the new session, clauditor shows your saved sessions and tells you exactly what to type:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ clauditor: 2 recent sessions found โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
1. (5m ago) Notion backfill โ populating database with User Email
โ read ~/.clauditor/sessions/.../1234.md and continue where I left off
2. (30m ago) feat/variable-agent โ migrating from ResponsesApi
โ read ~/.clauditor/sessions/.../5678.md and continue where I left off
Copy one of the โ lines above, or type something else to start fresh.
brew install IyadhKhalfallah/clauditor/clauditor
clauditor install
Or via npm:
npm install -g @iyadhk/clauditor
clauditor install
That's it. Two commands. clauditor registers hooks into Claude Code and runs in the background. No dashboard needed. No config needed.
Also works with npx (no global install):
npx @iyadhk/clauditor install
Hooks are registered to run via npx automatically.
New hooks are auto-registered on upgrade โ no need to re-run clauditor install.
Requires Node.js 20+.
Supported platforms: Claude Code CLI, VS Code extension, JetBrains extension. Does not work with Claude Code on the web (claude.ai/code).
Known limitation: The "continue" prompt block works reliably in the CLI. In the VS Code extension, the UserPromptSubmit hook may not fire consistently โ context is still injected via SessionStart but Claude may not always announce it. This is a Claude Code bug, not a clauditor issue.
clauditor registers 7 hooks into Claude Code:
UserPromptSubmit โ blocks before tokens are wastedBefore Claude processes your prompt, clauditor checks two things:
Waste factor = current tokens/turn รท baseline tokens/turn
1x = efficient (fresh session)
5x = growing
10x = blocked โ start fresh
PostToolUse โ blocks during autonomous workWhen Claude is working autonomously (editing files, running commands), there's no user prompt to intercept. The PostToolUse hook catches this โ after each tool call, it checks the waste factor and blocks if too high.
Uses exit code 2, which Claude Code treats as a blocking error. Claude acknowledges it, writes a handoff summary, and stops.
Also detects: cache degradation, token spikes, resume anomalies, edit thrashing, and buggy Claude Code versions (2.1.69-2.1.89 have a known cache bug that burns 10-20x tokens).
PreCompact โ saves context before compactionFires at the exact moment before Claude Code compacts your context. Saves session state as a fallback in case PostCompact doesn't fire.
PostCompact โ captures Claude's summary + mechanical stateFires after compaction. Merges Claude's own LLM-generated summary with mechanically extracted structured data (files, commits, commands) from the JSONL transcript.
SessionStart โ injects previous session contextWhen you start a new session, clauditor reads saved handoff files for this project and injects them into Claude's context. If multiple sessions exist (last 24h), Claude presents the choice.
PreToolUse โ prevents known errorsBefore Claude runs a command, clauditor checks the local error index (and optionally the team hub) for previous failures with the same binary. If a known fix exists with sufficient confidence, it injects it as context โ non-blocking, so Claude can adapt without being stopped.
[clauditor]: `npm run build` has failed 5 times on this project.
Last error: Module not found: Cannot resolve @/lib/db
Known fix: `npx drizzle-kit push && npm run build`
If the command succeeds after the warning, confidence increases. If it fails despite the warning, confidence decreases. The knowledge base self-corrects over time.
Stop โ blocks infinite loopsWhen Claude repeats the same tool call 3+ times with identical input and output, the Stop hook blocks it.
From a real user's Claude Code usage over 7 days:
TURNS BASE NOW WASTE TOKENS
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
317 21k 417k 20.1x 73M โโโโโโโโโโโโโโโโโโโโ
576 28k 401k 14.5x 116M โโโโโโโโโโโโโโโ
172 23k 249k 11x 25M โโโโโโโโโโโ
164 26k 220k 8.6x 21M โโโโโโโโโ
230 28k 218k 7.8x 31M โโโโโโโโ
...
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
37 sessions ยท 418M tokens total
15 sessions burned 5x+ more quota than necessary
clauditor impact
With rotation on all sessions: 157M tokens instead of 418M
Potential savings: 261M tokens (62% less quota)
clauditor watch
โโ clauditor โโ 4 sessions + 3 subagents (last 12h)
LAST 7 DAYS
37 sessions ยท 15 burned 5x+ quota
Worst: api/service (317 turns, 20.1x waste โ 21kโ417k/turn)
With rotation: 157M tokens instead of 418M (62% savings)
api-service (feat/variable-agent) opus-4-6 ยท 239 turns
Waste factor: 8x BLOCKED โ start a fresh session
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Started at 20k/turn โ now 153k/turn (8x more quota per turn)
Cache: 98% Turns: 239 ~$64 API est.
clauditor time
Shows token costs by hour of day to detect if peak hours burn more quota:
Token Usage by Hour โ last 7 days
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
10:00 98k/turn 304 turns cache 92% โโโโโโโโโโโ
14:00 124k/turn 289 turns cache 96% โโโโโโโโโโโโโโ
18:00 164k/turn 275 turns cache 98% โโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Peak (9am-5pm): 114k avg tokens/turn
Off-peak: 154k avg tokens/turn
| Command | Description |
|---|---|
clauditor | Show quota report (default) |
clauditor install | Register hooks into Claude Code (one-time) |
clauditor uninstall | Remove hooks |
clauditor watch | Live dashboard showing waste factor |
clauditor report | Quota usage report with waste bars |
clauditor share | Copy-pasteable summary for social media |
clauditor time | Token usage by hour of day (peak vs off-peak) |
clauditor sessions | See where your tokens went |
clauditor status | Quick health check (no TUI) |
clauditor impact | Lifetime stats |
clauditor activity | Recent actions log |
clauditor stats | Historical usage analysis |
clauditor doctor | Scan for cache bugs |
clauditor calibrate | Auto-calibrate rotation threshold |
clauditor suggest-skill | Find repeating workflows |
clauditor knowledge | Show accumulated errors and file activity |
clauditor handoff-report | Measure information preservation of last session handoff |
clauditor login | Sign in to clauditor hub (opens browser, or --device for SSH) |
Don't want clauditor to block or modify your sessions? Skip clauditor install and use it as a read-only analytics tool:
brew install IyadhKhalfallah/clauditor/clauditor
# or: npm install -g @iyadhk/clauditor
clauditor report # see waste across all sessions
clauditor time # peak vs off-peak token analysis
clauditor sessions # per-session breakdown
clauditor doctor # scan for cache bugs
clauditor share # copy-pasteable summary
These commands read your session JSONL files directly. No hooks registered, no session modifications, no side effects.
clauditor operates at the session boundary layer โ it monitors waste and rotates sessions. Other tools work at different layers and are fully compatible:
| Tool | Layer | What it does | Conflicts? |
|---|---|---|---|
| Headroom | API proxy | Compresses tool output tokens (~34% savings per turn) | No โ works at HTTP level |
| MemStack | Persistent memory | SQLite + vector DB for cross-session knowledge | No โ uses skills + rules |
| Claude Workspace Optimizer | Static workspace | Audits CLAUDE.md and memory files for bloat | No โ runs before sessions |
| GrapeRoot | Per-turn context | Builds code graph, pre-loads relevant files | No โ complementary |
| Hippo Memory | Persistent memory | Neuroscience-inspired memory with decay | No โ different approach |
You can run all of them together. clauditor handles when to rotate; the others optimize what happens within a session.
Everything works out of the box. One config file at ~/.clauditor/config.json:
{
"rotation": {
"enabled": true,
"threshold": 100000,
"minTurns": 30
},
"notifications": {
"desktop": true
}
}
| Setting | Default | Description |
|---|---|---|
rotation.enabled | true | Enable/disable session rotation |
rotation.threshold | 100000 | Tokens/turn average to trigger block |
rotation.minTurns | 30 | Minimum turns before blocking |
notifications.desktop | true | Desktop notifications for cache issues |
Created automatically on clauditor install. Edit to customize.
clauditor combines two methods to maximize information preservation during session rotation.
When clauditor blocks a session for rotation, it tells Claude to write its handoff in a structured format:
TASK: (what you were working on)
COMPLETED: (what's done)
IN_PROGRESS: (what's partially done, with file paths)
FAILED_APPROACHES: (what was tried and didn't work, and WHY)
DEPENDENCIES: (things that must happen in order)
DECISIONS: (choices made and why)
USER_PREFERENCES: (what the user asked for or rejected)
BLOCKERS: (unresolved issues)
This captures what only Claude knows โ reasoning, rejected approaches, conditionals โ in a parseable format. The parser detects structured output (2+ section headers) and falls back to prose if Claude doesn't follow the template.
Every handoff also includes structured data extracted mechanically from the JSONL transcript:
This data is deterministic โ no LLM interpretation, no paraphrasing, no loss.
Research shows LLM-generated summaries suffer from knowledge overwriting and semantic drift (Size-Fidelity Paradox). Mechanical extraction preserves files and commits deterministically. Claude's prose captures reasoning the transcript can't. Together they give the next session the best possible starting point.
clauditor handoff-report # see what your last handoff contains
Structural Coverage
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Score: 73% (11/15 structural items in handoff)
Files modified 2/4 โโโโโโโโโโโโโโโโโโโโ
Commits 2/2 โโโโโโโโโโโโโโโโโโโโ
Files read 3/5 โโโโโโโโโโโโโโโโโโโโ
Commands 2/2 โโโโโโโโโโโโโโโโโโโโ
Each handoff is saved as a separate timestamped file:
~/.clauditor/sessions/<encoded-project-path>/<timestamp>.md
Multiple sessions in the same project don't overwrite each other. Files older than 24h are cleaned up automatically.
/compact fires)clauditor learns from your sessions and builds per-project knowledge at ~/.clauditor/knowledge/<project>/.
Error index with confidence decay โ Records failed commands and their fixes. Each error has a confidence score (0โ1) that decays with a 45-day half-life. Recent errors rank above old ones. Stale errors fade naturally instead of accumulating forever.
npm run build conf=0.85 (confirmed, 5x)
npx drizzle-kit push conf=0.30 (inferred, 1x)
Noise filtering โ Typo commands (command not found), transient network errors (ETIMEDOUT), and tiny error messages are filtered at capture time. Keeps the error index clean from day one.
Implicit outcome tracking โ When PreToolUse warns about a command and PostToolUse sees the result, confidence adjusts automatically. Command succeeded after warning? +0.1. Failed despite warning? -0.15. Self-correcting, zero effort.
Confidence tiers โ Errors are labeled confirmed (0.7+), observed (0.4+), inferred (0.2+), or stale (<0.2). Claude sees the tier in the injection, so it knows how much to trust each entry.
File tracker โ Tracks edit/read counts across sessions. Identifies "hot files" (5+ edits across 3+ sessions) and injects context when Claude touches them, so it knows the file's history.
clauditor knowledge # see accumulated errors and file activity
For teams, clauditor can optionally connect to a hub for shared knowledge:
clauditor login
Opens your browser to sign in. For SSH or headless environments:
clauditor login --device
Visit: https://www.clauditor.ai/device
Enter code: XPFN-8442
When connected:
Knowledge starts as developer-scoped and auto-promotes to team-scoped when multiple developers report the same issue. No hub required for solo use โ all local features work independently.
Session handoffs work across projects. If you save a session in project A and open project B, clauditor finds it. Cross-project sessions show [project-name] labels so you know where they came from.
clauditor detects if your sessions ran on Claude Code versions 2.1.69-2.1.89, which have a confirmed prompt caching bug that causes 10-20x token consumption. The warning appears in clauditor report and via real-time hooks.
Why sessions get expensive:
Every Claude Code API call sends: tools โ system prompt โ CLAUDE.md โ conversation history. The conversation history grows linearly. Cache makes the prefix cheap (cache_read), but the growing tail requires cache_create each turn.
API call = tools (cached) + system (cached) + history (grows every turn)
After 200 turns, the history alone can be 200k+ tokens. A fresh session resets this to near zero.
What clauditor monitors:
| Metric | Source | Formula |
|---|---|---|
| Tokens/turn | JSONL usage field | input + output + cache_read + cache_create |
| Baseline | First 5 turns of session | Average tokens/turn |
| Current | Last 5 turns of session | Average tokens/turn |
| Waste factor | Derived | current รท baseline |
| Cache ratio | JSONL usage field | cache_read รท (input + cache_read + cache_create) |
Hook communication:
| Hook | Mechanism | Why |
|---|---|---|
UserPromptSubmit | Exit code 2 + stderr | Hard block โ stops prompt, shows message |
PostToolUse | Exit code 2 + stderr | Blocking error โ Claude acknowledges and stops |
PreToolUse | additionalContext | Injects known error fixes before commands |
PreCompact | File write | Saves fallback state at compaction moment |
PostCompact | File write | Captures Claude's own LLM summary |
SessionStart | additionalContext | Injects previous session state |
Stop | decision: "block" | Prevents infinite loops |
git clone https://github.com/IyadhKhalfallah/clauditor.git
cd clauditor
npm install
npm test # 275 tests
npm run build
npm link # makes `clauditor` available globally
MIT License. Not affiliated with or endorsed by Anthropic.
Contributions welcome. Rules:
MIT
.github/
ISSUE_TEMPLATE/
bug_report.md
feature_request.md
workflows/
ci.yml
release.yml
.gitignore
CHANGELOG.md
CONTRIBUTING.md
LICENSE
package-lock.json
package.json
README.md
src/
cli.ts
commands/
run.test.ts
run.ts
config.ts
daemon/
index.ts
parser.test.ts
parser.ts
parser.version.test.ts
store.ts
watcher.ts
features/
activity-log.ts
bash-filter.test.ts
bash-filter.ts
cache-health.test.ts
cache-health.ts
calibration.test.ts
calibration.ts
cost-tracker.test.ts
cost-tracker.ts
error-index.test.ts
error-index.ts
file-tracker.test.ts
file-tracker.ts
handoff-quality.test.ts
handoff-quality.ts
impact-tracker.ts
loop-detector.test.ts
loop-detector.ts
memory-guard.test.ts
memory-guard.ts
outcome-tracker.ts
project-brief.test.ts
project-brief.ts
quota-burn.test.ts
quota-burn.ts
quota-report.cache.test.ts
quota-report.test.ts
quota-report.ts
resume-detector.test.ts
resume-detector.ts
secret-scrubber.test.ts
secret-scrubber.ts
session-state-extraction.test.ts
session-state.per-session.test.ts
session-state.test.ts
session-state.ts
skill-suggest.test.ts
skill-suggest.ts
structured-handoff.test.ts
subagent-intel.test.ts
subagent-intel.ts
update-check.ts
hooks/
continue-detect.test.ts
post-compact-overwrite.test.ts
post-compact.test.ts
post-compact.ts
post-tool-use.ts
pre-compact.ts
pre-tool-use.test.ts
pre-tool-use.ts
session-start.ts
shared.ts
stop-handoff.test.ts
stop.test.ts
stop.ts
user-prompt-submit.ts
hub/
auth-server.ts
cache.ts
client.ts
device-flow.ts
git-project.ts
init-instruction.test.ts
init-instruction.ts
memory-sync.test.ts
memory-sync.ts
push-queue.ts
index.ts
install.ts
postinstall.ts
skills/
save-skill/
SKILL.md
tui/
alerts.tsx
app.tsx
cache-panel.tsx
dashboard.tsx
session-list.tsx
types.ts
tsconfig.json
tsup.config.ts
vitest.config.tsFAQ
clauditor is a Claude Code plugin with 1 hand-picked skill for development work, indexed on Flowy. Install it with the command on its page. It includes save-skill. Its skills do not fire on their own yet. Request auto-invocation to have Flowy route them as you prompt. Free and open source.