agent-instructions
Use when writing project instructions for a coding agent (CLAUDE.md, AGENTS.md, or equivalent). Covers what belongs in them, what…
Use when an LLM feature costs too much. Covers prompt caching, context reduction, model routing, batching, output limits, and finding where the tokens actually go. Trigger on "our openai bill is too high", "llm costs are out of control", "where are all these tokens going", "set
Claude Code
$ npx -y skills add nimadorostkar/Claude-Skills-collection --skill llm-cost-optimization --agent claude-code
Codex
$ npx skills add nimadorostkar/Claude-Skills-collection --skill llm-cost-optimization -a codex -y
Cursor
$ npx skills add nimadorostkar/Claude-Skills-collection --skill llm-cost-optimization -a cursor -y
Gemini CLI
$ npx skills add nimadorostkar/Claude-Skills-collection --skill llm-cost-optimization -a gemini-cli -y
GitHub Copilot
$ npx skills add nimadorostkar/Claude-Skills-collection --skill llm-cost-optimization -a github-copilot -y
OpenCode
$ npx skills add nimadorostkar/Claude-Skills-collection --skill llm-cost-optimization -a opencode -y
Windsurf
$ npx skills add nimadorostkar/Claude-Skills-collection --skill llm-cost-optimization -a windsurf -y
name: llm-cost-optimization description: Use when an LLM feature costs too much. Covers prompt caching, context reduction, model routing, batching, output limits, and finding where the tokens actually go. Trigger on "our openai bill is too high", "llm costs are out of control", "where are all these tokens going", "set up prompt caching". Do not use for cloud infrastructure spend — see the aws-cost-optimization skill; for choosing a cheaper model, see the model-selection skill. metadata: category: ai version: 1.0.0 tags: [cost, tokens, caching, optimization, llm]
Reduce the cost of an LLM feature without losing the quality that justified it. Most LLM bills are dominated by one or two things that nobody has measured, and the fix is usually structural rather than a matter of shaving tokens.
1. **Measure where the tokens go** — Input versus output, and within input: system prompt, tools, retrieved context, conversation history. The answer is frequently not what anyone expected. 2. **Cache the stable prefix** — If the system prompt and tools are identical across calls, prompt caching reduces their cost by roughly 90%. This is usually the single largest and cheapest win. 3. **Cut the context, not the quality** — Retrieving twenty chunks when five suffice costs four times as much and often produces a *worse* answer. Measure the quality at each k. 4. **Route to a smaller model** — Most tasks do not need the largest model. Measure the small one before assuming it cannot. 5. **Batch what is not interactive** — Batch APIs are typically half the price for work that can wait. Overnight classification does not need a synchronous call. 6. **Cap the output** — Output tokens cost several times more than input tokens. A `max_tokens` that is generous "just in case" is a standing cost.
**Finding where the money actually goes:**
Feature: support-assistant. 4.2M calls/month. $18,400/month.
Token breakdown per call (mean):
System prompt + tools 3,100 every call, identical
Retrieved context 9,800 top-20 chunks
Conversation history 6,400 grows unbounded within a session
User message 180
Output 420
-------
Input total 19,480
Output total 420
Findings, in order of size:
1. The system prompt is identical on every call and is not cached.
-> Enable prompt caching. 3,100 tokens x 4.2M at 10% of the cost.
Saving: ~$2,900/month. Effort: one line.
2. Retrieval returns 20 chunks. Quality on the eval set peaks at k=6
and is flat to k=20.
-> Reduce to k=6. Saving: ~$6,100/month. Quality: unchanged (measured).
3. History is never compacted; long sessions carry 40k+ tokens.
-> Compact above 8k. Saving: ~$2,400/month.
4. 31% of questions are near-duplicates of a previous question.
-> Semantic cache on the answer. Saving: ~$3,700/month.
Total: $18,400 -> $3,300/month. No measurable quality change.**The caching mistake that costs the most:**
# This defeats prompt caching entirely, and it is not obvious.
system = f"You are a support assistant. Current time: {datetime.now()}. ..."
# ^^^^^^^^^^^^^^^^
# The prefix differs on every call, so nothing is ever a cache hit.
# Correct: keep the stable part stable; put the variable part after the
# cache breakpoint.
system = [
{
"type": "text",
"text": STABLE_SYSTEM_PROMPT, # byte-identical every call
"cache_control": {"type": "ephemeral"},
},
{
"type": "text",
"text": f"Current time: {datetime.now().isoformat()}", # after the breakpoint
},
]A curated library of 137 production-grade skills for Claude and other AI coding agents. Every skill follows one structure, speaks with one voice, and earns its place by changing what the agent does.
Use when writing project instructions for a coding agent (CLAUDE.md, AGENTS.md, or equivalent). Covers what belongs in them, what…
Use when an agent needs state that survives a session or a context compaction. Covers what to persist, file-based memory,…
Use when automating agent behavior with lifecycle hooks. Covers hook events, deterministic enforcement of rules the model should…
Use when packaging skills, commands, hooks, and MCP servers into a distributable plugin. Covers manifest structure, bundling,…
Use when writing a new skill for an AI agent. Covers scoping, description writing for reliable triggering, progressive…
Use when reviewing or improving an existing agent skill. Covers triggering accuracy, content quality, redundancy with the base…
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or…
Ask which skill or flow fits your situation. A router over the skills in this repo.