Claude Code Subagents, Faturamın % 48 ‘ini oluşturuyordu. Çıktıları % 0,9 idi

https3A2F2Fdev-to-uploads.s3.us-east-2.amazonaws.com2Fuploads2Farticles2Ff59fd4gv4qhf3d263jt3

I thought my expensive Claude Code habit was long sessions. I was half right. When I finally broke down a month of usage, Claude Code subagents cost 48% of my entire bill , and the tokens they wrote back to me were 0.9% of the total. Almost all of the money went into reading, not writing. Each subagent starts with roughly 51K tokens of context , and it re-reads that context on every single request it makes. This is the autopsy, the mechanism behind it, and the rules I now run with. TL;DR Claude Code subagents are billed mostly for input, not output. Every tool call in an agent loop re-sends the full context: system prompt, tool schemas, CLAUDE.md, memory, and the conversation so far. In my setup, each subagent started at ~51K tokens before doing anything. Fan-out workflows made agents 48% of my Claude cost while output was 0.9% . Cost scales with number of agents × number of requests per agent × context size , not with how useful the answer is. Long main sessions have the same disease: 45 sessions over $100 were 79% of my spend , and requests above 400K tokens were 54% of main-session cost. Fixes that actually move the number: cap agents per run, batch small units into one agent, trim the starting context, and hand off to a fresh session before context gets huge. How did I measure where my Claude Code money went? I parsed the session transcripts Claude Code writes locally and grouped usage by session and by whether the message came from the main thread or a subagent. Each assistant message carries a usage block, so the breakdown is just arithmetic. Here's the shape of the script. Field names are what I saw in my version; check yours. import json , glob , os from collections import defaultdict totals = defaultdict ( lambda : defaultdict ( int )) for path in glob . glob ( os . path . expanduser ( " ~/.claude/projects/**/*.jsonl " ), recursive = True ): with open ( path ) as f : for line in f : try : row = json . loads ( line ) except json . JSONDecodeError : continue msg = row . get ( " message " ) or {} usage = msg . get ( " usage " ) if not usage : continue bucket = " subagent " if row . get ( " isSidechain " ) else " main " for k in ( " input_tokens " , " cache_creation_input_tokens " , " cache_read_input_tokens " , " output_tokens " ): totals [ bucket ][ k ] += usage . get ( k , 0 ) or 0 for bucket , t in totals . items (): print ( bucket , dict ( t )) Then I multiplied each token class by its rate for the model that produced it. I'm not printing prices here because they change and yours depend on your plan. The shares are what matter. The result on my machine: Measure Value Share of Claude cost from workflow subagents 48% Starting context per subagent ~51K tokens Output tokens as share of the total 0.9% Sessions over $100 45 , together 79% of cost Main-session requests over 400K tokens 54% of main-session cost The first line surprised me. The third one annoyed me. Why do Claude Code subagents cost so much? Because an agent is not one request. It's a loop, and every iteration of the loop re-sends the whole context window. A subagent that reads three files, greps twice, edits one file and reports back makes maybe eight model requests. Each of those requests includes: The system prompt Every tool's JSON schema (including MCP tools you forgot were loaded) Your CLAUDE.md files and memory index The skill and agent listings The task prompt Every tool result so far Items 1 through 4 are the fixed tax. In my setup that tax was about 51K tokens. The subagent pays it on request one, request two, request eight. Then item 6 grows on top. Quick napkin math, using my own 51K baseline: 1 subagent × 20 requests × 51K = ~1M input tokens before counting any file it read 15 subagents in one fan-out = ~15M input tokens of mostly identical preamble Prompt caching makes those re-reads much cheaper than fresh input. Cheaper is not free. When you multiply a discounted number by fifteen agents and twenty turns, it's still the biggest line on the bill. Why is output only 0.9% of the cost? Because agent work is read-heavy by nature. A subagent reads 30 files to write a 400-word summary. It reads a test log to decide "yes, it passes." The useful artifact is tiny; the evidence it had to look at is huge, and the preamble is repeated on top. That 0.9% number reframed how I think about "expensive models." I used to worry about verbose answers. Verbosity was a rounding error. Context size times request count was the whole game. What made my fan-out workflows especially bad? Three habits, all mine: One agent per tiny unit. I'd fan out "one agent per file" for a 25-file audit. Each agent paid the 51K entry fee to look at one file of maybe 2K tokens. The preamble outweighed the actual work by an order of magnitude. Every agent on the big model with full effort. Mechanical jobs like "extract every env var name from these files" don't need deep reasoning. I was paying top-tier rates for grep with extra steps. A fat global context. My global CLAUDE.md, memory index, MCP servers and skill listings all ride along into every subagent. A line I added once for a niche workflow got re-read tens of thousands of times by agents that never needed it. Are long Claude Code sessions just as expensive? Yes, for the same reason. A main session is also an agent loop, and the conversation keeps growing. On my machine, 45 sessions that crossed $100 accounted for 79% of all spend . Inside the main thread, requests above 400K tokens were 54% of the cost . Once a session is that large, every "ok, now also fix the typo" pays to re-send the whole history. The painful part: most of that history was irrelevant to the next step. I'd switched topics twice, and the session was still carrying a failed refactor from two hours earlier. How do I cut Claude Code subagent costs? These are the rules I now run with. They're written into my global instructions so Claude follows them without me nagging. 1. Cap agents per run. My default ceiling is 20 subagents per workflow. Going over requires saying the count and the reason before launch. Just having to justify it kills most over-fanned plans. 2. Batch small units into one agent. Instead of 25 agents for 25 files, I give one agent 5 to 8 files. The 51K entry fee gets split across real work. Cost scales with agent count, not file count. 3. Route mechanical work to cheaper effort. Collection, extraction and formatting run at low effort. Review, verification and synthesis inherit the main session's model and effort. Judgment is where the reasoning budget belongs. 4. Trim the fixed preamble. I moved project-specific rules out of the global CLAUDE.md into each repo's own file, and I start quick runs with an empty MCP config. Every token removed from the preamble is saved once per request per agent. 5. Hand off before 400K. When the topic changes or context passes 400K tokens, Claude writes a short handoff memo (what's done, what's next, which files) and I start a new session. A 500-token memo replaces hundreds of thousands of tokens of stale history. 6. Don't delegate single lookups. If I already know the file and the symbol, a direct read beats spawning an agent. Subagents earn their keep when they'd otherwise dump dozens of files into my main context. What I don't know yet I haven't run a clean before/after month under these rules, so I'm not going to claim a savings percentage. My usage mix also skews toward big audits and research fan-outs; if you mostly do single-file edits, your subagent share will be far lower. What I'm confident about is the mechanism. It isn't specific to my setup. Any agent loop re-sends its context every turn, and any fan-out multiplies that by the number of agents. So why were Claude Code subagents 48% of my bill? Claude Code subagents were 48% of my bill because every subagent started with about 51K tokens of fixed context (system prompt, tool schemas, CLAUDE.md, memory, skill listings) and re-sent all of it on every request in its loop, while the text they actually produced was only 0.9% of tokens. Cost grows with agents × requests × context size, so the fix is structural: fewer agents doing more work each, cheaper effort for mechanical jobs, a leaner global context, and fresh sessions before context balloons past 400K tokens. Written by the developer behind Preterview , an interview prep platform.

#code #subagents #bill #output #was

Kaynak: Dev.to

Alinti: Bu haber Dev.to tarafindan yayinlanmistir. Haberin tamamini ziyaret ederek okuyabilirsiniz.

Guncelleme: 24.09.2026 05:26 – Barış Tekin haber derlemesi

Yazı gezinmesi

Mobil sürümden çık