Agent Token Forensics
Offline, read-only analysis of AI coding agent transcripts for token cost and cache waste
Agent Token Forensics is an open-source MCP server for developer tools. It runs locally on your machine and is started by your AI client.
- Pricing
- Open source
- Platforms
- CLI, API, Linux
- Runs
- Locally
- Version
- 0.2.0
- Listing updated
Similar MCP servers
Install
You install MCP servers on a computer. Send yourself the link.
Add with the CLI
Run in a terminal
claude mcp add agent-token-forensics -- uvx agent-token-forensicsAdd --scope user to use it in every project, or --scope project to share it in .mcp.json.
Or share it with your project
Add to .mcp.json
{
"mcpServers": {
"agent-token-forensics": {
"command": "uvx",
"args": [
"agent-token-forensics"
]
}
}
}Add to claude_desktop_config.json
{
"mcpServers": {
"agent-token-forensics": {
"command": "uvx",
"args": [
"agent-token-forensics"
]
}
}
}Settings → Developer → Edit Config, then quit and reopen Claude Desktop.
Add to ~/.cursor/mcp.json
{
"mcpServers": {
"agent-token-forensics": {
"command": "uvx",
"args": [
"agent-token-forensics"
]
}
}
}Use .cursor/mcp.json in a project to share it with the project.
Add to ~/.copilot/mcp-config.json
{
"mcpServers": {
"agent-token-forensics": {
"type": "stdio",
"command": "uvx",
"args": [
"agent-token-forensics"
]
}
}
}Or put the same entry in .mcp.json at your workspace root to share it.
Add with the CLI
Run in a terminal
codex mcp add agent-token-forensics -- uvx agent-token-forensicsOr add to config.toml
Add to ~/.codex/config.toml
[mcp_servers.agent-token-forensics]
command = "uvx"
args = ["agent-token-forensics"]Add to your client's MCP settings (most use this shape)
{
"mcpServers": {
"agent-token-forensics": {
"command": "uvx",
"args": [
"agent-token-forensics"
]
}
}
}Gemini CLI and Antigravity
Gemini CLI
Add to ~/.gemini/settings.json
{ "mcpServers": { "agent-token-forensics": { "command": "uvx", "args": [ "agent-token-forensics" ] } } }Or run: gemini mcp add -s user agent-token-forensics uvx -- agent-token-forensics
Antigravity
Add to ~/.gemini/config/mcp_config.json
{ "mcpServers": { "agent-token-forensics": { "command": "uvx", "args": [ "agent-token-forensics" ] } } }Use .agents/mcp_config.json to add it to one workspace only.
Devin Desktop (formerly Windsurf)
Add to ~/.config/devin/mcp_config.json
{ "mcpServers": { "agent-token-forensics": { "command": "uvx", "args": [ "agent-token-forensics" ] } } }On Windows the file is %APPDATA%\devin\mcp_config.json. Use .devin/mcp_config.json to share it with a project.
Cline
Add to cline_mcp_settings.json
{ "mcpServers": { "agent-token-forensics": { "command": "uvx", "args": [ "agent-token-forensics" ] } } }Open it from the MCP Servers icon → Configure → Configure MCP Servers.
Zed
Add to Zed settings.json
{ "context_servers": { "agent-token-forensics": { "command": "uvx", "args": [ "agent-token-forensics" ] } } }Open it with zed: open settings file. Merge context_servers into the settings you already have.
JetBrains AI Assistant and Junie
AI Assistant
Add to Settings → Tools → AI Assistant → Model Context Protocol (MCP) → Add
{ "mcpServers": { "agent-token-forensics": { "command": "uvx", "args": [ "agent-token-forensics" ] } } }Junie
Add to ~/.junie/mcp/mcp.json
{ "mcpServers": { "agent-token-forensics": { "command": "uvx", "args": [ "agent-token-forensics" ] } } }Use .junie/mcp/mcp.json to share it with a project.
Kiro
Add to ~/.kiro/settings/mcp.json
{ "mcpServers": { "agent-token-forensics": { "command": "uvx", "args": [ "agent-token-forensics" ] } } }Use .kiro/settings/mcp.json to add it to one workspace only.
Using several servers? Build one config file with the MCP config generator.
About Agent Token Forensics
Reads the JSONL session logs that AI coding agents leave on disk and reports where token spend goes: prompt-cache hits that suddenly collapse, context that grows past a compaction point, and tool calls that repeat in a loop. It understands the usage fields used by Claude Code, OpenAI and Codex-style logs, Cursor, and Gemini, and estimates recoverable cost in USD.
The tool runs entirely locally with the Python standard library and no runtime dependencies. It never writes to disk or makes network calls. Thresholds for compaction, cache-bust detection and loop length can be adjusted from the command line, and output is available as JSON for CI budgets or as Markdown summaries.
It is aimed at developers who run long agent sessions and want to see why a bill is high before changing their workflow. The same detection logic is also exposed as a read-only MCP server over stdio so an AI client can request an analysis directly.
Tools this server provides (2)
Taken from the project documentation; the running server may differ.
From the tool list in its README, going by the names, 1 of 2 tools reads data; 1 name doesn't say.
From the server's own tool labels and tool names; not verified by us.
- analyze_transcriptsName suggests: reads
- Analyzes a JSONL transcript file or directory and returns cache bust events, compaction points, retry loops, top tools by tokens, and a cost summary.
- forensics_about
- Returns version, supported transcript schemas, and read-only guarantees.
What it does
- Prompt-cache bust detection
- Flags turns where a warm cache hit ratio drops sharply, pointing to prefix changes or idle eviction.
- Compaction inflection points
- Identifies the turn where context crosses a set token threshold and estimates savings from compacting.
- Retry loop detection
- Spots consecutive identical tool calls above a configurable count.
- Tool token attribution
- Ranks tools by the tokens attributed to them across a session.
- Multi-vendor log parsing
- Auto-detects usage fields from several coding agent transcript formats line by line.
- Read-only MCP server
- Exposes analysis and schema information as tools over stdio for MCP-compatible clients.
Good for
- Finding which long coding sessions waste budget on uncompacted context
- Checking whether a prompt cache is being invalidated by changes to the prompt prefix
- Catching agents stuck repeating the same tool call before the cost grows
- Adding a token budget check to CI using JSON output
- Letting an AI assistant inspect its own session logs through the MCP server
Pricing
Open source
Free and MIT licensed; optional paid cloud control plane is separate.
Agent Token Forensics FAQ
Does Agent Token Forensics send my transcripts anywhere?
No. The CLI and MCP server make no network calls and write no files. A browser version runs client-side and uploads nothing.
Which Python version is required?
Python 3.10 or newer, using only the standard library.
How do I run Agent Token Forensics without installing?
With uvx, run agent-token-forensics analyze --demo to see sample output before scanning local logs.
Which log formats are supported?
Claude Code and Anthropic usage fields, OpenAI, Codex and Cursor prompt token fields, Gemini usageMetadata, and Antigravity flat transcripts.
Is Agent Token Forensics free?
Yes. Agent Token Forensics is open source, so you can use and self-host it for free.
How do I add Agent Token Forensics to Claude Code?
Run this command in your terminal: claude mcp add agent-token-forensics -- uvx agent-token-forensics
What are the best alternatives to Agent Token Forensics?
The closest alternatives to Agent Token Forensics are Agent Cost Analyzer, ctx-profiler, TokenTrace, Agent Observability and Agentic Observability MCP.
Where this comes from
- Description: written from the project's README and its MCP Registry entry.
- Install steps: from the official MCP Registry entry.