Cost Optimizer logo

Cost Optimizer

CommunityPopular
mergisi
cost-optimizer

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.

Overview

Publishermergisi
Repositoryawesome-openclaw-agents
Skill namecost-optimizer
Stars
4K
Forks
649
Bundled files
Instructions only
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by mergisi on GitHub. Read the source before you install it.

Installation

Install the Cost Optimizer AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/mergisi/awesome-openclaw-agents.git /tmp/awesome-openclaw-agents
mkdir -p .claude/skills
cp -r /tmp/awesome-openclaw-agents/skills/claude/cost-optimizer .claude/skills/cost-optimizer
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Cost Optimizer in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Cost Optimizer on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Cost Optimizer is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

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.

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?"

Frequently asked questions

What does the Cost Optimizer AI skill do?

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.

Why use Cost Optimizer on TypingMind?

Because you install it once and use it with any model. Cost Optimizer is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Cost Optimizer in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/mergisi/awesome-openclaw-agents/tree/main/skills/claude/cost-optimizer. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Cost Optimizer?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Cost Optimizer?

As many as you like. As long as a model supports skills, you can use Cost Optimizer with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Cost Optimizer AI skill free?

Yes. It is published on GitHub by mergisi under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