Attribute AI assistant token usage to turns, sessions, commits, branches, PRs, time windows, or files.
Project description
token-pulse
Attribute AI assistant token usage to turns, sessions, commits, branches, PRs, time windows, or files — answering questions like "how many tokens did this PR cost me?"
Reads local Claude Code session logs (~/.claude/projects/**/*.jsonl) for accurate per-turn API token counts (input / output / cache_read / cache_creation), and provides an estimated mode for VS Code GitHub Copilot chat logs.
Status: v0.1 — Claude Code backend is accurate. Copilot backend is best-effort estimation.
Install
# pipx (recommended)
pipx install token-pulse
# or pip
pip install token-pulse
# with optional tiktoken-based estimation for Copilot logs
pip install 'token-pulse[estimate]'
Quick start
# Last conversation turn
token-pulse turn
# Current session
token-pulse session
# A specific commit
token-pulse commit HEAD
token-pulse commit a1b2c3d
# Range of commits
token-pulse commit HEAD~5..HEAD
# Everything since branching off main
token-pulse branch --base main
# A pull request (uses `gh` CLI)
token-pulse pr 1234
# Arbitrary time window
token-pulse window --since "2026-04-20" --until "2026-04-22"
# Per-file attribution from tool calls (Edit/Write/Read targets)
token-pulse file src/foo.py
# JSON output for piping
token-pulse session --json
Sample output
Scope: commit a1b2c3d "feat: add scoring service"
Window: 2026-04-22 14:31:08 → 2026-04-22 15:08:47 (37m 39s)
Backend: claude-code (12 turns, 1 session)
Input tokens: 48,210
Output tokens: 12,883
Cache read: 312,456
Cache creation: 18,902
─────────────────────────────
Billable in: 67,112
Billable out: 12,883
Estimated cost: $0.42 (claude-sonnet-4-5)
Why?
Existing tools (ccusage, splitrail, etc.) give you per-day/per-session totals. token-pulse lets you slice the same underlying data by VCS-meaningful boundaries:
| Question | Command |
|---|---|
| How much did this PR cost? | token-pulse pr 42 |
| Which commit was most token-expensive? | token-pulse commit HEAD~10..HEAD --rank |
| Which file consumes the most agent context? | token-pulse file --top 10 |
| What was the burn rate this morning? | token-pulse window --since 09:00 |
Backends
claude-code (default, accurate)
Parses JSONL files in ~/.claude/projects/ (override with CLAUDE_PROJECTS_DIR). Token counts come straight from the Anthropic API usage field — exact, including cache hits.
copilot (estimated, opt-in)
Parses VS Code workspace storage chat logs (~/Library/Application Support/Code/User/workspaceStorage/<id>/GitHub.copilot-chat/). Token counts are estimated by re-tokenizing message text with tiktoken (or a chars/4 heuristic if tiktoken is not installed). Does not include hidden system prompts or tool-call payloads, so expect 30–60% under-counting. Useful for relative comparisons, not billing.
token-pulse session --backend copilot
Use as an agent skill
This repo doubles as an agent skill (Claude Code & VS Code Copilot). Drop the repo into your skills dir:
# Claude Code
git clone https://github.com/618coffee/token-pulse ~/.claude/skills/token-pulse
# VS Code Copilot (workspace-scoped)
git clone https://github.com/618coffee/token-pulse .github/skills/token-pulse
Then ask your agent: "How many tokens did the last commit cost?" and it will run token-pulse commit HEAD for you. See SKILL.md.
Configuration
Optional ~/.config/token-pulse/config.toml:
default_backend = "claude-code"
default_currency = "USD"
[pricing.overrides]
"claude-sonnet-4-5" = { input = 3.00, output = 15.00, cache_read = 0.30, cache_creation = 3.75 } # $/Mtok
Limitations
- Copilot backend is estimation only (see above).
- PR scope requires the
ghCLI authenticated to the repo. - Per-file attribution is heuristic: assistant turn tokens are split equally across files touched by
tool_useblocks in that turn. - Time-window filtering uses entry
timestamp; clock skew between machines may cause edge-case misattribution.
Contributing
PRs welcome. See CONTRIBUTING.md.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file token_pulse-0.1.0.tar.gz.
File metadata
- Download URL: token_pulse-0.1.0.tar.gz
- Upload date:
- Size: 19.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ec6545fe60ede95ec1e9f3caef9ade286ea1479a3abd9c6eef30033250441439
|
|
| MD5 |
cb86b78267fb67af0bb852f5722d48db
|
|
| BLAKE2b-256 |
c4a57cfcc15e5085fcb2c9e10c3645aaa5c1bcddea8bae4751f623e9661ce596
|
Provenance
The following attestation bundles were made for token_pulse-0.1.0.tar.gz:
Publisher:
publish.yml on 618coffee/token-pulse
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
token_pulse-0.1.0.tar.gz -
Subject digest:
ec6545fe60ede95ec1e9f3caef9ade286ea1479a3abd9c6eef30033250441439 - Sigstore transparency entry: 1360773595
- Sigstore integration time:
-
Permalink:
618coffee/token-pulse@d3fefc34764555ac9f1e94926fa89ae8f2d58fe2 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/618coffee
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d3fefc34764555ac9f1e94926fa89ae8f2d58fe2 -
Trigger Event:
release
-
Statement type:
File details
Details for the file token_pulse-0.1.0-py3-none-any.whl.
File metadata
- Download URL: token_pulse-0.1.0-py3-none-any.whl
- Upload date:
- Size: 19.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aac354dcd38d0e97ee3c7d74587d398a92ca8f781b66d97507a1ee075d1c63b1
|
|
| MD5 |
3acc58f44341226cee36a7cd6f3a29ac
|
|
| BLAKE2b-256 |
3bc7318b9a013e9844b903d08d3f1a025533fe5ca681153382c213502f83d63e
|
Provenance
The following attestation bundles were made for token_pulse-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on 618coffee/token-pulse
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
token_pulse-0.1.0-py3-none-any.whl -
Subject digest:
aac354dcd38d0e97ee3c7d74587d398a92ca8f781b66d97507a1ee075d1c63b1 - Sigstore transparency entry: 1360773644
- Sigstore integration time:
-
Permalink:
618coffee/token-pulse@d3fefc34764555ac9f1e94926fa89ae8f2d58fe2 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/618coffee
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d3fefc34764555ac9f1e94926fa89ae8f2d58fe2 -
Trigger Event:
release
-
Statement type: