cache-efficiency — скилл для Claude Code: анализ кэша промптов
Скилл разбирает, окупается ли кэширование промптов: считает долю попаданий в кэш, соотношение записи и чтения и траты по каждому из них.
npx skills add hoangsonww/Claude-Code-Agent-Monitor --skill cache-efficiency -a claude-codeЧто делает cache-efficiency
Скилл работает с данными дашборда Agent Monitor. Он берёт суммарные токены из /api/analytics, разбивку по сессиям из /api/sessions, а деньги — из /api/pricing/cost. На выходе — отчёт в Markdown с таблицами: доля попаданий в кэш, сколько токенов записано и сколько прочитано, как эти суммы делятся в долларах. Отдельный раздел — десять сессий с самым плохим переиспользованием.
Формула простая: cache_hit_rate = total_cache_read / (total_cache_read + total_input), а cache_reuse = total_cache_read / total_cache_write. Если reuse меньше единицы, вы платите за кэш, который почти не читаете обратно. Запись в кэш стоит дороже чтения, и она тарифицируется даже тогда, когда блок так и не переиспользовали. Токены считаются как эффективные суммы current + baseline, поэтому данные до компакции не теряются.
Скилл принимает аргумент: пусто — анализ по всем данным, либо период вроде «today», ID сессии для сужения выборки, либо цель наподобие «hit rate > 80%». Без запущенного Agent Monitor с его API скилл работать не сможет: все четыре эндпоинта — его собственные.
Какие задачи решает
- посчитать долю попаданий в кэш промптов по всем сессиям
- найти сессии, где запись в кэш сильно превышает чтение
- разложить расходы на кэш по чтению и записи в долларах
- оценить, сколько сэкономит рост доли попаданий
- разобрать одну конкретную сессию с плохим переиспользованием
Примеры запросов агенту
- Проанализируй эффективность кэша промптов за эту неделю
- Покажи сессии с самым плохим переиспользованием кэша
- Разбери сессию
abc123— почему у неё мало чтений из кэша?
Как установить cache-efficiency
1Через Skills CLI (Vercel)
npx skills add hoangsonww/Claude-Code-Agent-Monitor --skill cache-efficiency -a claude-code2Вручную: положить файлы
~/.claude/skills/cache-efficiency/SKILL.mdПапка скилла целиком; для одного проекта — .claude/skills/cache-efficiency/
1Через Skills CLI (Vercel)
npx skills add hoangsonww/Claude-Code-Agent-Monitor --skill cache-efficiency -a codex2Вручную: положить файлы
.agents/skills/cache-efficiency/SKILL.mdДля всех проектов — ~/.agents/skills/
1Через Skills CLI (Vercel)
npx skills add hoangsonww/Claude-Code-Agent-Monitor --skill cache-efficiency -a cursor2Вручную: положить файлы
.cursor/skills/cache-efficiency/SKILL.mdCursor читает и .agents/skills/, и .claude/skills/
1GitHub CLI
gh skill install hoangsonww/Claude-Code-Agent-Monitor cache-efficiency2Вручную: положить файлы
.github/skills/cache-efficiency/SKILL.md1Через Skills CLI (Vercel)
npx skills add hoangsonww/Claude-Code-Agent-Monitor --skill cache-efficiency -a gemini-cli2Командой платформы
gemini skills install https://github.com/hoangsonww/Claude-Code-Agent-Monitor --path plugins/ccam-analytics/skills/cache-efficiencyВручную: положить файлы
.devin/skills/cache-efficiency/SKILL.mdСтарый путь .windsurf/skills/ тоже читается
Через Skills CLI (Vercel)
npx skills add hoangsonww/Claude-Code-Agent-Monitor --skill cache-efficiency -a opencodeClaude.ai
Упакуйте папку в zip и загрузите в Settings → Capabilities → Skills
По шагам, с командами для каждой платформы: Как установить скилл в Claude Code: пять способов
Вопросы о cache-efficiency
Как установить cache-efficiency в Claude Code?
Выполните npx skills add hoangsonww/Claude-Code-Agent-Monitor --skill cache-efficiency -a claude-code. Скилл появится в ~/.claude/skills/cache-efficiency/SKILL.md.
Что делает cache-efficiency?
Считает долю попаданий в кэш промптов, соотношение записи и чтения, долларовую разбивку расходов на кэш и находит сессии с худшим переиспользованием. Результат — отчёт в Markdown с таблицами.
Какие данные нужны скиллу?
Эндпоинты дашборда Agent Monitor: /api/analytics, /api/sessions, /api/sessions/{id} и /api/pricing/cost. Без запущенного дашборда анализировать нечего.
Исходный текст
SKILL.md · MIT
---
name: cache-efficiency
description: >
Analyze prompt-cache effectiveness for Claude Code usage from the Agent
Monitor dashboard — cache hit rate (total_cache_read / (total_cache_read +
total_input)), cache_write vs cache_read reuse, cache-read vs cache-write
spend, and the sessions with the poorest reuse. Pulls token totals from
/api/analytics, per-session detail from /api/sessions, and dollar splits
from /api/pricing/cost. Use when diagnosing cache spend or deciding whether
prompt caching is paying off.
---
# Cache Efficiency
Diagnose whether prompt caching is actually saving money, and where it is not.
## Input
The user provides: **$ARGUMENTS**
This may be: empty (analyze the whole fleet), "today" / "this week" / a date range, a session ID to scope the analysis, or a target like "hit rate > 80%". When empty, analyze all data from `/api/analytics`.
## Data Sources
| Endpoint | Returns |
|----------|---------|
| `GET /api/analytics` | `tokens.total_input`, `tokens.total_output`, `tokens.total_cache_read`, `tokens.total_cache_write` (baselines pre-summed), plus `daily_sessions` |
| `GET /api/sessions?limit=200` | Session list — each has model, cwd, started_at, ended_at, inline `cost`, metadata (JSON: usage_extras with cache token detail) |
| `GET /api/sessions/{id}` | Full session detail with nested agents and events, for drill-down on a flagged session |
| `GET /api/pricing/cost` | `{ total_cost, breakdown: [{ model, input_tokens, output_tokens, cache_read_tokens, cache_write_tokens, cost, matched_rule }] }` — used to price cache read vs write spend |
### How cache economics work
```
cache_hit_rate = total_cache_read / (total_cache_read + total_input)
cache_reuse = total_cache_read / total_cache_write
cache_read_cost = (cache_read_tokens / 1M) × cache_read_per_mtok
cache_write_cost = (cache_write_tokens / 1M) × cache_write_per_mtok
```
Cache writes cost more per token than cache reads (e.g. Sonnet $3.75 write vs $0.30 read per Mtok), and writes are billed even if the cached block is never reused. The payoff only arrives on subsequent reads — so a healthy fleet shows **cache_read_tokens far exceeding cache_write_tokens**. When `cache_reuse < 1`, you are paying to cache context you barely re-read.
Token counts are **effective totals** = `current + baseline` (baselines preserve pre-compaction tokens).
## Report Sections
### 1. Fleet Cache Hit Rate
From `/api/analytics`: compute `cache_hit_rate × 100`. State raw `total_cache_read` and `total_input`. Benchmark: >70% strong, 40–70% moderate, <40% weak prompt-cache utilization.
### 2. Write vs Read Reuse
Compute `cache_reuse = total_cache_read / total_cache_write`. Show both token counts. Flag if reuse < 1 (writing more cache than is ever read back).
### 3. Cache Spend Split
From `/api/pricing/cost` breakdown, sum `cache_read_cost` and `cache_write_cost` across all models. Show the dollar split and what fraction of total cost is cache-write overhead vs cache-read savings.
### 4. Sessions With Poor Reuse
From `/api/sessions?limit=200`, parse `metadata.usage_extras` for per-session cache read/write where available; rank sessions by lowest read/write reuse (and by cache_write-heavy cost). List the worst 10 with model, cost, and reuse ratio. Use `/api/sessions/{id}` to drill into any single flagged session.
### 5. Recommendations
- Sessions where `cache_write >> cache_read`: short or one-shot sessions rarely recoup cache writes — note them.
- Stable, repeated context (system prompts, large files) should be cached once and reused; high churn defeats caching.
- Estimate the dollar impact of raising the hit rate to the next benchmark tier.
## Output
Structured Markdown with tables. Currency as USD to 4 decimal places; rates as $/Mtok; percentages with ▲/▼ for any trend. Token counts with thousands separators.
© hoangsonww · MIT · hoangsonww/Claude-Code-Agent-Monitor