ctx-profiler
Profiles token waste in Claude Code, Codex and Cline session logs and simulates compaction
ctx-profiler 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, macOS
- Runs
- Locally
- Version
- 0.1.1
- 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 ctx-profiler -- uvx ctx-profilerAdd --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": {
"ctx-profiler": {
"command": "uvx",
"args": [
"ctx-profiler"
]
}
}
}Add to claude_desktop_config.json
{
"mcpServers": {
"ctx-profiler": {
"command": "uvx",
"args": [
"ctx-profiler"
]
}
}
}Settings → Developer → Edit Config, then quit and reopen Claude Desktop.
Add to ~/.cursor/mcp.json
{
"mcpServers": {
"ctx-profiler": {
"command": "uvx",
"args": [
"ctx-profiler"
]
}
}
}Use .cursor/mcp.json in a project to share it with the project.
Add to ~/.copilot/mcp-config.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.
Add with the CLI
Run in a terminal
codex mcp add ctx-profiler -- uvx ctx-profilerOr add to config.toml
Add to ~/.codex/config.toml
[mcp_servers.ctx-profiler]
command = "uvx"
args = ["ctx-profiler"]Add to your client's MCP settings (most use this shape)
{
"mcpServers": {
"ctx-profiler": {
"command": "uvx",
"args": [
"ctx-profiler"
]
}
}
}Gemini CLI and Antigravity
Gemini CLI
Add to ~/.gemini/settings.json
{ "mcpServers": { "ctx-profiler": { "command": "uvx", "args": [ "ctx-profiler" ] } } }Or run: gemini mcp add -s user ctx-profiler uvx -- ctx-profiler
Antigravity
Add to ~/.gemini/config/mcp_config.json
{ "mcpServers": { "ctx-profiler": { "command": "uvx", "args": [ "ctx-profiler" ] } } }Use .agents/mcp_config.json to add it to one workspace only.
Devin Desktop (formerly Windsurf)
Add to ~/.config/devin/mcp_config.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
Add to cline_mcp_settings.json
{ "mcpServers": { "ctx-profiler": { "command": "uvx", "args": [ "ctx-profiler" ] } } }Open it from the MCP Servers icon → Configure → Configure MCP Servers.
Zed
Add to Zed settings.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
Add to Settings → Tools → AI Assistant → Model Context Protocol (MCP) → Add
{ "mcpServers": { "ctx-profiler": { "command": "uvx", "args": [ "ctx-profiler" ] } } }Junie
Add to ~/.junie/mcp/mcp.json
{ "mcpServers": { "ctx-profiler": { "command": "uvx", "args": [ "ctx-profiler" ] } } }Use .junie/mcp/mcp.json to share it with a project.
Kiro
Add to ~/.kiro/settings/mcp.json
{ "mcpServers": { "ctx-profiler": { "command": "uvx", "args": [ "ctx-profiler" ] } } }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 ctx-profiler
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.
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_session_logName 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.
What it does
- 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
Pricing
Open source
Free and open source under the MIT license.
ctx-profiler 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.