context-cost-analyzer

A context-cost analyzer for a Claude Code session. It reads a `/context` breakdown and identifies which loaded files, skills, agents, or tools consume the most of the available token budget.

In plain words
What is it for?
Use it to analyze token counts, classify them against budget targets, trace costs to loaded files and plugins, and prioritize reductions.
Why use it?
It helps explain why a session has less room for useful work. The ordered savings list shows which context sources are worth reducing first.

Agent

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add agents/yacb2/aidex/context-cost-analyzer
Clone the repo
git clone --depth 1 https://github.com/yacb2/aidex
Per session 39 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,589 The whole file, excluding the scripts and references it only reads on demand.
Security scan B 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00039 $0.01589
Opus 5 $0.00019 $0.00794
Sonnet 5 $0.00008 $0.00318
Haiku 4.5 $0.00004 $0.00159

Measured 2d ago against content hash 73695d26ca55, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade B, and why

context-cost-analyzer scanned grade B with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Reads agent configuration directoriesmediumAgent snooping

.claude/, .codex/, .gemini/ hold keys, settings and other credentials a mod has no legitimate need for.

- For each plugin with N ≥ 3 agents, estimate cost = N × 600 tokens, grep recent transcripts under `~/.claude/projects/*/` for invocation of the plugin's command names. Zero matches in last 30 days → flag `CB-PL` CRITICA
skills/aidex/agents/context-cost-analyzer.md · 98 lines

How it starts

The opening of the file, as written. The whole thing — 98 lines — stays where its author put it; the contents beside it link to each section on GitHub.

You analyze a Claude Code session's idle context cost. Input is a /context breakdown (pasted text or a file path) plus the project path.

Setup

Read the budget heuristics: ~/.claude/skills/aidex/references/05-context-budget.md.

Steps

1. Parse breakdown

Extract one token count per category from the input:

  • system-prompt, system-tools, memory-files, skills, custom-agents, mcp-tools.

Tolerant regex: category name (case-insensitive, space or hyphen) followed by digits with optional commas, then token somewhere nearby. If a category is missing, record 0. Compute total and percentage of 200k.

2. Classify against budget

Use the targets in 05-context-budget.md § Budget targets. Mark each tunable category OK, WARN, or CRIT.

3. Attribute cost

For each non-trivial category, identify the contributors:

memory-files — list files actually loaded:

  • ~/.claude/CLAUDE.md, <project>/.claude/CLAUDE.md or <project>/CLAUDE.md, ~/.claude/rules/*.md, ~/.claude/rules/*.md, MEMORY.md paths.
  • Report each with approximate line count. Flag overlap across global/user/project.

custom-agents — enumerate plugins with agents:

  • Scan ~/.claude/plugins/cache/*/*/*/agents/*.md, group by plugin directory.
  • For each plugin with N ≥ 3 agents, estimate cost = N × 600 tokens, grep recent transcripts under ~/.claude/projects/*/ for invocation of the plugin's command names. Zero matches in last 30 days → flag CB-PL CRITICAL.

skills — detect duplicates, stack-irrelevant, and always-resident bloat:

  • For each pair (~/.claude/skills/X, <project>/.claude/skills/X), read both SKILL.md frontmatter. If name matches, compute Jaccard similarity on description words. >0.7 → CB-DU WARNING.
  • Detect project stack from package.json / pyproject.toml / Cargo.toml / go.mod / docker-compose.yml. List global skills under ~/.claude/skills/ whose domain doesn't match the detected stack as CB-SR candidates for skillOverrides (name-only or off).
  • Post-compaction budget model. Claude Code keeps recent skill invocations in context across turns: after auto-compaction, the most recent invocation of each skill is preserved (~5,000 tokens cap per skill, ~25,000 tokens combined budget). Skills not invoked recently can be dropped entirely. This means the real cost of an installed skill depends on whether it is always resident (built-in or MCP-pinned, loaded every session) or lifecycle-managed (auto-trigger or user-invocable, only persists post-invocation).
  • CB-SKILL-DESC-RESIDENT finding (new): for skills that are always resident — built-ins and any skill pinned via MCP alwaysLoad: true — measure their description length in SKILL.md frontmatter. Report WARNING when description >800 characters; these tokens are paid every session. For lifecycle-managed skills, do NOT emit this finding even with long descriptions: the cost is bounded by the 5k cap and amortized across invocations.
  • When ranking CB-SR and CB-DU savings, downweight non-resident skills proportionally (their max contribution is min(skill_size, 5k) per session, not full size).

Read the full file on GitHub · 98 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 98 lines · 39 tokens per session scan B 73695d26ca55

Subscribe to this mod's changes

context-cost-analyzer is an agent published in the GitHub repository yacb2/aidex (2 stars, last pushed 4d ago), licensed MIT. It adds 39 tokens to every session and 1,589 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it B with 1 finding (reads agent configuration directories). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other agents, from other repositories

ap-goal-checker

L4 terminal leaf - GOAL-CHECK. Independent, adversarial, default-FAIL. Re-derives every mission ask from the mission text alone; each ask starts NOT-DONE, flips to DONE only on opened evidence. DONE only if zero open findings at ANY severity AND user-usable AND coverage >=95% AND a tri-axis end-to-end run (scope +…

Spielewoy/autoprompt-skill · 92 tokens

ap-implementer

L3 executor - G4 IMPLEMENT. Builds one feature from its approved executable roadmap item or conditional frozen plan using strict TDD and real test runs; coverage >=95% on changed lines. Reports PLAN-CONFLICT rather than improvising.

Spielewoy/autoprompt-skill · 52 tokens

ap-manager

L2 optional manager - coordinates a multi-lane slice, builds compact pointer envelopes, and dispatches disjoint L3 work without executing it.

Spielewoy/autoprompt-skill · 32 tokens

ap-researcher

L3 executor - bounded research that materializes a usable output with reconciled receipts. Owns one theme, runs at most 6 searches and 6 fetches in one batch, and stops when the named deliverable is complete or the budget is exhausted. Does not spawn.

Spielewoy/autoprompt-skill · 61 tokens

ap-depth-prober

L4 terminal leaf - G3.5 DEPTH-LOCK. Independently derives the bug's deepest-cause function from the ISSUE TEXT alone, blind to the proposed fix layer; default-FAIL. Emits D1-D5. depth-miss REJECTs to G1.

Spielewoy/autoprompt-skill · 62 tokens

ap-execharness-resolver

L3 executor - EXECHARNESS RESOLVE. Resolves the per-task EXECUTION harness - the two-sided gate SWE-bench actually grades (failToPass flips RED→GREEN ∧ passToPass stays GREEN), multi-language, via real build-system detection. Ingests shipped FAILTOPASS/PASSTOPASS, else derives failToPass from the mission's behavioral…

Spielewoy/autoprompt-skill · 100 tokens