cost-optimizer — скилл для Claude Code: что делает и как установить
Скилл cost-optimizer следит за расходами на LLM при выполнении DAG и снижает уровень моделей или пропускает шаги, чтобы уложиться в бюджет.
MIT 143 установок ★ 274 обновлён 2026-10-30
npx skills add curiositech/some_claude_skills --skill cost-optimizer -a claude-codeЧто делает cost-optimizer
Скилл контролирует накопленные расходы при выполнении графов задач (DAG). Перед запуском каждого узла он рассчитывает ожидаемую цену по истории или базовым значениям: от ~$0.001 для Haiku до ~$0.16 для Opus. Полученная сумма сопоставляется с установленным лимитом.
Когда остаётся менее 20% бюджета, скилл переводит шаги Tier 2 на Tier 1. При падении остатка ниже 10% на базовый уровень переключаются все оставшиеся узлы, а необязательные действия пропускаются. Если лимит исчерпан полностью, выполнение останавливается, возвращая частичный результат и подробный отчёт о тратах.
Инструмент использует Read и Grep и принимает аргументы вида [dag-id] [budget-usd]. Первичный выбор моделей он оставляет для llm-router. Слишком агрессивное снижение уровня моделей опасно: ошибки генерации вызовут повторные попытки, а ретраи обойдутся дороже своевременного использования старшей модели.
Какие задачи решает
- контролировать расходы на вызовы LLM в рамках заданного бюджета DAG
- динамически понижать уровень модели с Tier 2 на Tier 1 при дефиците средств
- пропускать необязательные узлы графа при приближении к лимиту
- формировать итоговый отчёт по затратам на каждый узел пайплайна
Примеры запросов агенту
- Проверь бюджет для пайплайна dag-etl-42 с лимитом 0.50 USD
- Оптимизируй затраты на выполнение DAG: budget 1.20 USD, id data-sync
- Сформируй отчёт о расходах на токены после выполнения dag-reports
Как установить cost-optimizer
1Через Skills CLI (Vercel)
npx skills add curiositech/some_claude_skills --skill cost-optimizer -a claude-code2Вручную: положить файлы
~/.claude/skills/cost-optimizer/SKILL.mdПапка скилла целиком; для одного проекта — .claude/skills/cost-optimizer/
1Через Skills CLI (Vercel)
npx skills add curiositech/some_claude_skills --skill cost-optimizer -a codex2Вручную: положить файлы
.agents/skills/cost-optimizer/SKILL.mdДля всех проектов — ~/.agents/skills/
1Через Skills CLI (Vercel)
npx skills add curiositech/some_claude_skills --skill cost-optimizer -a cursor2Вручную: положить файлы
.cursor/skills/cost-optimizer/SKILL.mdCursor читает и .agents/skills/, и .claude/skills/
1GitHub CLI
gh skill install curiositech/some_claude_skills .claude/skills/cost-optimizer2Вручную: положить файлы
.github/skills/cost-optimizer/SKILL.md1Через Skills CLI (Vercel)
npx skills add curiositech/some_claude_skills --skill cost-optimizer -a gemini-cli2Командой платформы
gemini skills install https://github.com/curiositech/some_claude_skills --path .claude/skills/cost-optimizerВручную: положить файлы
.devin/skills/cost-optimizer/SKILL.mdСтарый путь .windsurf/skills/ тоже читается
Через Skills CLI (Vercel)
npx skills add curiositech/some_claude_skills --skill cost-optimizer -a opencodeClaude.ai
Упакуйте папку в zip и загрузите в Settings → Capabilities → Skills
По шагам, с командами для каждой платформы: Как установить скилл в Claude Code: пять способов
Вопросы о cost-optimizer
Как установить cost-optimizer в Claude Code?
Выполните команду npx skills add curiositech/some_claude_skills --skill cost-optimizer -a claude-code. Файл скилла запишется по пути ~/.claude/skills/cost-optimizer/SKILL.md.
Что делает cost-optimizer?
Он непрерывно отслеживает стоимость токенов при исполнении графа задач. Если лимит исчерпывается, скилл переводит узлы на младшие модели или останавливает выполнение.
Заменяет ли cost-optimizer логику llm-router?
Нет, исходным распределением моделей по задачам управляет llm-router. Скилл cost-optimizer подключается только при риске выйти за рамки бюджета.
Исходный текст
SKILL.md · MIT
---
name: cost-optimizer
description: Tracks cumulative LLM costs across DAG execution and makes real-time decisions to stay within budget. Downgrades models, skips optional nodes, or stops early when cost exceeds thresholds. Use
when managing execution budgets, analyzing cost breakdowns, or optimizing model routing for cost. Activate on "cost budget", "too expensive", "reduce cost", "cost optimization", "model downgrade", "budget
exceeded". NOT for LLM model selection logic (use llm-router), pricing comparisons across providers, or billing/invoicing.
allowed-tools: Read,Grep
argument-hint: '[dag-id] [budget-usd]'
metadata:
tags:
- cost
- optimizer
- cost-budget
- too-expensive
- reduce-cost
pairs-with:
- skill: cost-accrual-tracker
reason: The tracker provides the real-time cost data that the optimizer uses for budget decisions
- skill: llm-router
reason: Model routing is the primary mechanism through which cost optimization is enacted
- skill: cost-verification-auditor
reason: Post-execution auditing validates that optimization decisions actually reduced costs
---
# Cost Optimizer
Tracks cumulative LLM costs across DAG execution and makes real-time decisions to stay within budget: downgrade models, skip optional nodes, or stop early.
---
## When to Use
✅ **Use for**:
- Setting and enforcing cost budgets for DAG executions
- Real-time cost monitoring during execution
- Deciding when to downgrade model tiers mid-execution
- Identifying which nodes are most expensive and why
- Post-execution cost analysis and optimization recommendations
❌ **NOT for**:
- Choosing which model to use per node (use `llm-router`)
- Provider pricing comparisons (static data, not a skill)
- Billing or invoicing features
---
## Budget Enforcement Process
```mermaid
flowchart TD
N[Node about to execute] --> C[Check: spent + estimated_node_cost vs budget]
C --> S{Within budget?}
S -->|Yes, >20% remaining| E[Execute at planned model tier]
S -->|Yes, <20% remaining| W[Execute but downgrade to Tier 1 if possible]
S -->|No| D{Node optional?}
D -->|Yes| SK[Skip node]
D -->|No| H{Human gate available?}
H -->|Yes| A[Ask human: continue over budget?]
H -->|No| ST[Stop execution, return partial results]
```
### Budget Tiers
| Budget Remaining | Action |
|-----------------|--------|
| >50% | Execute at planned model tier |
| 20-50% | Log warning. Continue at planned tier. |
| 10-20% | Downgrade remaining Tier 2 nodes to Tier 1 (Haiku) |
| 5-10% | Downgrade ALL remaining nodes to Tier 1. Skip optional nodes. |
| <5% | Stop execution unless next node is critical path |
| 0% | Stop. Return partial results with cost breakdown. |
### Cost Estimation Per Node
Before each node executes, estimate its cost:
```
estimated_cost = (avg_input_tokens × input_price + avg_output_tokens × output_price)
```
Use historical averages for this skill + model combination. If no history, use defaults:
- Tier 1 (Haiku): ~800 input + 400 output = ~$0.001
- Tier 2 (Sonnet): ~2000 input + 1000 output = ~$0.012
- Tier 3 (Opus): ~3000 input + 1500 output = ~$0.16
### Post-Execution Report
```yaml
cost_report:
total_budget: 0.50
total_spent: 0.37
budget_remaining: 0.13
nodes_executed: 8
nodes_skipped: 1
nodes_downgraded: 2
model_breakdown:
haiku: { calls: 4, cost: 0.004 }
sonnet: { calls: 3, cost: 0.036 }
opus: { calls: 1, cost: 0.33 }
savings_recommendations:
- "Node 'deep-analysis' used Opus ($0.33) but downstream accepted on first try. Try Sonnet next time — potential saving: $0.32"
- "Nodes 'validate-a' and 'validate-b' are sequential but independent. Parallelize to reduce wall-clock time."
```
---
## Anti-Patterns
### No Budget at All
**Wrong**: Running DAGs without any cost tracking until the API bill arrives.
**Right**: Every DAG execution has a budget, even if generous. Track spend per node.
### Aggressive Downgrading
**Wrong**: Downgrading Opus nodes to Haiku at 50% budget remaining, causing quality failures that trigger expensive retries.
**Right**: Only downgrade when the alternative is stopping execution. Retries cost more than the original model tier.
### Ignoring Retries in Cost
**Wrong**: Budgeting for one attempt per node.
**Right**: Budget for avg_retries × cost_per_attempt. A node with 3 retries on Sonnet costs $0.036, not $0.012.
© curiositech · MIT · curiositech/some_claude_skills