/skillry-optional-specialist:cost-control-token-reviewfrom skillry-optional-specialist
Audits LLM token consumption, model selection, caching, batch API usage, and subagent fanout to produce quantified cost optimizations with projected savings.
Ships in skillry-optional-specialist. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Skillry 3.0.0 merged the skills below into this one. The procedure in this file stays the default. When a task, agent or document names one of these old skills, open only its reference.
| Old skill | Reference | Covers |
|---|---|---|
llm-api-cost-optimization | references/llm-api-cost-optimization.md | LLM/API spend engineering: per-call token logs, prompt caching, model tiering, batching, context trimming, cost dashboard |
cloud-spend-review | references/cloud-spend-review.md | Cloud waste: rightsizing, idle and orphaned resources, storage tiering, egress, reserved/spot/committed discounts, tagging, anomaly alerts |
Audit an AI system's token consumption, model selection, caching strategy, batch API usage, context management, and subagent fanout for cost inefficiencies. Produces a quantified cost analysis with specific, implementable optimizations and projected monthly savings — not vague advice to "use smaller models."
references/cloud-spend-review.md.If per-request token logging is not in place, instrument the application to log input_tokens, output_tokens, cache_read_tokens, and cache_creation_tokens per API call before proceeding. High-level monthly totals are not sufficient for optimization work.
For Anthropic models (claude-*):
cache_control: {type: "ephemeral"} breakpoint must be placed at the end of the stable content block, before any variable content (user query, dynamic retrieved chunks)For OpenAI models (gpt-4o-, gpt-4-):
cached_tokens field in the API response to measure actual cache hits| Task type | Current model | Required capability | Recommended model | Monthly savings |
|---|---|---|---|---|
| Query classification | claude-3-5-sonnet | Simple classification | claude-3-5-haiku | -80% for this task |
| Code generation | claude-3-5-sonnet | Complex reasoning | claude-3-5-sonnet | Keep |
| Short extraction | gpt-4o | Simple extraction | gpt-4o-mini | -75% for this task |
Do not recommend model downgrades without verifying quality on a representative sample. Downgrade only tasks where the smaller model's output quality is acceptable, not tasks where it saves money but produces worse results.
A system that configures 32K context for queries that average 2K tokens is not wasting money on unused context (most APIs charge for actual tokens, not allocated context), but it may indicate a context pruning problem if context grows over multi-turn interactions. Check for unbounded context growth: in a 20-step agent task, does the context grow linearly with each step's output?
For each identified workload:
total_tokens_per_task = orchestrator_input + orchestrator_output + Σ(worker_i_input + worker_i_output) + synthesis_input + synthesis_output
Example: orchestrator (2K in, 0.5K out) → 5 workers (each 3K in, 1K out) → synthesis (18K in from worker outputs + 2K context, 1.5K out) = 2.5K + 20K + 19.5K = 42K tokens per user query.
At Sonnet pricing ($3/M input, $15/M output): 42K tokens ≈ $0.63 per user query. At 1,000 queries/day: $630/day, $18,900/month.
If the fanout cost has never been calculated, do it now before scaling the system. The orchestrator's token count is a small fraction of the true cost.
Present these as a table with a narrative explanation of which optimizations contribute the most savings.
System prompt not cached because it contains variable content. The system prompt includes Today is {{date}} or the user's display name. Every request generates a unique system prompt, preventing caching even though 99% of the content is static. Move all variable content to the human turn (user message), not the system prompt. The system prompt must be byte-identical across requests to be cached.
Using flagship models for every task. The model selection was made during prototyping. The same flagship model now handles complex reasoning tasks (correct) and simple yes/no classification queries (a 5-100x cost overhead). Implement task-type routing. Reserve flagship models for tasks where the quality difference is measurable. Classification, short extraction, and reformatting tasks should use the smallest model that meets the quality bar.
Context accumulation in multi-step agents. Step 1 adds 1K tokens. Step 2 adds the full output of step 1 (another 1K). Step 3 adds the full outputs of steps 1 and 2. By step 10, the context is 55K tokens. Total cost for the task: O(n²) in the number of steps. Add explicit context pruning between steps: keep only a summary of completed steps (200-500 tokens), not the full outputs. This reduces a 10-step task from ~55K tokens to ~7K tokens.
Batch API not used for nightly jobs. A document analysis pipeline processes 5,000 documents per night with results needed by 8am — a 6-hour window. The pipeline uses synchronous API calls. Switching to the Batch API saves 50% of that pipeline's monthly cost with no change to output quality and no change to the delivery deadline. If results are needed in hours (not seconds), use the Batch API.
Fanout cost never modeled. An orchestrator receives a user query (2K tokens). It fans out to 6 specialized workers (each 4K in + 1.5K out). Synthesis: 13.5K in + 2K out. Total per query: 2K + 36K + 15.5K = ~53.5K tokens. The team modeled cost as "about 2K tokens per query" based on the orchestrator's direct token count. At 500 queries/day, actual cost is 27× higher than estimated. Model the full fanout before launch, not after the first invoice.
No token logging in production. The team wants to reduce costs but has only the monthly billing total. They cannot tell which request types are expensive, whether caching is working, or whether context is growing unboundedly. Per-request token logging is a prerequisite for any cost optimization work. Implement it before attempting any optimization.
Downgrading models without quality validation. The team routes all classification tasks from Sonnet to Haiku to save money. They do not test whether Haiku meets the quality bar for those tasks. Six weeks later, user complaints about classification errors rise by 30%. The cost saving was real but the quality regression was not caught. Always validate on a representative 100-example sample before committing a model downgrade to production.
Output token max set to model maximum. max_tokens is set to 4,096 for all requests because "we might need it." Average output is 350 tokens. This does not directly increase cost (most APIs charge for actual output tokens, not max tokens) but it increases the response timeout window and can mask runaway generation in some runtime implementations. Set max_tokens to 2× the 95th percentile of actual output length with a reasonable hard cap.
Produce a cost control review report with:
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
llm-cost, token-optimization, api-spend, cost-analysis, model-tiering
9 skills in this plugin
/ecommerce-integration-reviewEcommerce: catalog, checkout, payments, inventory, orders, taxes; WordPress/WooCommerce plugins and themes./nfc-linktree-menu-builder-reviewNFC card, linktree, menu builder, QR and tap-to-open flows, plus print-ready artifacts and export./local-llm-runtime-reviewLocal LLM runtimes: model routing, resource limits, privacy boundaries, offline behavior.npx claudepluginhub fluxonlab/skillry --plugin skillry-optional-specialistOther plugins' skills for the same job