My Claude Code agents were spending 200k tokens reading my bug log before doing anything
retained text
I still see people complaining that AI sucks at writing code. Too long, ignores the components you already have, impossible to maintain. If you open one chat and type "build me a feature", yeah, that's exactly what you get. I'm building a synth plugin in C++ (JUCE) on my own, about 144,000 lines so far, and Claude Code does basically all of the typing. One main session plans, briefs and checks, and up to 6 agents do the work, each in its own git worktree. It works, but it took a lot of setup and most of it I learned by watching things go wrong. There is NO enforcement in a skill or in CLAUDE.md. Claude reads them and mostly follows them, and mostly isn't good enough when 6 agents run for hours. Hooks are the only thing that can actually stop it. A PreToolUse hook that exits with code 2 blocks the call, and whatever it prints to stderr goes back to Claude as the reason. Mine refuse git add -A, --no-verify, a commit straight to main, a 7th agent, a build started outside my build queue and sleep loops. If you're starting out, make your first hook the one that refuses git add -A. It's a few lines: read the command, say why, exit 2. Always print what to do instead, or it just tries the next way around. And block, don't rewrite. I had a hook that quietly changed agents' commands and auto mode started refusing them as attempts to get around it. Fair enough honestly. The briefs cost me the most tokens, and it's easy to miss why. When you start a project your plan file and bug log are basically empty, so "read build.md and bugs.md first" is a cheap line to put in a brief. Then Claude writes to them every day, you never open them yourself, and you don't notice they've grown to 290 KB and 284 KB. Every agent was burning around 200k tokens and several minutes on them before doing anything. Now a small script greps out the exact lines a job needs (its step in the plan, its bug) and those get pasted into the brief with the exact commands to run. Same job, same agent: 600k+ tokens before, 61k after. Just starting an agent costs about 58k, so I run fewer agents with better briefs. Every brief also lists the files the job should need, and a hook compares every read against that list. Going off the list is allowed, sometimes it really does need a header it found, but I get told, and it's usually a hole in my brief. After 10 it gets stopped and has to ask. Then the machine. I had 11 agents at once on an M5 Max (18 cores, 128 GB) and the load sat at 85. Everything got slower and nothing finished sooner. Now it's max 6 agents, max 2 that compile, and every compile, test run and render goes through one queue (a bash script with mkdir locks as slots, and a hook that refuses anything started outside it). The queue sets -j and the thread count per job from the cores actually free and keeps 4 for me. Even then I found one test program on 10 cores because it sized its thread pool by the core count. Some of the slowness wasn't the AI at all. A panel export took 80 minutes because it started a fresh headless Chrome for each of \~460 images. One Chrome for the whole run: 19 seconds. A shared ccache across worktrees took a fresh worktree build to 52 seconds, 605 of 608 files from cache. I don't trust the reports either. An agent told me our sub oscillator was "at or above" the reference synth. I listened and it clearly wasn't. It had measured relative to its own fundamental, and absolute band energy said 1 to 16 dB short. Anything that matters I check myself. CPU at 100% doesn't mean progress either. I watch the job's own output, "test 14/41" and how long since it last printed. One that fooled me: a program writing into a pipe buffers its output, so the log stays empty and a job working flat out looks dead. `script -q /dev/null <cmd>` gives it a terminal and it prints line by line. All of that ends up in my statusline, one line per agent with model, tokens, age, last save, last action and what its job is doing, going yellow then red as things go stale. Most problems I catch because a number turned red. If you build one, start with two things per agent: how long since it last did anything, and what it's running right now. A hook writes them to a file on every tool call and the statusline reads that file. Models: I gave Opus, Sonnet and Haiku the same hard questions and all three got them right. On a multi-hour job Haiku sent duplicate reports and kept restarting builds after it said it was done. So Haiku for lookups, Sonnet for most of the work, Opus when I'm not sure Sonnet can. None of this runs unattended. I adjust the hooks pretty much every day based on what the agents actually do. Still beats code reviewing 20 developers. Would love input on peoples workflows and how you monitor your agents
document fetched 2026-10-12 00:35 · canonical https://reddit.com/r/ClaudeCode/comments/1x3d6uv/my_claude_code_agents_were_spending_200k_tokens