# ctx-profiler

> ctx-profiler is an open-source MCP server for developer tools. Profiles token waste in Claude Code, Codex and Cline session logs and simulates compaction. It runs locally on your machine and is started by your AI client.

- **Kind:** MCP server
- **Pricing:** Open source
- **Platforms:** CLI, API, macOS, Linux, Windows
- **Repository:** https://github.com/cuhawk/ctx-profiler
- **MCP Registry name:** io.github.cuhawk/ctx-profiler
- **Categories:** [developer tools](https://ai-powered.com/categories/developer-tools)
- **Listing updated:** 2026-11-30

## About

Coding-agent sessions quietly resend the same context on every turn, so a large tool output or repeated file read keeps costing tokens for the rest of the session. This tool replays multi-turn transcripts from agent harnesses turn by turn and assigns every token to one of six buckets, separating waste such as file re-reads, oversized tool output and replayed reasoning from useful new work.

It also runs five compaction policies against a log to estimate how many tokens and dollars each one would save before any harness code is changed. Costs can be computed from built-in model pricing or overridden with custom per-million-token prices, which suits self-hosted models.

The project is aimed at developers who build or tune coding-agent harnesses and want measured numbers rather than guesses. It is a pure Python package with a command-line interface and a stdio MCP server, so an assistant can profile its own transcripts.

## Features

- **Six-bucket token attribution:** Every token in a session is assigned to exactly one category, so totals always reconcile with the reported count.
- **Compaction policy simulation:** Compares five deterministic trimming policies and reports tokens saved and estimated cost savings per policy.
- **Cache-aware cost reporting:** Shows both cache-aware cost and uncached list cost so savings are not overstated when prompts are cached.
- **Multiple harness formats:** Auto-detects transcripts from Claude Code, Codex, Cline, OpenClaw and OpenAI traces.
- **Flexible output formats:** Exports results as terminal tables, Markdown, JSON, CSV or SVG charts.
- **MCP server interface:** Exposes log analysis and compaction simulation as tools that an MCP-compatible agent can call.

## Good for

- Finding which tool outputs and repeated file reads inflate a coding agent's context
- Comparing candidate context compaction policies before changing agent harness code
- Estimating cache-aware API cost of long coding sessions
- Letting a coding agent profile its own session logs through MCP

## Install

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

```sh
claude mcp add ctx-profiler -- uvx ctx-profiler
```

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": {
    "ctx-profiler": {
      "command": "uvx",
      "args": [
        "ctx-profiler"
      ]
    }
  }
}
```

### Claude Desktop (claude_desktop_config.json)

```json
{
  "mcpServers": {
    "ctx-profiler": {
      "command": "uvx",
      "args": [
        "ctx-profiler"
      ]
    }
  }
}
```

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

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

```json
{
  "mcpServers": {
    "ctx-profiler": {
      "command": "uvx",
      "args": [
        "ctx-profiler"
      ]
    }
  }
}
```

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

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

```json
{
  "mcpServers": {
    "ctx-profiler": {
      "type": "stdio",
      "command": "uvx",
      "args": [
        "ctx-profiler"
      ]
    }
  }
}
```

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 ctx-profiler -- uvx ctx-profiler
```

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

```toml
[mcp_servers.ctx-profiler]
command = "uvx"
args = ["ctx-profiler"]
```

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

```json
{
  "mcpServers": {
    "ctx-profiler": {
      "command": "uvx",
      "args": [
        "ctx-profiler"
      ]
    }
  }
}
```

Or run: gemini mcp add -s user ctx-profiler uvx -- ctx-profiler

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

```json
{
  "mcpServers": {
    "ctx-profiler": {
      "command": "uvx",
      "args": [
        "ctx-profiler"
      ]
    }
  }
}
```

Use .agents/mcp_config.json to add it to one workspace only.

### Devin Desktop (~/.config/devin/mcp_config.json)

```json
{
  "mcpServers": {
    "ctx-profiler": {
      "command": "uvx",
      "args": [
        "ctx-profiler"
      ]
    }
  }
}
```

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": {
    "ctx-profiler": {
      "command": "uvx",
      "args": [
        "ctx-profiler"
      ]
    }
  }
}
```

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

### Zed (Zed settings.json)

```json
{
  "context_servers": {
    "ctx-profiler": {
      "command": "uvx",
      "args": [
        "ctx-profiler"
      ]
    }
  }
}
```

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": {
    "ctx-profiler": {
      "command": "uvx",
      "args": [
        "ctx-profiler"
      ]
    }
  }
}
```

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

```json
{
  "mcpServers": {
    "ctx-profiler": {
      "command": "uvx",
      "args": [
        "ctx-profiler"
      ]
    }
  }
}
```

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

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

```json
{
  "mcpServers": {
    "ctx-profiler": {
      "command": "uvx",
      "args": [
        "ctx-profiler"
      ]
    }
  }
}
```

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": {
    "ctx-profiler": {
      "command": "uvx",
      "args": [
        "ctx-profiler"
      ]
    }
  }
}
```

## 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_session_log` (name suggests: reads): Analyzes a coding-agent session log and attributes tokens to categories.
- `simulate_compaction`: Simulates compaction policies on a session log and reports savings.

## FAQ

### How do I install ctx-profiler?

It can be run with uvx from the project directory, or installed with pip install -e . for a local editable install. The core has no required runtime dependencies beyond Python 3.10 or newer.

### Which agent formats are supported?

Transcripts from Claude Code, OpenAI Codex CLI, Cline, OpenClaw and OpenAI traces are supported, and the format is detected automatically.

### Does the simulator check whether the agent still completes tasks?

No. The simulation computes token economics under deterministic transformations and does not re-run the model, so task accuracy needs a separate evaluation.

### What license is ctx-profiler under?

The project is released under the MIT license.

### Is ctx-profiler free?

Yes. ctx-profiler is open source, so you can use and self-host it for free.

### How do I add ctx-profiler to Claude Code?

Run this command in your terminal: claude mcp add ctx-profiler -- uvx ctx-profiler

### What are the best alternatives to ctx-profiler?

The closest alternatives to ctx-profiler are Agent Token Forensics, Tokenscope, context-doctor, TokenSlim MCP — verifiable token reduction for agents and Token Optimizer 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.

## Alternatives

- [Agent Token Forensics](https://ai-powered.com/mcp/agent-token-forensics): Agent Token Forensics is an open-source MCP server for developer tools.
- [Tokenscope](https://ai-powered.com/mcp/tokenscope): Tokenscope is an open-source MCP server for developer tools.
- [context-doctor](https://ai-powered.com/mcp/context-doctor): context-doctor is an open-source MCP server for ai models and llm tooling.
- [TokenSlim MCP — verifiable token reduction for agents](https://ai-powered.com/mcp/tokenslim-mcp-verifiable-token-reduction-for-agents): TokenSlim MCP — verifiable token reduction for agents is an open-source MCP server for developer tools.
- [Token Optimizer MCP](https://ai-powered.com/mcp/token-optimizer-mcp): Token Optimizer MCP is an MCP server for ai models and llm tooling.
- [Sipcode](https://ai-powered.com/mcp/sipcode): Sipcode is an open-source MCP server for developer tools.
- [Compress-token](https://ai-powered.com/mcp/compress-token): Compress-token is an open-source 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/ctx-profiler
