# Agent Token Forensics

> Agent Token Forensics is an open-source MCP server for developer tools. Offline, read-only analysis of AI coding agent transcripts for token cost and cache waste. It runs locally on your machine and is started by your AI client.

- **Kind:** MCP server
- **Pricing:** Open source
- **Platforms:** CLI, API, Linux, macOS, Windows
- **Repository:** https://github.com/blackbadhope/agent-token-forensics
- **MCP Registry name:** io.github.BlackBadHope/agent-token-forensics
- **Categories:** [developer tools](https://ai-powered.com/categories/developer-tools)
- **Listing updated:** 2026-12-02

## About

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.

## Features

- **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

## Install

### Claude Code: Add with the CLI (Terminal)

```sh
claude mcp add agent-token-forensics -- uvx agent-token-forensics
```

Add --scope user to use it in every project, or --scope project to share it in .mcp.json.

### Claude Code: Or share it with your project (.mcp.json)

```json
{
  "mcpServers": {
    "agent-token-forensics": {
      "command": "uvx",
      "args": [
        "agent-token-forensics"
      ]
    }
  }
}
```

### Claude Desktop (claude_desktop_config.json)

```json
{
  "mcpServers": {
    "agent-token-forensics": {
      "command": "uvx",
      "args": [
        "agent-token-forensics"
      ]
    }
  }
}
```

Settings → Developer → Edit Config, then quit and reopen Claude Desktop.

### Cursor (~/.cursor/mcp.json)

```json
{
  "mcpServers": {
    "agent-token-forensics": {
      "command": "uvx",
      "args": [
        "agent-token-forensics"
      ]
    }
  }
}
```

Use .cursor/mcp.json in a project to share it with the project.

### VS Code (~/.copilot/mcp-config.json)

```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.

### Codex: Add with the CLI (Terminal)

```sh
codex mcp add agent-token-forensics -- uvx agent-token-forensics
```

### Codex: Or add to config.toml (~/.codex/config.toml)

```toml
[mcp_servers.agent-token-forensics]
command = "uvx"
args = ["agent-token-forensics"]
```

### Gemini CLI and Antigravity: Gemini CLI (~/.gemini/settings.json)

```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

### Gemini CLI and Antigravity: Antigravity (~/.gemini/config/mcp_config.json)

```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 (~/.config/devin/mcp_config.json)

```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 (cline_mcp_settings.json)

```json
{
  "mcpServers": {
    "agent-token-forensics": {
      "command": "uvx",
      "args": [
        "agent-token-forensics"
      ]
    }
  }
}
```

Open it from the MCP Servers icon → Configure → Configure MCP Servers.

### Zed (Zed settings.json)

```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 (Settings → Tools → AI Assistant → Model Context Protocol (MCP) → Add)

```json
{
  "mcpServers": {
    "agent-token-forensics": {
      "command": "uvx",
      "args": [
        "agent-token-forensics"
      ]
    }
  }
}
```

### JetBrains AI Assistant and Junie: Junie (~/.junie/mcp/mcp.json)

```json
{
  "mcpServers": {
    "agent-token-forensics": {
      "command": "uvx",
      "args": [
        "agent-token-forensics"
      ]
    }
  }
}
```

Use .junie/mcp/mcp.json to share it with a project.

### Kiro (~/.kiro/settings/mcp.json)

```json
{
  "mcpServers": {
    "agent-token-forensics": {
      "command": "uvx",
      "args": [
        "agent-token-forensics"
      ]
    }
  }
}
```

Use .kiro/settings/mcp.json to add it to one workspace only.

### Other clients (your client's MCP settings (most use this shape))

```json
{
  "mcpServers": {
    "agent-token-forensics": {
      "command": "uvx",
      "args": [
        "agent-token-forensics"
      ]
    }
  }
}
```

## Tools

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_transcripts` (name 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.

## 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, Aretuza.Code and Agent Observability.

## Where this comes from

- Description: written from the project's README and its MCP Registry entry.
- Install steps: from the official MCP Registry entry.

## Alternatives

- [Agent Cost Analyzer](https://ai-powered.com/mcp/agent-cost-analyzer): Agent Cost Analyzer is an open-source MCP server for developer tools.
- [ctx-profiler](https://ai-powered.com/mcp/ctx-profiler): ctx-profiler is an open-source MCP server for developer tools.
- [TokenTrace](https://ai-powered.com/mcp/tokentrace): TokenTrace is an open-source MCP server for developer tools.
- [Aretuza.Code](https://ai-powered.com/mcp/aretuza-code): Aretuza.Code is a freemium MCP server for developer tools.
- [Agent Observability](https://ai-powered.com/mcp/agent-observability): Agent Observability is an open-source MCP server for developer tools.
- [Agentic Observability MCP](https://ai-powered.com/mcp/agentic-observability-mcp): Agentic Observability MCP is a freemium MCP server for analytics and data.
- [Tokmeter — AI Agent Usage & Cost](https://ai-powered.com/mcp/tokmeter-ai-agent-usage-and-cost): Tokmeter — AI Agent Usage & Cost is a free MCP server for developer tools.
- [Budgetary: estimate token spend](https://ai-powered.com/mcp/budgetary-estimate-token-spend): Budgetary: estimate token spend is a freemium MCP server for developer tools.

---
Source: https://ai-powered.com/mcp/agent-token-forensics
