# Cost Tracking

> Track API token costs for specific operations in Claude Code. Use when the user invokes /cost-tracking to start measuring costs, or says "stop tracking", "stop cost tracking", or "how much did that cost" to stop and calculate. Tracks input, output, and cache tokens per API call and calculates USD cost using current Anthropic pricing.

- **Type:** Skill
- **Install:** `agentstack add skill-jbdamask-john-claude-skills-cost-tracking`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [jbdamask](https://agentstack.voostack.com/s/jbdamask)
- **Installs:** 0
- **Category:** [AI & ML](https://agentstack.voostack.com/c/ai-and-ml)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [jbdamask](https://github.com/jbdamask)
- **Source:** https://github.com/jbdamask/john-claude-skills/tree/main/skills/cost-tracking

## Install

```sh
agentstack add skill-jbdamask-john-claude-skills-cost-tracking
```

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

## About

# Cost Tracking

Track the exact token cost of any Claude Code operation by marking a start and stop point in the session JSONL.

## Start Tracking

When the user invokes `/cost-tracking`:

1. Determine the current session JSONL path. It lives at:
   ```
   ~/.claude/projects//.jsonl
   ```
   Find the project directory by looking for the most recently modified `.jsonl` file under `~/.claude/projects/`. The project hash is a mangled version of the working directory path (slashes replaced with dashes, e.g., `-Users-johndamask-myproject`).

2. Determine the cost tracking output directory:
   ```
   ~/.claude/projects//cost-tracking/
   ```

3. Run the start script:
   ```bash
   python3 /scripts/start_tracking.py  
   ```

4. Store the returned `tracking_id` — mention it to the user and remember it for the stop step.

5. Confirm: "Cost tracking started. I'll calculate costs when you say 'stop tracking'."

## Stop Tracking

When the user says "stop tracking", "stop cost tracking", or asks about the cost:

1. Run the stop script with the tracking_id from the start step:
   ```bash
   python3 /scripts/stop_tracking.py  
   ```

2. The script outputs a formatted cost report and writes:
   - `tokens.jsonl` — per-entry token log with timestamp, model, input_tokens, output_tokens
   - `summary.json` — aggregated cost breakdown by model

3. Present the report to the user.

## Pricing

Pricing is stored in `resources/pricing.json` (last updated 2026-03-08, source: https://platform.claude.com/docs/en/about-claude/pricing). The stop script loads this file at runtime. It distinguishes between 5-minute and 1-hour cache writes using the `cache_creation.ephemeral_*` fields in the session JSONL. If pricing appears stale, fetch the pricing page and update `resources/pricing.json`.

## Source & license

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

- **Author:** [jbdamask](https://github.com/jbdamask)
- **Source:** [jbdamask/john-claude-skills](https://github.com/jbdamask/john-claude-skills)
- **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-jbdamask-john-claude-skills-cost-tracking
- Seller: https://agentstack.voostack.com/s/jbdamask
- 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%.
