cost-session — скилл для Claude Code: что делает и как установить
Скилл cost-session для Claude Code детализирует затраты на каждое сообщение внутри сессии, показывая дорогие запросы.
MIT 249 установок ★ 82 234 обновлён 2026-10-25
npx skills add ruvnet/ruflo --skill cost-session -a claude-codeЧто делает cost-session
Скилл запускает [scripts/session.mjs](../../scripts/session.mjs), чтобы разобрать JSONL-файл сессии и найти самые дорогие сообщения по числу токенов, кэшу и эскалации моделей. Он вычисляет медианные значения p50, p90 и p99, а также выделяет аномальные сообщения, превышающие p99 в два раза.
Инструмент требует разрешенный инструмент Bash для работы со скриптами. Если сессия не найдена в директориях проектов, выполнение завершается с ошибкой и кодом 2.
Для работы скилла нужен Node.js и установленная среда Claude Code.
Какие задачи решает
- детализировать стоимость сообщений сессии
- найти дорогие запросы по токенам и кэшу
- вычислить медианные перцентили стоимости p50 и p99
- отфильтровать сессию по времени с флагом --since
Примеры запросов агенту
- Разбери сессию --session-id <id> по сообщениям
- Покажи топ 10 дорогих сообщений сессии
- Выведи стоимость сообщений с --since 2026-06-16T13:00:00Z
Как установить cost-session
1Через Skills CLI (Vercel)
npx skills add ruvnet/ruflo --skill cost-session -a claude-code2Вручную: положить файлы
~/.claude/skills/cost-session/SKILL.mdПапка скилла целиком; для одного проекта — .claude/skills/cost-session/
1Через Skills CLI (Vercel)
npx skills add ruvnet/ruflo --skill cost-session -a codex2Вручную: положить файлы
.agents/skills/cost-session/SKILL.mdДля всех проектов — ~/.agents/skills/
1Через Skills CLI (Vercel)
npx skills add ruvnet/ruflo --skill cost-session -a cursor2Вручную: положить файлы
.cursor/skills/cost-session/SKILL.mdCursor читает и .agents/skills/, и .claude/skills/
1GitHub CLI
gh skill install ruvnet/ruflo plugins/ruflo-cost-tracker/skills/cost-session2Вручную: положить файлы
.github/skills/cost-session/SKILL.md1Через Skills CLI (Vercel)
npx skills add ruvnet/ruflo --skill cost-session -a gemini-cli2Командой платформы
gemini skills install https://github.com/ruvnet/ruflo --path plugins/ruflo-cost-tracker/skills/cost-sessionВручную: положить файлы
.devin/skills/cost-session/SKILL.mdСтарый путь .windsurf/skills/ тоже читается
Через Skills CLI (Vercel)
npx skills add ruvnet/ruflo --skill cost-session -a opencodeClaude.ai
Упакуйте папку в zip и загрузите в Settings → Capabilities → Skills
По шагам, с командами для каждой платформы: Как установить скилл в Claude Code: пять способов
Вопросы о cost-session
Как установить cost-session в Claude Code?
Выполните команду npx skills add ruvnet/ruflo --skill cost-session -a claude-code, затем проверьте файл ~/.claude/skills/cost-session/SKILL.md.
Что делает cost-session?
Разбирает сессию по сообщениям, рассчитывает стоимость по токенам и кэшу, выводит перцентили стоимости и находит аномально дорогие запросы.
Что нужно для работы cost-session?
Для работы скилла необходим разрешенный инструмент Bash, Node.js и сохраненные JSONL-файлы сессий в ~/.claude/projects/*/.
Исходный текст
SKILL.md · MIT
--- name: cost-session description: Per-message cost breakdown within a single session. The drill-down companion to cost-anomaly — when an outlier session is flagged, this surfaces the specific expensive messages so operators can see whether the cost came from output tokens, cache writes, or model escalations. argument-hint: "[--session-id <id>] [--top 20] [--since <iso-ts>] [--format table|json]" allowed-tools: Bash disable-model-invocation: true --- When cost-anomaly flags a session as a >3.5σ outlier, the next question is "which MESSAGES were expensive?". cost-session answers that. | Question | Skill | |---|---| | "Which sessions cost the most?" | `cost-conversation` | | "Which sessions are outliers?" | `cost-anomaly` | | **"Which messages in THIS session were expensive?"** | **`cost-session`** ← this | ## Algorithm Implementation: [`scripts/session.mjs`](../../scripts/session.mjs). 1. Resolve session jsonl: `--session-id <id>` (scans `~/.claude/projects/*/`) or `--latest` (default; picks most-recently-modified jsonl). 2. Parse all assistant messages with `usage` blocks. 3. Cost each message via shared PRICING (`_prices.mjs`). 4. Sort descending by `cost_usd`, surface top-N (default 20). 5. Compute p50/p90/p99 of message costs for in-session percentile context. 6. Flag the top message if it's >2× the p99 — that's an in-session outlier. ## Why this matters: cache writes are the silent cost Example real session, top message: ``` | # | Model | In | Out | Cache W | Cache R | Cost | | 1 | opus-4-7 | 6 | 569 | 881898 | 0 | $16.58 | ``` Without the **Cache W** column it looks like "569 output tokens cost $16" — that's wrong by 380×. The actual cost is ephemeral 1h cache write at opus pricing: 881,898 tokens × $18.75/1M = $16.54. Operators reading the table see immediately: "the model wrote 881K tokens to ephemeral cache". From there the question becomes "why did we cache 881K tokens of context for a 6-input request?" — that's a real engineering signal. ## Drill-down workflow ```bash # Step 1: find outliers across all sessions cost anomaly --alert-on-outliers 1 || cost anomaly # see which session-ids # Step 2: drill into the flagged session cost session --session-id <flagged-id> --top 10 # Step 3: open that jsonl at the timestamp the top message reports, # inspect the prompt + tool calls ``` ## Percentile context Top of output: ``` | p50 (median) message | $0.85 | | p90 message | $1.45 | | p99 message | $1.74 | ``` Lets operators ask "is this top message a 2× outlier or a 380× one?" without having to compute it themselves. The "top is >2× p99" footer fires when the answer is "yes, this is an in-session outlier worth investigating". ## --since filter Useful for drilling into a specific time range within a long session: ```bash cost session --since 2026-06-16T13:00:00Z --top 5 ``` Only messages with `timestamp >= --since` are considered. ## Edge cases - No costed assistant messages → "_No costed assistant messages_" + exit 0. - `--session-id` not found in any project's jsonls → exit 2 with error. - `--top` must be a positive integer → exit 2.
© ruvnet · MIT · ruvnet/ruflo