A Claude Code plugin that analyses your actual session transcripts (JSONL) to surface real token costs, waste patterns, and week-over-week improvement trends — no manual tracking required.
-
cost_summaryActual token usage from JSONL transcripts, broken out by session, date, and grand total.
- Input / cache_creation / cache_read / output tokens per session
- Top sessions by total token consumption
- Configurable rolling window (
days, default 30) - Filter by
projectslug or across all projects
When to use: "How many tokens did we use this week?" / "Which session was most expensive?"
-
cost_trendWeek-over-week comparison of token usage and waste metrics.
- Per-week totals: tokens, redundant reads, large-context turns, fix-loop turns, cache hit ratio
- Delta and % change between this week and last week
- Plain-English interpretation:
✓ Token usage down 18%/✗ Redundant reads up 12% - Configurable number of weeks (
weeks, default 2)
When to use: "How much cost optimization did we achieve?" / "Are we improving week over week?"
-
suggest_optimizationsAnalyses transcripts and returns prioritised actionable suggestions.
- HIGH — Repeated file reads (top files read across sessions)
- HIGH — Intra-session redundant reads (re-reads with no edit between)
- MEDIUM — Large-context turns (cache_read > 100K tokens)
- MEDIUM — Retry/fix loops (turns with >8 tool calls)
- INFO — Read vs Grep tool balance
When to use: "What are the biggest waste patterns?" / "What should I fix first?"
-
file_read_analysisDeep-dive on file read behaviour across sessions.
- Top 15 most-read files with redundant read counts
- Total redundant reads, split by: re-read after edit (valid) vs re-read without edit (waste)
- Targeted recommendations per file
When to use: "Which files am I re-reading unnecessarily?" / "Is the redundant read problem getting better?"
-
top_repeated_tasksFinds recurring task patterns across sessions using bigram clustering on human messages.
- Top-N phrase pairs by occurrence frequency
- Token cost attributed to each repeated pattern
- Example message for each cluster
When to use: "What work keeps coming back?" / "What should we automate or template?"
-
summarisePure-computation before/after health report against the last time
summarisewas called. No LLM involved — all classification is rule-based with a 5% change threshold.- Verdict:
IMPROVINGMOSTLY_IMPROVINGMIXEDMOSTLY_DECLININGDECLININGBASELINE_SET
- Went well — metrics that improved by >5% since last run
- Needs work — metrics that regressed by >5%
- Unchanged — stable metrics
- Tracks: total tokens, cache hit ratio, redundant reads, large-context turns, fix-loop turns, Read/Grep ratio
- Snapshot persisted to
~/.claude/cost-analysis-state.json— survives across sessions
First call captures the baseline and returns
BASELINE_SET. Subsequent calls compare against it.All other tools (
cost_summary,suggest_optimizations,file_read_analysis) also emit avsLastRunfield showing key deltas from their own previous call — same state file, per-tool snapshots.When to use: "Are things better or worse than last time?" / End-of-week retrospective.
- Verdict:
-
reset
Clears all persisted plugin state so every tool starts fresh.
target: "all"(default) — clears both baselines and read trackertarget: "baselines"— clears onlyvsLastRunsnapshots for all tools andsummarisetarget: "tracker"— clears only the session read tracker used by thePreToolUse:Readhook
When to use: Beginning of a new sprint/week, after a major workflow change, or when summarise baselines are stale.
The plugin registers a UserPromptSubmit hook that fires whenever your message contains cost/token/efficiency keywords:
costtokenoptimspendusageefficienhow muchwasteredundantcache hitsession logwhat did we
It injects a reminder to use the plugin tools before reading manual files.
macOS / Linux:
curl -fsSL https://raw.githubusercontent.com/sarins-lab/code-optimization-plugin/main/install.sh | shWindows (PowerShell):
irm https://raw.githubusercontent.com/sarins-lab/code-optimization-plugin/main/install.ps1 | iexBoth scripts automatically update ~/.claude/settings.json with the marketplace entry, enable the plugin, and wire the cost-keyword reminder hook. Restart Claude Code after running.
Add to ~/.claude/settings.json:
"extraKnownMarketplaces": {
"sarins-lab": {
"source": { "source": "github", "repo": "sarins-lab/code-optimization-plugin" }
}
},
"enabledPlugins": {
"code-optimization-plugin@sarins-lab": true
}Add to your .mcp.json or Claude Code MCP settings:
{
"mcpServers": {
"cost-analysis": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@sarins-lab/code-optimization-plugin"]
}
}
}Claude Code will pull the latest version from npm automatically on each start.
- Open Claude Code
- Run
/plugins→ Navigate toMarketplacetab → select Add MarketPlace - Enter:
sarins-lab/code-optimization-plugin - Navigate to
Disovertab and enable the plugin - Restart Claude Code
This is equivalent to Option B but done entirely inside Claude Code without editing any files.
All tools live in scripts/analysis-server.mjs. To add a new tool:
- Add the tool definition to the
TOOLSarray (name, description, inputSchema) - Implement the function — use
loadSessions(project)andextractTurns(session)as the data layer - Register it in the
fnsmap inside the request router - Bump the version in
package.jsonand.claude-plugin/plugin.json