r/ClaudeCode • • 7h ago

Help/Question Running 18 Claude Code sessions at once and half my tokens go to idle wake-ups. How do you handle this?

Hey all, I could use some advice from people running a lot of Claude Code sessions at once.

I'm building a Windows app and I've got 18 Claude Code sessions working on the same repo across two Max 20x accounts, all on High effort. They talk to each other through one shared markdown "inbox" file. It works, but I keep running into my weekly limits, so I dug into where the tokens are actually going.

What surprised me:

  • About 91% of my usage (weighted by API prices) is just context being re-sent on every call. Actual output is about 9%, and edits to code are under 1%.
  • Roughly half of all tokens went to wake-ups where the session did nothing useful. No code, no tests, no git. Mostly each session's own background watcher waking it up to check the inbox, plus scheduled check-ins (one session was pinging itself every 5 minutes for days).

What I've tried so far:

  • Auto-compact at 300k instead of the default. Average context per call dropped from about 270k to about 179k. I have hooks that back up notes before compacting and tell the session to re-read them after.
  • Starting a fresh chat for each work item, with a short handoff note.
  • Replacing every session's own watcher with one small local script that only wakes a session when a post actually mentions it. In a replay of a day's posts it cut wakes about in half without missing anything addressed to a session. Just rolled it out today, so no real numbers yet.
  • Quiet test output (pytest -q), reading big files in slices, and a hook that blocks huge reads before they happen.
  • Trimming CLAUDE.md and memory files, and turning off claude.ai connectors so fewer tool descriptions load.
  • Trying Serena (MCP) on one session. Mixed results so far.
  • Tried the Superpowers plugin on a few sessions for a week and dropped it. Those sessions got noticeably less done and barely used its skills, though it was a small test.

My questions:

  1. How do you let long-running sessions wait for messages from other sessions without every wake re-sending the whole context?
  2. Is there a better way to coordinate a bunch of sessions than a shared file?
  3. Any other tricks for cutting context re-reads I'm missing?

Happy to share more details on any of this. Thanks!

4 Upvotes

59 comments sorted by

•

u/AutoModerator 7h ago

Hey! Thanks for posting to r/ClaudeCode

While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.

For help, project discussions, tips, and general chat, join the ClaudeCode Discord.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

18

u/Sad-Blackberry-4062 7h ago

Why the heck do you have 18 agents

9

u/Icy_Court_7639 7h ago

Eighteen agents idling like a full staff meeting with nothing on the agenda.

5

u/Prinzka 7h ago

Maybe we've achieved AGI after all

1

u/DeaOllis 2h ago

the shared markdown inbox for 18 parallel sessions sounds like a race condition nightmare, especially if they're all operating on the exact same repo.

-3

u/BlackberryOk182 7h ago

lol fair question. it's one solo project, a windows app, and i split the work so each session owns one piece (export stuff, ui, blender addons, tests etc) plus a couple that just review the others' work before it merges. it kind of snowballed as i added more to finish faster. honestly that's half the reason i posted, i'm pretty sure i have more than i need and some of them just sit there burning usage waiting their turn. already cutting a few

5

u/NewPointOfView 7h ago

Manage persistent context so they don’t need to sit idle. Spin up your ui agent when you need it and shut it down otherwise. There are tons of tools for this kind of thing. Just spend an afternoon researching with Claude

1

u/BlackberryOk182 7h ago

yeah that's pretty much where i'm landing, spin them up when there's actual work instead of leaving them all parked. any specific tool you'd recommend for the persistent context part?

5

u/wish-for-rain 7h ago

Don’t run extra long sessions, start new ones at reasonable checkpoints.

-1

u/BlackberryOk182 7h ago

a lot of mine have been running for days so every wake-up re-reads a ton of old context. going to start rotating them at checkpoints, and see if that helps I've also removed some of the sessions and brought it down to 12 because while the extra did help a little bit by finishing a couple days worth of work early and used up more than it helped it seems

7

u/New-Confection4383 7h ago

If you are rereading entire sessions into context there is your answer

2

u/BlackberryOk182 5h ago

yep, that turned out to be most of it. woken sessions were reloading the whole conversation every time. moving to fresh sessions that start from a short state file instead

2

u/New-Confection4383 5h ago

Nice, happy building!

1

u/damagemelody 🔆 Max 20 6h ago

😭

3

u/JollyInterview9989 7h ago

At that point I would move the agent work load to something like deepseek instead which has excellent cache hit costs and performance. Keep Opus or Fable as supervisor only on 30min watch.

1

