r/ClaudeCode • u/reluctantLlama • 8h ago
Bug / Issue Nested Sessions in Claude Code
Well, just a warning to others out there to new behaviour I noticed today in the way Claude was spawning sub-sessions. It is nesting them - which didn't seem like a big deal - it actually helped me keep track of which sessions were working on related features or projects. EXCEPT what I discovered is the nested sessions were waking up their "parents" in the hierarchy each time they completed work. For example: Session 1 spawns -> Session 2. Session 2 is working for a few hours, back and forth with me; I go look at Session 1... it is being woke every time Session 2 completes work (to say its done). The Session 2 spawned a Session 3... again... notifications back up the stack. Re-awakening the old sessions up the chain, regardless of their length, reloading their cache and all the token usage that goes with it. So beware if you haven't noticed this before. I was very confused how my usage was spiking so quickly, thinking I was working in a small session. They were all chained.
•
u/AutoModerator 8h 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.
2
u/Starks1293 7h ago
the reason it spikes that hard is the prompt cache i think. a parent that sat idle longer than the cache lasts gets its whole context read in again at full price every time a child pings it, so a long parent costs u close to a full turn per ping even if all it says back is ok
one way around it is not letting the children report back at all. tell the child to write what it did into a file in the repo (notes/<task>.md or whatever) and stop there, then u read that and give the parent one line when u actually want it to carry on. and keep the parent short, a parent sitting on 150k of context is the expensive one to wake
1
u/zionek 8h ago
yes its been like that for a while. What I do is to ask to detach it or detach it manually. Its so stupid that it keeps messaging the parent app of every step that the child does.
1
u/called9527 6h ago
is this in the desktop app or the cli? for child work i'd try subagents instead of full sessions, they just hand a summary back to the parent so it isn't getting poked at every step
1
u/Long-Barracuda-7521 5h ago
What you are describing sounds like the completion message being delivered to the parent as a new turn: every child finish re-opens the parent's turn, and that cascades up the chain. The deeper the nest, the more wake-ups per hour.
Two things that usually cut it:
claudeprocess, use the Agent/Task tool instead. A subagent's result arrives as a single tool result in the parent — no turn is started, no cascade, and the parent stays idle until you talk to it.~/.claudesession files, or a hook that resumes a parent when a child finishes, is exactly the wire that carries the wake-up. If you need cross-session coordination, pass a note through a file and let the human (or the next prompt) pick it up.I would also check whether the re-awakening is a real turn or just a notification: if the parent's token counter moves every time a child reports, it is a turn, and it is burning the parent's context for nothing.
1
u/controlfree 5h ago
I hit the same cost spike when a child session kept waking the parent. What worked for me is to treat nested sessions as a bug, not a feature: I stop the child, and I start each piece of work in its own Terminal tab with its own git worktree. I also tell Claude in the prompt not to spawn a sub-session if a new task comes up, and to print the task so I can open a new tab myself. After that the cache behaviour became predictable again.