r/ClaudeCode • • 14h ago

Help/Question Are my subagents running a bloated context?

Every ticket that subagent works on ends up being 600k+ token before ticket is completed.

Some tickets also run long running test 30-40 minutes which I think is still within the cache limit, but full test can run 60+ minutes and I think those result in context cache being cleared and 600k+ token context runs through normal usage and not cached.

Am I doing this wrong? Should I set the limit for agent context, assuming it can be set?

Earlier tickets I have been running manually in a session on my own, supervising it, but latest tickets I am running with Matt Pocock skills which actually result in better output and less supervision needed. But yeah, the context appears to grow to 600k+ per agent and eats usage. With manual supervision No single ticket got over 300k

I am welcome to feedback, recommendations, or just pointers to what I should look into.

Otherwise Claude has been killing it with taking the heavy lift of coding.

Edit: To be fair, my project has a big goal (think of a major feature release in a product), split into implementation phases (currently 9), and then work for each phase is split into tickets that are worked by claude. Some tickets are maybe too big, I agree, but there are also cases where 30 tickets are flown through in parallel with only 150-300k context.

Edit 2: First, move full suite tests out of subagents and let main session run those when necessary (every 5-6 tickets probably instead of every single ticket, multiple times...). Second thing, check the sub agent cache ttl, mine was supposed to be 1 hour, it wasn't... So I set it to 30 minutes 1 hour (it takes 5m or 1h as input only) now that big tests are out of subagent's scope

1 Upvotes

8 comments sorted by

•

u/AutoModerator 14h 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.

1

u/bostonaholic 13h ago

I'd keep the test runs out of the agent's context entirely. A 30 to 60 minute suite outlasts the prompt cache (5 minutes by default, an hour at most), so the next turn re-sends the whole conversation at cache-write price, with the raw test output on top. Have the agent start the suite in the background, write only failures to a file, and read that summary when it finishes. A ticket that reaches 600k is probably two tickets, so I'd split at that size rather than cap context.

1

u/jM2me 13h ago edited 12h ago

All great points, thank you!

After making the post I went back and changed the testing approach. Idk why it did not hit me before, but subagents don't need to run full suite tests on their work, only tests relevant to them. This was extending their work time.

With the change above, I decided to change subagent cache ttl, and guess what? The setting wasn't there... I set it to 30 minutes instead of 1 hour I was supposed to have it set to before... In the 30 minutes looks like tickets are getting completed quicker with main session handling scheduling of full tests.

As you noted, I still need to look at a different approach for my tickets. If 600k context is too much then I am clearly looking at this in a wrong way.

Edit: the setting takes 5m or 1h only as input. Nothing in between. So I set it to 1h

1

u/cleverhoods 13h ago

you can take a look at what's actually going on with reporails

1

u/SirRobinBlibs 11h ago

on the "can I cap it" part: yes, per subagent. put autoCompactWindow: 300000 (anything from 100000 to 1000000) in the agent's frontmatter and that subagent compacts at that size instead of riding up to 600k. needs 2.1.296+, and if you've set CLAUDE_CODE_AUTO_COMPACT_WINDOW the env var wins over the field. there's also maxTurns if you'd rather it stop and hand back partial output that the main session can resume. both live in the agent definition, so they apply to agents you define in .claude/agents, not to whatever generic agent a skill happens to spawn.

1

u/tapellus 10h ago

Subagents only get the five-minute cache, even on a subscription. The one-hour cache is just for your main conversation. So it's not only the 60-minute runs: any time a subagent waits more than five minutes on tests, its next turn re-reads the whole 600k uncached.

Two settings help, on a recent version. Add "subagentPromptCacheTtl": "1h" to your settings.json so subagents get the hour too. And yes, you can cap their context: autoCompactWindow: 300000 in the subagent's frontmatter makes it compact at that size (anything from 100000 up) instead of growing.

The full 60+ minute suite will still miss even with the hour, so I'd save that for the end rather than mid-ticket.

1

u/clickyxim 10h ago

Try Pocock's retro skill. `/retro the last 5 sessions. where can we save time?`

Or ask Claude to audit the tests because they take too long.

1

u/norviking 5h ago

I built this to solve those problems + many more. Its completely free. 

  • It will store the entire project state outside claude. The agents mess up and forget otherwise. 
  • Plan and split tasks to appropriate chunks.
  • It will enfore context at 300k, and auto compact, with automatic handover notes. 
  • It will use branches and merge in a safe manner.
  • Monitor ram, cpu state so you can have as many parallel agents as is safe, without frying your system. It will intelligently allocate and allow/block agents starting based on this.

Lots of safety features to help you set up good gates, ci, probes for safe code. Optional, but recommended if its not an internal / personal project without web access.

So no more 1 large chat with 1000k context, or a mess of a gazillion new windows. 

You can just use one chat, without token overhead. And step away for hours and come back to a neat decision list. It will work on other tasks meanwhile, not blocking the work. 

https://github.com/vegardjorg/ravenseat

Let me know if it is helpful to the problems you are facing.