Home
cd ../playbooks
Developer ToolsBeginner

Claude Code Cost Optimizer

A static audit of a project's Claude Code setup for the handful of well-known token-cost leaks — oversized CLAUDE.md prepended every turn, bloated memory files, never-invoked skills loaded into the index, unscoped subagent fan-out, and the cache-killing hook that silently ~10x's cost — each with a PASS/WARN/FAIL check and a concrete fix, ranked by biggest win per effort.

5 minutes
By mergisi (awesome-openclaw-agents)Source
#claude-code#cost-optimization#token-usage#prompt-caching#developer-tools#audit

The fastest way to quietly double your Claude Code bill is a settings hook that echoes a timestamp into every message — it invalidates the prompt cache on every single turn, which can roughly 10x cost, and it never shows up as an obvious problem because everything still works, just far more expensively.

Who it's for: Claude Code users whose token spend jumped and want to know why, teams auditing a project for context bloat before it gets worse, developers who suspect their CLAUDE.md or memory files have grown too large, anyone doing a post-mortem after a runaway agent run burned through tokens

Example

"My Claude Code bill doubled this month — audit this project for waste" → A static scan running seven concrete checks (CLAUDE.md line count, memory-file size, unused large skills, subagent fan-out, prompt-cache-killing hooks, over-pinned expensive models, uncompacted sessions), each scored PASS/WARN/FAIL, returned as a priority-ranked fix list with the single biggest win — usually an oversized CLAUDE.md or a cache-invalidating hook — at the top

CLAUDE.md Template

New here? 3-minute setup guide → | Already set up? Copy the template below.

# Claude Code Cost Optimizer

Audit a project's Claude Code setup for the handful of well-known cost leaks and output a prioritized remediation list. This is a static inspection — no pricing API calls, no guesswork about past spend, just the structural things that quietly inflate per-turn token cost.

## When to Use

- "My Claude Code bill doubled this month — what's going on?"
- "Audit this project for token waste."
- "Why is my session context always huge?"
- A post-mortem after a runaway agent run.

## What to Check

Get new playbooks like this one

One email a week with new Claude Code workflows. Free, like everything here.

No spam. Unsubscribe anytime.

README.md

What This Does

A static, no-guesswork audit of the structural things that quietly inflate Claude Code token cost on every turn — it doesn't call a pricing API or try to reconstruct past spend, it inspects the setup for the handful of well-known leaks and returns a fix list ranked by biggest win per unit of effort. The headline culprits it catches are the ones that compound silently: an oversized CLAUDE.md (which is prepended to literally every message, so every excess line costs tokens forever), bloated memory files that should be a linked index rather than a dump, large skills that are never invoked yet still load into the skill index each turn, and — the sneakiest one — a settings hook that injects a timestamp or random value into every turn, breaking the prompt cache in a way that can roughly 10x cost while nothing visibly fails.

Each of seven checks produces a PASS/WARN/FAIL with a concrete bash command to run and a specific remediation, and the output is a priority-ranked list so the most impactful fix surfaces first. It's deliberately honest about its own limits: it estimates relative impact ("~30% smaller context") and explicitly refuses to invent dollar figures unless you supply your actual bill, pointing you to a before/after cost check to validate.


Quick Start

Step 1: Create a Project Folder

mkdir cost-optimizer && cd cost-optimizer

Step 2: Download the Template

Click Download above, then:

mv ~/Downloads/CLAUDE.md ./

Step 3: Audit a Project

claude

Point Claude at the project whose costs you want to understand and ask it to audit for token waste. It will run the seven checks, score each PASS/WARN/FAIL, and return a priority-ranked fix list with the biggest win first — without inventing dollar savings.


