# Cost Optimizer

Trigger when the user asks to audit Claude Code costs, reduce token spend, says "my...

- Repository: https://github.com/mergisi/awesome-openclaw-agents (4042 stars)
- Category: AI and agents
- License: MIT
- Last updated: 2026-10-28
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add mergisi/awesome-openclaw-agents --skill cost-optimizer -g -a claude-code -y`
Codex: `npx skills add mergisi/awesome-openclaw-agents --skill cost-optimizer -g -a codex -y`
Cursor: `npx skills add mergisi/awesome-openclaw-agents --skill cost-optimizer -g -a cursor -y`
Gemini CLI: `npx skills add mergisi/awesome-openclaw-agents --skill cost-optimizer -g -a gemini-cli -y`

## 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.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# 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' .
```

The rest: https://github.com/mergisi/awesome-openclaw-agents/blob/HEAD/skills/claude/cost-optimizer/SKILL.md