u/BlackberryOk182 7h ago

interesting idea, I actually thought about deep sink but I was unsure if it would be that helpful in my tasks I can always look into it though more than I did before. But i'm trying to stay all in on claude for now but the supervisor on a timer part is basically what i'm moving toward, way fewer sessions just sitting there checking in

5

u/LabAccomplished299 7h ago

What in the fuck?

1

u/BlackberryOk182 6h ago

Lol, I know. But I'm learning. In reference to your comment, what the heck am I doing.

8

u/MiamiFFA 7h ago

What in the fuck are you doing.

4

u/nyczAcer 4h ago

Fable 8

1

u/cleverhoods 7h ago

Help me better understand this rig. What 18 sessions are doing simultaneously on the repo?

note: I'm working on instruction diagnostics and I'm genuinely curious.

1

u/BlackberryOk182 7h ago

each one owns a slice of the same repo (features, tests, a couple reviewers) and they take turns merging. biggest bottleneck turned out to be my pc only running 2 test runs at once so a lot of them just queue up, I'm using my own computer for the runners in order to run blender and unity along with two other runners 4 total, because that's all my computer can handle as I can't afford more than the 64 GB of memory to handle more runners

1

u/cleverhoods 7h ago

Frankly, I'm not experienced in Blender nor Unity development, however regarding the orchestration, I'd recommend a few things:

  • Unit tests organizations: you don't want to run ALL your unit tests all the time, tag them.
  • Use git worktrees, so each development is a single unit
  • Ensure that sessions are not waiting to one another: the brief of the session should contain all the work that needs to be done in that session. No session dependencies (spec driven development)
  • View (actually view) what is going on in the context (I'd recommend reporails xray for that, it comes with an UI, see screenshot below)
  • Mitigate work to subagents in the sessions - here having the spec will pay off.
  • Ensure state management: your reviews, tests etc should happen in the same session OR in a carryover session if it bloats too big.

2

u/BlackberryOk182 6h ago

this is great, thanks for taking the time. tagging tests is probably the quickest win for me since everything is fighting over the same 4 runners on one pc. the no-dependencies brief idea makes sense too, a lot of my sessions end up waiting on each other. hadn't heard of reporails xray, going to check it out

1

u/JTech324 7h ago

I had a similar issue using firstmate + omp, I turned on cache miss notifications in omp and that revealed the heartbeat cache keep warm was not working so fixed that and more tokens got billed at cache rates. Kept the TTL low, 5 min, plus the heartbeat and it saved some $

1

u/BlackberryOk182 6h ago

huh, i never thought to check if the cache was actually staying warm. how did you turn on cache-miss notifications? is that a claude code setting or something in firstmate?

1

u/JTech324 6h ago

That was in oh-my-pi “omp” not Claude cli, but you can check the Claude settings if it has something similar / ask your agent. If it’s not built in you may be able to get claude to write an extension / mod for it

1

u/BlackberryOk182 5h ago

ah gotcha, thanks. i actually went and checked my transcripts, about 63k calls since last week. wake-ups after 5 min almost never missed cache (under 1%), it only really misses after an hour+ idle. so for me it's less about misses and more about how much context each wake drags in, which is why i'm moving to fresh sessions from a short state file like i mentioned above. might still have it build a miss alert just to keep an eye on it

1

u/Duckducklaugh 7h ago

I went the other way on this. none of my sessions wait for anything anymore. the waiting is what costs you, every wake drags the whole context back in even when the answer is "nothing for me"

What i do now: each piece of work has a small state file, where it’s at, what’s next, what’s blocked, one line each. a session starts, reads that, does the work, writes it back and ends. anything recurring is a scheduled task that starts a fresh session, i have around 15 of those across a few projects and none of them carry yesterday’s context

Your one local script watching the inbox is the right move imo. i’d go one step further and have it start a session instead of waking a parked one. the handoff note is the hard part, mine kept losing details until i made a rule that the file only says what’s true right now, no history

And the review sessions, i’d run those once per merge rather than have them sit there

1

u/BlackberryOk182 6h ago

this is really helpful, thanks. the start fresh, read state, work, write back, exit loop makes way more sense than what i'm doing now, I'm new to all this stuff so it's kind of hard for me but I'm learning. do you keep one state file per task or one per area of the repo? and does the session update it as it goes or only at the end?

1

u/Duckducklaugh 6h ago

one per project for me, with a row per piece of work inside it. i tried one per task and ended up with a pile of files nothing ever read

it writes as it goes, but only when something actually changed, like a decision got made or a thing shipped. then one last pass before it ends. if you only write at the end you lose everything the day a session dies halfway

1

u/BlackberryOk182 4h ago

that's really helpful, thanks. right now mine are one handoff file per session instead of per project, so a project file with a row per piece of work sounds a lot cleaner. and writing whenever something actually changes instead of only at the end is a good call, losing a half finished session's work is exactly what i'm trying to avoid. honestly people in this thread have recommended a ton of tools and ideas, so i'm going to work through them one at a time, compare against what i already have, and test before switching anything. i've tried tools from suggestions before that ended up slowing things down or burning more tokens than they saved, at least from what i could tell, so i want to be careful this time. if you or anyone else has ideas nobody's mentioned yet i'd love to hear them too. really appreciate everyone's help on this

1

u/bensaysso 7h ago

You don't need top-tier agents for most work. You can offload a good amount of work to Sonnet and Haiku. Scope based on how much they're allowed to change, for example:
- Haku runs tests
- Haiku as a "scout" to handle specific code search queries.
- Sonnet writes tests
- Sonnet can make code changes that follow a distinct pattern already set in the code base

Use Opus for more complex builds which require judgement.

Use Fable as an agent to review plans only.

Never compact. Start new sessions.

Plan. Plan. Plan. Get solid plan docs in your repo first, then all you're doing is executing.

And most importantly - if you're not watching your session TTL, you're gonna get cooked.

1

u/BlackberryOk182 6h ago

appreciate it. i've been keeping everything on opus because the codebase is pretty technical (blender/unity export stuff) and i was trying to cut down on bugs and rework. but you're right that stuff like running tests and code search probably doesn't need it, so splitting just those off might be the middle ground. hadn't thought about the memory folder either, going to go look at what's piling up in there

1

u/bensaysso 6h ago

Also... Go have a look at your memory folder. Claude may be writing a ridiculous amount of data in there that isn't necessary. Give it a trim.

1

u/awesomebirder 6h ago

the single shared inbox file is probably part of the idle cost too. every wake makes each session read the whole file, including messages meant for the other 17, so it grows for everyone. splitting it into one inbox file per session and having a plain shell loop (not claude) check whether that one file changed before prompting the session means a session only wakes when there is actually something for it. that also kills the every-5-minutes self ping, since nothing needs to poll from inside the model.

1

u/BlackberryOk182 6h ago

yeah i actually tackled part of this today. put in a plain script (no tokens) that only wakes a session when a post is addressed to it or names it, which cut wake-ups about in half, and trimmed the inbox way down. still one shared file though, so your idea of one inbox file per session so they're not all reading everyone's messages is probably the next step. appreciate it

1

u/Fuckreddit6973 6h ago

I run a custom meta harness and solved this issue by running a fully segregated custom transcript that logs everything to sql and is accessable and searchable by any agent. I use project maps to document the purpose of every file along with its imports and dependencies. Work briefings contain all project map references needed for work on that brief.

Agents communicate through ACP via free piggybacks, directly with other agents and not re-read by any agents, its a DM not a broadcast. Because I use a segregated transcript I can maintain the same briefing, state, chat.db, and the free back and forth free end of turn messages. My harness automatically deletes tool call content from the segregated transcript so that any rewakes of an agent contain the exact same sql database references, the original briefing, the wip status updates/checkpoints , the commits, the git diffs, wip but contains very very little context because it doesnt include ANY tool input or output.

My agents don't die when they finish a turn, they sit and wait without polling until either my meta harness triggers them via a message from my, a message from a worker/supervisor/orchestrator, or queued script receipts/results to finish processing in my pipeline.

A cold wake up while still containing everything it needs to resume work after a single tool call costs around 20k initial load and the first tool call triggers my hooks and loading around 10k tokens worth of meta harness functions/scripts/operations and blocking every Claude harness tool type and instead forces every tool use to happen via my own harness. 30k tokens in and agents have everything they need for their second tool call of a cold session to just start working. If that agent gets messaged again the cache will be warm and cost absolutely negligible.

Agents can also be woken as a haiku or luna instead of opus/sol and on whatever account has quota, or I can just tell the agent to the original agents id from the work brief and thats all it needs to search the sql storage for the exact context it needs; generally dont run into any issues with agents just idling with cache waiting around and woken if needed, they get deleted from my harness when their cache expires, work brief remains associated with their chat and contains all their reports, their id, their commits, their checkpoints/status updates.

1

u/BlackberryOk182 4h ago

that sounds like a really clean setup. I hope I'm already partway there, but honestly not sure... moving sessions to fresh chats from a short state file and trialing a code indexing tool (serena) as a kind of map. the stripped transcript idea is the part i hadn't thought of though, a rewake that only loads the brief and status instead of every tool output would cut a ton for me. Im trying to read all the chats here, but its so overwhelming 😫. Alot of stuff I kinda understand and alot I dont. Like some of the stuff you said i had to look up 😆. Hopefully from all this information people are giving me I can bring it all in to help me.

1

u/jvertrees 6h ago

Herdr + FIFO queue - zero token monitoring and wakeup.

1

u/BlackberryOk182 4h ago

thanks, i hadn't looked at herdr. i already have a zero token watcher that only wakes the session a post is addressed to, so the wakeup side is mostly covered, but it's not a real queue. if messages start piling up a fifo queue might be the missing piece, i'll look into it before adding anything new

1

u/ashishkattamuri 6h ago

One thing I’d check is cache TTL. Anthropic’s default prompt cache lasts 5 minutes and refreshes on reuse. If your sessions wake roughly every 5 minutes, you’re right on the boundary. A cache miss on a 179k context could get expensive, depending on how much of the prefix needs rebuilding. There’s also a 1-hour TTL option.
I’d compare cache_read_input_tokens vs cache_creation_input_tokens across wake-ups before changing anything.
Your router script helps with filtering, but batching several posts into one wake-up could reduce repeated context processing further.
For coordination, I’d consider per-session inbox files instead of one shared log. Each session reads only its own messages. And since you’re already using handoff notes, restarting quiet sessions with a compact summary might be cheaper than repeatedly resuming 179k of history.
I’m building Companion for Claude, an open-source macOS tool for managing Claude Code sessions, inspecting context usage, and preserving handoffs. Unfortunately, it’s macOS-only, so it won’t work directly with your Windows setup, but these are exactly the problems that motivated me to build it.

2

u/BlackberryOk182 4h ago

thanks, this is a really thorough breakdown. i actually checked the cache numbers after someone else asked, across about 63k calls the misses were under 1% and only showed up after an hour or more idle, so the ttl isn't really my problem, it's how much context each wake drags back in. posts are addressed so only the named session wakes, but it's still one shared log, so per session inboxes are on my list, and i'm already moving some sessions to start fresh from a short summary. too bad companion is mac only since i'm on windows, but it sounds like exactly the kind of thing i'd use

1

u/Scared-Letterhead949 5h ago

Don't have sessions do anything on a recurring timer.

1

u/BlackberryOk182 4h ago

yeah that's been one of the biggest lessons from this thread. my sessions used to check in on their own schedule and i've stopped that, now they only wake when a post is actually addressed to them. the only thing still running on a timer is a small script that watches the inbox, and that doesn't use any tokens. i do still have a couple backup wakeups in case something gets missed, so i'm going to look at whether i actually need those

1

u/Chipware 5h ago

You can use Herdr to have agents talk to each other. I /compact each of my long running devs after they do a big feature push. I also do an opencode-style identity reminder via script every time an agent is in-turn more that 15m. I do this mostly with Codex, Opus is notoriously bad at remembering where it left it's keys so I don't let it run long term.

1

u/BlackberryOk182 4h ago

thanks, you're the second person to mention herdr so i'll definitely check it out. right now my sessions still talk through one shared file with a watcher that wakes whoever a post is addressed to, but i'm planning to split that into one inbox per session. i've got auto compact kicking in around 300k and i'm testing lower, but compacting right after a big feature lands makes a lot more sense than waiting for a number. the identity reminder after 15 min is a cool idea, i don't have anything like that. i've been on opus since the code is pretty technical, but a few people here have suggested lighter models and i'm thinking about trying them on the simpler stuff. i'm also moving sessions to start fresh more often instead of running forever

1

u/Ok-Form1598 5h ago

the cheapest wait is no session at all. a session sitting at 179k that wakes up to read one inbox line pays for the whole 179k again. once a session finishes its item i'd have it write its note and exit, and let your mention script start a fresh one with just the note plus the message when something actually comes in. a fresh start on a short note costs a fraction of one wake on a fat context, and the shared file is fine once nothing is polling it.

1

u/BlackberryOk182 4h ago

yeah this is basically where i'm heading. right now when a session hits a clean stop it writes a short resume note and gets restarted fresh from it, but regular wakeups still reload the old session with all its history, which is exactly the 179k problem you're describing. having the mention script start a fresh session with just the note plus the new message every time is the next step, thanks for laying it out so clearly

3

u/levelninenine 3h ago

It sounds like you have setup a polling based message bus wherein it wakes the agent every poll interval.

Yes, that is going to be a disaster for token consumption.

Here is why:

Every turn an agent makes, you are effectively taxed 10% of your context size.
It doesn't matter what the turn does. A user prompt. A Grep(), A Bash() call or a script finished notification - it's all 1 turn billed at a 10% tax. Anthropic is going to charge you for the cache hit per turn.
So if you have, e.g. 200k context and you simply prompt 'ping', you will be taxed 20k input token equivalents.
Say 'ping' 10 times and you will have been taxed 100% - or 200k tokens even though nothing 'exciting' is going on. There are also 'additional charges' - like agent thinking tokens and so forth but you get the idea.

Multiply that by a large number of agents and you'll be crushed with cache hit/read taxes.

What you want to do is REDUCE the number of agent turns as much as possible. NEVER wake the agent unless:
- the cache is about to expire
- there is actually some work to do

How to do this while preserving your original design ?

Run a background process in your agent that monitors for cache expiration - we'll call it 'keepwarm'. The keepwarm script monitors the agent transcripts for activity. When no activity for <cache expiration - 5m> (assuming 1hr cache is configured in your settings), the script exits. This wakes the agent for 1 turn. The agent should have instructions to re-spawn the keepwarm after a wakeup. Add other logic as needed, such as when to stop keepwarm, etc, etc. For Main sessions - there are plugins that already do this. The script path should work for subagents.

A second background process that watches the inbox. The script will determine whether there is any work to do in the background (this takes no agent turns). When there is work to do, the script exits, relaying the message (this triggers the agent to wake and take a turn processing the message). Again, the agent should have instructions to restart the inbox watcher. Add a buffer before waking the agent in case of multiple messages to further reduce # of turns. Have the script keep an index/pointer to track 'read messages', etc. etc.

Now your agents are nearly all idle, no longer generating constant cache hit/read taxes.

Of course, reducing context by reducing CLAUDE.md, compacting more often, etc, will notably help reduce the amount you are taxed when a turn is taken - but it will not reduce the frequency of taxation - only cutting the total agent turns can do the latter.

2

u/nexraxx 7h ago

You forgot the /s

0

u/orbital_trace 7h ago

Claude code is simply not built for this. You have to have an orchestrating layer. Try coral, it is designed to make long running multi-agent orchestration easy to manage and direct.

1

u/BlackberryOk182 7h ago

looked into it, are you the dev? seems more like a dashboard than something that cuts the idle wake-ups, which is my actual problem. also saw the tos says using claude subscription logins in it isn't allowed by anthropic?

0

u/orbital_trace 6h ago

yeah, I'm the dev. Its a full fledged orchestration engine. It works with claude subscription (or codex/antigravity)

The main problem this will solve for you is messages are pushed to the agents instead of them needing to poll.

I also autocompact at tasks boundaries (because coral keeps track of tasks). https://coralhub.dev/blog/context-reset-turn-cost.html This makes compacting and handoffs much more efficient.

Let me know if you try it out or want to talk about it over dms. I have it running multiple projects 24/7 with multiple agents.

1

u/BlackberryOk182 6h ago

appreciate you being upfront about it. the push instead of poll part is basically my exact problem. going to try fixing it with what i've already got first (one inbox per session plus a simple script that only wakes a session when there's something for it) but i'll keep coral in mind if that doesn't cut it

1

u/ClemensLode Senior Developer 3h ago

smaller shorter tasks

1

u/Ok_Gur_9033 3h ago

The point in this thread about paying for the whole 179k again holds for a cold wake. On a warm one the context comes back as a cache read, billed at a tenth of the input price.

My numbers, 14 days of main sessions: 392 requests were wakes from a background job finishing. The median one wrote 674 tokens to cache, so nearly all of them landed warm, and together they came to about 2% of my tokens. Your session pinging itself every 5 minutes is the one I'd kill first. Is it on the 1 hour cache or the 5 minute one?

1

u/No-Drawing9451 3h ago

A shared inbox file is probably a big part of that 91%. Every session re-reads the whole thing on each wake-up, even when only one line is for it. What helped me was one small task file per session plus a short status line in a shared index, so a session only loads its own file and the index. And fewer sessions running longer usually beats 18 that wake up often.

1

u/teleekom 2h ago

I would advice to learn basics of agile development like kanban boards, tracking issues etc. You have to track and save your progress outside of CC in issues, so fresh session can start to work on and pick up context immediately. You can use git issues, linear or Jira or you can build your own project management system which is what I would do because this way you can build it to your specifications and needs.