Agent skill

Claude Code Cost Optimizer

by mergisi in mergisi/awesome-openclaw-agents

Audits a project's Claude Code setup for common token-cost leaks and returns a prioritized fix list, using only static inspection of files and settings.

MITAuto-check passedAgent Workflows

Install Claude Code Cost Optimizer

skills CLI
$ npx skills add mergisi/awesome-openclaw-agents --skill cost-optimizer -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install mergisi/awesome-openclaw-agents cost-optimizer --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/mergisi/awesome-openclaw-agents.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/claude/cost-optimizer .claude/skills/cost-optimizer && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
cost-optimizer
GitHub stars
4k
Token cost
~1.1k tokens
SKILL.md length
443 words
Files
1
Skills in repo
16
Repo updated
First seen
Licence
MIT

At a glance

Audits a project's Claude Code setup for common token-cost leaks and returns a prioritized fix list, using only static inspection of files and settings.

  • Works in 7 steps: CLAUDE.md size → Memory file bloat → Unused or shadowed skills → …
  • The Claude Code bill has jumped and you want to know why
  • SKILL.md covers When to use, What to check, Output format and Example invocations
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

The agent inspects a project without calling any pricing API or guessing at past spend, and records PASS, WARN or FAIL with a short note for each check. The checks cover the size of `CLAUDE.md` (under 100 lines passes, over 300 fails because it is prepended to every message), bloated memory files (a warning above 500 lines, a failure above 1500), and skills that have large bodies but are never invoked.

It also looks at subagent fan-out, warning when a repo spawns more than 5 parallel subagents per run without aggregation or when subagents re-read the whole repo instead of getting a scoped prompt, and at prompt-cache hygiene, failing any hook that injects a date or random value into every turn. Each finding comes with a suggested fix, such as moving reference material out of `CLAUDE.md` into skill files or docs. The excerpt is truncated, so any further checks are not described.

When your agent uses it

  • The Claude Code bill has jumped and you want to know why
  • Session context is always huge and you suspect a bloated CLAUDE.md
  • Reviewing a project after a runaway agent run
  • Trimming memory files and unused skills

Example prompts

  • “My Claude bill doubled this month. Audit this project for token waste.”
  • “Why is my session context always so large? Check CLAUDE.md and my memory files.”
  • “Run /cost-optimizer on this repo.”

Requirements

  • A shell that can run `wc`, `find` and `grep` in the project

Workflow steps

7 steps, taken from the step headings in SKILL.md.

  1. CLAUDE.md size
  2. Memory file bloat
  3. Unused or shadowed skills
  4. Subagent fan-out patterns
  5. Prompt cache hygiene
  6. Model selection
  7. Session file size

What it can do on your machine

Read from SKILL.md and the folder at commit 05820c5. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are bash).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Claude Code Cost Optimizer loads about 1.1k tokens when it runs. Until then it costs about 75 tokens; SKILL.md has 443 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~75
When it runs · the whole SKILL.md, loaded when a task matches
~1.1k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from mergisi/awesome-openclaw-agents at commit 05820c5, republished under its MIT licence (© mergisi). 443 words, ~1,089 tokens.

