From shipshitdev-library
Audits and reduces AI agent token and inference spend through context discipline, prompt caching, model routing, batching, and workflow capture.
How this skill is triggered — by the user, by Claude, or both
Slash command
/shipshitdev-library:ai-agent-cost-optimizerThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Reduce AI agent spend without reducing shipped quality. Optimize for cost per correct completed task, not raw token count.
Reduce AI agent spend without reducing shipped quality. Optimize for cost per correct completed task, not raw token count.
Price the model and context to the cost of failure.
Use more capable models when a wrong answer could create expensive rework, security risk, data loss, or architectural drag. Use cheaper models and smaller context when the task is bounded, reversible, test-covered, or mechanical.
Do not save tokens in ways that increase retries, hide important evidence, or lower code quality.
Identify what is actually driving cost before recommending changes:
If usage data is unavailable, mark it unknown and inspect local configs, logs, scripts, or provider dashboards only when accessible.
Pricing, model availability, cache behavior, and benchmark rankings are date-sensitive. Verify current provider documentation before citing specific prices or recommending a model as the default.
Treat social posts, benchmark screenshots, and vendor marketing as hypotheses. Convert them into local tests before changing default routing.
Look for these common waste patterns:
Fix context shape first:
Design stable prefixes:
Do not generalize that streaming breaks caching. Cache misses usually come from unstable prefixes, unsupported providers or models, thresholds, TTL expiry, or changed tool/message structure.
Use this rubric as the starting point:
| Task | Default Tier | Promote When |
|---|---|---|
| Architecture, security-critical review, irreversible operations, high-blast-radius refactors | Premium | Already premium; add review or tests |
| Feature implementation, debugging, test writing, routine refactors | Workhorse | Failing repeatedly, weak tests, or hidden architecture risk |
| Lint, format, rename, simple extraction, boilerplate, classification | Utility or local | Output needs nuanced judgment or affects production behavior |
| Long agentic loops | Workhorse with strict context budgets | Loop reaches unclear design decisions or persistent failures |
| Exploration across unknown codebases | Workhorse or premium for initial map, then cheaper tier for bounded follow-up | Architecture is unclear or stakes are high |
Use local evaluation over broad leaderboard claims. A cheaper model that doubles retries may be more expensive than the premium model.
Batch related small questions into one call when they share context. Partition broad tasks into independent subtasks when each subtask can run with isolated context and return a compact result.
Avoid spawning extra agents just to parallelize trivial work. Multi-agent systems can increase token spend unless context isolation or wall-clock savings justify the overhead.
When a workflow is repeated and stable, capture it so agents stop rediscovering it:
Capture the final working workflow, not the exploratory path that found it.
Compare before and after using task-level metrics:
Report savings as measured ranges. Avoid unsupported claims like "80% reduction" unless the baseline and after-state are both known.
When auditing a workflow, return:
Related skills:
context-fundamentals - Understand what consumes contextcontext-optimization - Apply compaction, masking, caching, and partitioningmulti-agent-patterns - Evaluate when sub-agent context isolation is worth the overheadtool-design - Reduce tool ambiguity and response bloatskill-capture - Persist repeated workflows as reusable skillsnpx claudepluginhub shipshitdev/skills --plugin worktreeDiagnoses and reduces LLM API costs using observability data. Finds expensive spans, applies context trimming, model right-sizing, caching, and retry fixes. Guards against quality regressions.
Monitors, caps, and recovers from context accumulation in agentic systems with per-cycle cost tracking, budget enforcement, and emergency pruning. Use for long-lived agent loops, rising API costs, or post-mortem analysis.
Guides agentic engineering workflows: eval-first loops, 15-min task decomposition, model routing (Haiku/Sonnet/Opus), AI code reviews, and cost tracking.