djc00p/claude-api-cost-optimizer/claude-api-cost-optimizer
Claude Code and agent skill by djc00p/claude-api-cost-optimizer
- community
Checking that the SKILL.md file is still in the repository.
Minimize Anthropic Claude API costs through model selection, prompt caching, batching, and cost tracking. ⚠️ Enables local caching and cost logging — review file permissions and exclude secrets. Trigger phrases: reduce API costs, optimize Claude spending, save on API calls, Claude cost optimization, cheaper Claude models.
Install
npx vskill@latest install djc00p/claude-api-cost-optimizer/claude-api-cost-optimizerSKILL.md
The same SKILL.md was published earlier as djc00p/claude-api-cost-optimizer/claude-api-cost-optimizer.
Claude API Cost Optimizer
⚠️ Local Data Warning: This skill creates~/.claude_cache/,costs.log, andbatch_results.jsonlwhich may contain source code, API responses, and prompts. Setchmod 600on these files, never cache secrets/PII, and add cache directories to.gitignore.
Cut Claude API costs by 70–90% using intelligent model selection, caching, and batching.
Quick Start
- Audit your current API calls — identify which tasks use Opus or Sonnet that could use Haiku. Model selection alone saves 10–18x on simple tasks. Ensure
ANTHROPIC_API_KEYis set in your environment (required). - Pick the cheapest model tier for each task: Haiku (cheapest) → Sonnet (mid) → Opus (most expensive, use sparingly). See
references/pricing.mdfor current rates. - Enable prompt caching for repeated context (system prompts, codebases) by adding
"cache_control": {"type": "ephemeral"}to message blocks - Implement cost reporting — track
input_tokens,output_tokens, and cache metrics from API responses
Key Concepts
- Model selection — Haiku for simple tasks (formatting, comments) — cheapest tier. Sonnet for medium (refactoring, debugging) — mid tier. Opus for complex only (architecture, security) — most expensive, use sparingly. See
references/pricing.mdfor current rates. - Prompt caching — Cache large static content (system prompts, codebase context). Cache reads cost 90% less; writes pay off after 1–2 reuses.
- Batching — Combine multiple requests into one API call to eliminate per-request overhead. 80% fewer calls ≈ 80% lower cost.
- Local caching — Cache identical responses locally to skip redundant API calls entirely.
- Context extraction — Send only relevant snippets, not whole files. Smaller inputs = lower costs.
- max_tokens discipline — Set realistic limits; unused token budget is wasted money.
Common Usage
Code examples are in Python but concepts apply to any language or SDK.
Model selection pattern:
Prompt caching:
Cost tracking:
Security Checklist
Before using cost tracking and local caching:
- [ ] Set
chmod 600 ~/.claude_cache/and all log files - [ ] Never cache content containing secrets, credentials, or PII
- [ ] Set a short TTL (
max_age_hours) and clear cache regularly - [ ] Add cache directories to
.gitignore - [ ] Use encrypted volumes or ephemeral storage in CI environments
- [ ] Audit cached content periodically for sensitive data leaks
References
references/implementation.md— Full implementation patterns, model routing, caching setup, batching, retry logic, and anti-patternsreferences/pricing.md— Current pricing, cache cost math, savings calculations, and batch API details
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingSKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/djc00p/claude-api-cost-optimizer/claude-api-cost-optimizer)