Download SKILL.mdSave it as .claude/skills/cost-optimizer/SKILL.md (or your agent's skills folder).
name
cost-optimizer
description
Trigger when the user asks to audit Claude Code costs, reduce token spend, says "my Claude bill is too high", "optimize my CLAUDE.md", "why is this project burning tokens", or "/cost-optimizer". Scans a project for the common Claude Code cost leaks and returns a prioritized fix list.

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.

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?"
  • Post-mortem after a runaway agent run

What to check

Run each check and record PASS / WARN / FAIL with a short note.

1. CLAUDE.md size
bash
wc -l CLAUDE.md .claude/CLAUDE.md 2>/dev/null
  • PASS: under 100 lines
  • WARN: 100-300 lines
  • FAIL: >300 lines — this is prepended to every message, so every line costs tokens forever.

Fix: move reference material (API keys, runbooks, verbose examples) into skill files or docs/, and leave CLAUDE.md as a thin pointer.

2. Memory file bloat
bash
find ~/.claude/projects -name 'MEMORY.md' -exec wc -l {} \;
find .claude/memory -type f -exec wc -l {} \; 2>/dev/null
  • WARN if any memory file is >500 lines.
  • FAIL if >1500 lines — memory should be a curated index with links to detail files, not a dump.

Fix: extract old sections into memory/<topic>.md detail files and link from the index.

3. Unused or shadowed skills
bash
ls ~/.claude/skills/ .claude/skills/ 2>/dev/null
  • Cross-reference with the skill invocations in the last 30 days of shell history or session logs if available.
  • Skills that have never been invoked but have huge SKILL.md bodies (>300 lines) are loaded into the skill index every turn — prune them.
4. Subagent fan-out patterns

Grep the project for Task/agent launch patterns:

bash
grep -rn 'TaskCreate\|subagent\|parallel.*agent' --include='*.md' --include='*.js' --include='*.ts' .
  • WARN if the repo spawns >5 parallel subagents per run without aggregation — each spins up its own context window.
  • FAIL if subagents re-read the whole repo instead of receiving a scoped prompt.

Fix: pass a short brief + a handful of file paths to each subagent, not the entire CLAUDE.md context.

Show full SKILL.md (165 more words)Show less
5. Prompt cache hygiene

Look for .claude/settings.json and check if the project sets an unusually short cache TTL, or if hooks invalidate the cache every message (e.g. a hook that echoes a timestamp into the system prompt).

  • FAIL any hook that injects date / uuidgen / random content into every turn — it kills the cache, 10x cost.
6. Model selection

Grep for explicit model pins:

bash
grep -rn 'opus\|sonnet\|haiku\|claude-3\|claude-4' .claude/ CLAUDE.md 2>/dev/null
  • WARN if Opus is pinned for routine tasks that Sonnet could handle. Recommend the /model-cost-compare skill for a per-task estimate.
7. Session file size
bash
du -sh ~/.claude/projects/*/sessions 2>/dev/null | sort -h | tail -5

Huge session dirs suggest you never /compact long-running threads. Suggest periodic compaction.

Output format

Print a ranked list. Top of the list = biggest win per effort.

Cost Optimizer — <project>

Priority 1 (FAIL)
  [CLAUDE.md]      412 lines — prepended every turn. Extract sections into skills/.
  [cache hygiene]  .claude/settings.json hook injects `date +%s` on SessionStart. Remove it.

Priority 2 (WARN)
  [memory]         MEMORY.md is 820 lines. Index top, details linked.
  [model pinning]  Opus 4.6 pinned in 4 skill files — 2 could drop to Sonnet 4.6.

Priority 3 (nice-to-have)
  [skills]         3 skills (haiku-card, foo, bar) never invoked in last 30 days.

Estimated impact: roughly halving per-turn overhead — validate with a before/after /cost check.

Do not invent dollar savings. You can estimate relative impact ("~30% smaller context") but not absolute currency unless the user provides their current bill.

Example invocations

  • /cost-optimizer
  • "Audit this project for Claude Code cost waste"
  • "My CLAUDE.md feels too big — what should I cut?"
  • "Why is my prompt cache missing every turn?"

© mergisi, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in skills/claude/cost-optimizer of mergisi/awesome-openclaw-agents.

Open the folder on GitHubat commit 05820c5

Compare with similar skills

Claude Code Cost Optimizer next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Claude Code Cost Optimizer compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Claude Code Cost Optimizer this skillmergisi/awesome-openclaw-agents4k—~1.1kAutomated safety check: PassMIT
Caveman Learn Token FixesJuliusBrussee/caveman111k—~2.8kAutomated safety check: PassApache-2.0
Context Budget Checkposhan0126/dotclaude871—~1.4kAutomated safety check: PassMIT
Caveman Memory File CompressorJuliusBrussee/caveman-code942—~1.2kAutomated safety check: PassMIT
Claude Code Masteryborghei/Claude-Skills886—~1.9kAutomated safety check: PassMIT
Code Context Slicingtrailofbits/skills7.4k—~2.1kAutomated safety check: PassCC-BY-SA-4.0

Similar skills

  • Caveman Learn Token Fixes

    JuliusBrussee/caveman

    Acts on a Caveman learn report: reviews ranked token sinks, applies cost-lowering edits one at a time with your consent, and reports what each fix returned.

    111k GitHub stars~2.8k tokensUpdated today
    Agent WorkflowsAuto-check passed
  • Context Budget Check

    poshan0126/dotclaude

    Estimates the per-turn token cost of a project's .claude folder and CLAUDE.md, split into always-loaded, path-scoped and invoked-only files, and flags what runs over budget.

    871 GitHub stars~1.4k tokensUpdated 1 mo ago
    Agent WorkflowsAuto-check passed
  • Caveman Memory File Compressor

    JuliusBrussee/caveman-code

    Rewrites a memory file such as CLAUDE.md or a todo list in terse caveman-style text to cut input tokens, saving a readable backup outside the project tree.

    942 GitHub stars~1.2k tokensUpdated 1 mo ago
    Agent WorkflowsAuto-check passed
  • Claude Code Mastery

    borghei/Claude-Skills

    A skill your agent uses when the user asks to "optimize CLAUDE.md", "create a new skill", "write a custom agent", "configure hooks", "manage context window", "set up MCP servers", "scaffold a skill…

    886 GitHub stars~1.9k tokensUpdated yesterday
    Agent WorkflowsAuto-check passed
  • Code Context Slicing

    trailofbits/skills

    Official

    Picks a small, graph-based slice of source with Trailmark and hands a focused code task to a smaller or local model without exposing the whole repository.

    7.4k GitHub stars~2.1k tokensUpdated yesterday
    Agent WorkflowsAuto-check passed
  • Context Routing Audit

    withkynam/vibecode-pro-max-kit

    Audits a project's context routing, skill discoverability and skill wiring by running a chain of validator scripts and fixing whatever they report.

    1.1k GitHub stars~1.2k tokensUpdated 3 mo ago
    Agent WorkflowsAuto-check passed

More from mergisi/awesome-openclaw-agents

All 16 skills in this repo
  • Excalidraw Architecture Diagram

    mergisi/awesome-openclaw-agents

    Generates or updates a whiteboard-style architecture diagram of the current codebase as an Excalidraw JSON file, showing services and data flow.

    4k GitHub stars~1.1k tokensUpdated 12 days ago
    Auto-check passed
  • Git Commit Message Writer

    mergisi/awesome-openclaw-agents

    Drafts a commit message from your staged diff, matching the repo's own style and explaining why the change happened, not just what changed.

    4k GitHub stars~664 tokensUpdated 12 days ago
    Auto-check passed
  • Model Cost Compare

    mergisi/awesome-openclaw-agents

    Trigger when the user asks which model to use, wants to compare model costs, says "what's cheapest for this task", "should I use Opus or Sonnet", "can a smaller model handle this", or…

    4k GitHub stars~1k tokensUpdated 12 days ago
    Auto-check passed
  • Openclaw Debugger

    mergisi/awesome-openclaw-agents

    Trigger when an OpenClaw agent is broken, silent, crashing, stuck, not responding, returning empty output, or the user says "my agent is down", "agent not working", "/openclaw-debugger".

    4k GitHub stars~959 tokensUpdated 12 days ago
    Auto-check passed
  • Code Explainer

    mergisi/awesome-openclaw-agents

    Explains a pasted code snippet in plain English, returning the detected language, a one-sentence summary, how it works and one practical tip.

    4k GitHub stars~283 tokensUpdated 12 days ago
    Auto-check passed
  • Commit Message

    mergisi/awesome-openclaw-agents

    Generate a clean, conventional commit message from a description of your changes.

    4k GitHub stars~239 tokensUpdated 12 days ago
    Auto-check passed

Questions about Claude Code Cost Optimizer

What does Claude Code Cost Optimizer do?

Audits a project's Claude Code setup for common token-cost leaks and returns a prioritized fix list, using only static inspection of files and settings. The agent inspects a project without calling any pricing API or guessing at past spend, and records PASS, WARN or FAIL with a short note for each check.md` (under 100 lines passes, over 300 fails because it is prepended to every message), bloated memory files (a warning above 500 lines, a failure above 1500), and skills that have large bodies but are never invoked.

When should I use Claude Code Cost Optimizer?

Claude Code Cost Optimizer fits situations like: the Claude Code bill has jumped and you want to know why; session context is always huge and you suspect a bloated CLAUDE.md; reviewing a project after a runaway agent run; trimming memory files and unused skills.

How do I install Claude Code Cost Optimizer in Claude Code?

Run `npx skills add mergisi/awesome-openclaw-agents --skill cost-optimizer -a claude-code`. Or copy the skill folder (skills/claude/cost-optimizer in mergisi/awesome-openclaw-agents) into .claude/skills/cost-optimizer in your project. Claude Code loads it when a task matches its description.

How do I install Claude Code Cost Optimizer in Codex?

Run `npx skills add mergisi/awesome-openclaw-agents --skill cost-optimizer -a codex`. Or copy the skill folder (skills/claude/cost-optimizer in mergisi/awesome-openclaw-agents) into .agents/skills/cost-optimizer in your project. Codex loads it when a task matches its description.

Can I use Claude Code Cost Optimizer in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add mergisi/awesome-openclaw-agents --skill cost-optimizer -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/cost-optimizer, .gemini/skills/cost-optimizer, .github/skills/cost-optimizer and .opencode/skills/cost-optimizer in your project.

What does Claude Code Cost Optimizer need to run?

SKILL.md names no scripts, command-line tools or credentials: Claude Code Cost Optimizer is instructions for the agent only. Our summary lists: A shell that can run `wc`, `find` and `grep` in the project.

Does Claude Code Cost Optimizer access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Claude Code Cost Optimizer safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Claude Code Cost Optimizer use?

Claude Code Cost Optimizer is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Claude Code Cost Optimizer use?

About 1.1k tokens (SKILL.md is roughly 4.4k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Claude Code Cost Optimizer?

Skills that share tags, products or a category with Claude Code Cost Optimizer: Caveman Learn Token Fixes (JuliusBrussee/caveman, 111k stars), Context Budget Check (poshan0126/dotclaude, 871 stars), Caveman Memory File Compressor (JuliusBrussee/caveman-code, 942 stars) and Claude Code Mastery (borghei/Claude-Skills, 886 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Claude Code Cost Optimizer?

mergisi (a GitHub user) maintains it in mergisi/awesome-openclaw-agents, which has 3,999 GitHub stars. The repository holds 16 skills in this directory. The repository was last updated on September 26, 2026.

Source: mergisi/awesome-openclaw-agents on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.