Tips & Best Practices

  • Fix the cache-hygiene finding first if it appears — a hook that injects changing content every turn is the single highest-leverage cost leak, since prompt caching is doing most of the work of keeping a long session affordable.
  • Treat CLAUDE.md as a thin pointer, not a knowledge base — anything a given task doesn't always need (runbooks, verbose examples, reference tables) belongs in a skill file or docs/ that's loaded on demand rather than prepended to every message.
  • Re-run the audit after making changes and compare with an actual before/after cost check — the tool deliberately won't fabricate savings numbers, so the real validation is measuring your own per-turn overhead drop.

Limitations

  • A static structural inspection only — it finds setup-level leaks (context size, cache hygiene, model pinning) but can't see into the actual content of a runaway conversation or diagnose a genuinely token-heavy task that legitimately needs the context it uses.
  • It estimates relative impact, never absolute dollar savings, unless you provide your current bill — anyone wanting a hard currency figure has to supply the baseline themselves.
  • The specific thresholds (100/300 lines for CLAUDE.md, 500/1500 for memory) and file paths assume a conventional Claude Code project layout; adapt them if your setup stores these files elsewhere.

$Related Playbooks

Developer Tools

Cinematic GSAP + Lenis Motion System

Build a connected, premium web motion language with GSAP, ScrollTrigger, and Lenis smooth scroll — a full token system for eases/durations/staggers, Lenis-driven-by-the-GSAP-ticker setup, a reusable data-attribute markup API for text reveals and parallax, and reduced-motion handling built in from the start, not bolted on after.

15 minutes
Advanced
Developer Tools

CEO-Mode Plan Review

Review a technical or product plan the way a great CEO would — pick a mode (expand scope, cherry-pick expansions, hold scope, or cut ruthlessly), then apply nine prime directives and eleven cognitive patterns to catch every silent failure, missing edge case, and unnamed error before it ships.

10 minutes
Advanced
Developer Tools

Claude Code Project Architecture

A setup guide for structuring a Claude Code project's full toolkit — layered CLAUDE.md context, slash commands, sub-agents, skills, hooks, and plugins — each used for what it's actually good at instead of one mechanism for everything.

20 minutes
Intermediate
Developer Tools

Claude Model Migration Assistant

Migrate code and prompts between Claude models — update model strings, remove incompatible beta headers, and adjust prompts only for reported behavioral differences.

5 minutes
Beginner
Developer Tools

Claude Code Plugin Builder

End-to-end guided workflow for building Claude Code plugins — structure, commands, agents, skills, hooks, and MCP integration — with a validation checklist before you distribute.

15 minutes
Advanced
Developer Tools

CLAUDE.md Progressive Disclosurer

Slim down and restructure a bloated CLAUDE.md (or AGENTS.md) using progressive disclosure — move low-frequency detail to Level 2 references while keeping Level 1 lean, with zero information loss.

15 minutes
Intermediate
Developer Tools

Claude Usage Analyst

Analyze Claude Code token usage, cost, quota burn, model mix, and cache read/write using ccusage evidence — and explain in human terms why your quota got exhausted.

10 minutes
Beginner
Developer Tools

CLI Demo Generator

Generate professional animated CLI demos as GIFs using VHS terminal recordings — with self-bootstrapping setup, output filtering, and frame-level verification.

15 minutes
Intermediate
Developer Tools

Cloudflare Troubleshooting

Investigate and resolve Cloudflare issues with API-driven evidence — ERR_TOO_MANY_REDIRECTS, SSL mode mismatches, DNS, and proxy problems — instead of guessing.

15 minutes
Intermediate
Developer Tools

Changelog Generator

Generate release notes from git commits, updates, or feature lists

10 minutes
Advanced
Developer Tools

CI/CD Pipeline Generator

Create production-ready CI/CD pipeline configurations for GitHub Actions, GitLab CI, CircleCI, and Jenkins with deployment to Vercel, Netlify, or AWS.

15 minutes
Intermediate
Developer Tools

Codebase Documenter

Create comprehensive, beginner-friendly documentation for codebases including READMEs, architecture guides, API docs, and code comments.

10 minutes
Beginner

Browse all Developer Tools playbooks →