# Session Cost

> Посчитать израсходованные токены сессии Claude Code (input/output/cache) из ее транскрипта. Использовать когда нужно приложить расход токенов к смете/отчету по задаче, оценить объем работы агента, или сравнить вклад генерации против перечитывания контекста. Триггеры "сколько токенов потратили", "расход токенов за сессию", "токены в смету", "cost сессии". Для остатка лимита аккаунта это НЕ сюда -…

- **Type:** Skill
- **Install:** `agentstack add skill-dewil-claude-toolkit-session-cost`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [dewil](https://agentstack.voostack.com/s/dewil)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [dewil](https://github.com/dewil)
- **Source:** https://github.com/dewil/claude-toolkit/tree/main/skills/session-cost

## Install

```sh
agentstack add skill-dewil-claude-toolkit-session-cost
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# session-cost

Считает токены сессии Claude Code по ее транскрипту, программно и без внешних API. `/usage` дает только % лимита аккаунта, `/cost` - ручной вызов; этот скилл дает сырые токены по типам, пригодные для сметы, отчета и автоматизации.

## Как работает

Claude Code пишет каждую сессию в `~/.claude/projects//.jsonl`. У каждого assistant-сообщения есть `message.usage` с полями `input_tokens`, `output_tokens`, `cache_creation_input_tokens` (запись кэша), `cache_read_input_tokens` (чтение кэша). Скрипт суммирует их за сессию.

Имя папки проекта - абсолютный путь рабочей папки, где каждый не-alnum символ заменен на `-` (`/Users/x/My.Proj` -> `-Users-x-My-Proj`).

## Запуск

```bash
python3 scripts/session-cost.py                 # текущая сессия (env CLAUDE_CODE_SESSION_ID), проект по CWD
python3 scripts/session-cost.py --session   # конкретная сессия
python3 scripts/session-cost.py --file 
python3 scripts/session-cost.py --project  --all-sessions
python3 scripts/session-cost.py --json          # машиночитаемо
```

## Что знать про цифры (важно для честной сметы)

- **Текущая сессия** определяется по env `CLAUDE_CODE_SESSION_ID` (его ставит Claude Code) - надежно. Без него - свежайшая по mtime, а при **параллельных сессиях** в одном проекте это может оказаться ЧУЖАЯ сессия. Тогда указывай `--session` явно.
- **`cache_read` обычно доминирует** (десятки млн) - это перечитывание постоянного контекста (системный промпт, правила, память, схемы тулов) на каждом ходу, а НЕ работа по задаче. Показатель реального труда агента - **`output`** (и отчасти `cache_write`). Скрипт помечает это в выводе (строка `work`).
- **per-session = per-задача** только когда сессия однотемная. Для сессии, где смешаны разные задачи, точной разбивки по задачам нет - бери сессию целиком или дели вручную по границам.

## Когда НЕ применять

- Нужен остаток лимита аккаунта (не расход конкретной сессии) - это `/usage` или usage-эндпоинты аккаунта.
- Нужна стоимость в деньгах - скрипт дает токены; конверсию в валюту делать снаружи по актуальным ценам модели.

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [dewil](https://github.com/dewil)
- **Source:** [dewil/claude-toolkit](https://github.com/dewil/claude-toolkit)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-dewil-claude-toolkit-session-cost
- Seller: https://agentstack.voostack.com/s/dewil
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
