cd /news/developer-tools/ai-agent-profiler-measure-agent-cost… · home topics developer-tools article
[ARTICLE · art-67701] src=dev.to ↗ pub= topic=developer-tools verified=true sentiment=· neutral

AI Agent Profiler — Measure agent cost, cache waste, and context bloat

A developer built a local-first profiler that acts as a transparent reverse proxy between coding agents and LLM providers, revealing that only ~60% of API costs go to actual prompts while the rest is agent overhead. The tool classifies requests into 11 types and tracks cache waste, showing that a 5-minute cache TTL penalty can cause expensive cold regenerations on long sessions.

read2 min views1 publishedJul 21, 2026

I built a local-first profiler that sits as a transparent reverse proxy between your coding agent (Claude Code, OpenCode) and the LLM provider, recording every request without adding latency. It's like perf

for your agent — showing you exactly where your tokens go.

Live demo (read-only dashboard with sample data).

Only ~60% of my API cost was my actual prompts. The rest was agent overhead I never saw — subagent exploration (search

), context compaction, catch-up summaries when I stepped away, and session-title generation. The profiler classifies every request into 11 kinds (main

, search

, compact

, recap

, title

, subagent

, webfetch

, quota

, tool_result

, guide

, unknown

) and shows a "Cost by kind" table. The search

subagent alone ate ~25-30% of tokens when I told the agent "explore thoroughly."

The 5-minute cache TTL penalty is real and expensive. Claude Code places cache_control: {"type": "ephemeral"}

markers without an explicit TTL — so your cached prefix (system prompt, tools, message history) expires after ~5 minutes of inactivity. Step away to read docs or grab coffee, come back, and the next request pays a full cache write on potentially 200K+ tokens. On Opus models, a cache write is a massive multiplier on your first request back. The profiler detects cold regenerations, marks them with severity badges, and shows exactly what each idle gap cost you.

Long sessions compound it. Every turn grows the cached prefix, so cold-refresh costs grow linearly. A 3-hour session can re-write 200K+ tokens on each expiry. The profiler tracks context growth over time and flags when tool definitions alone account for 10-15K tokens re-sent on every call.

I tried to optimize and mostly failed. I built a full optimization layer (pruning stale tool results, collapsing system prompts, removing unused tools) and benchmarked it. Early numbers looked spectacular — but they were wrong. Cross-session cache warming inflated baselines, and the cost model initially ignored cache-write tokens. Once both were fixed, savings vanished. Editing the cached prefix turns cheap reads into expensive writes, and the client re-sends the pristine full history every turn anyway. I wrote up the autopsy in the repo under docs/optimization/FINDINGS.md.

npm install -g ai-agent-profiler
aap install              # seeds config
aap serve                # terminal 1: proxy + dashboard at :8080/ui
aap run claude           # terminal 2: launch Claude Code through the proxy

Supports Anthropic, OpenAI, DeepSeek, AWS Bedrock (SigV4), and Ollama. Zero telemetry, secrets redacted. All metrics rebuildable from raw traces.

Repo: https://github.com/rguiu/ai-agent-profiler

── more in #developer-tools 4 stories · sorted by recency
── more on @claude code 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/ai-agent-profiler-me…] indexed:0 read:2min 2026-07-21 ·