[BUG] Sub-agent messages render in wrong vertical order — insertion position resets on main↔sub-agent context switch
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
When a sub-agent makes multiple sequential tool calls (each in a separate assistant message), the messages render in the wrong vertical order in the inline sub-agent expansion. Some messages appear above the initial prompt, while others appear below it.
It appears that whenever the TUI switches context between the main conversation and the sub-agent panel, the output insertion position resets to the top of the sub-agent's output region, causing new content to be prepended rather than appended chronologically.
The bug reproduces in both fullscreen (/tui fullscreen, using mouse click to switch) and classic/default TUI modes (using keyboard navigation to switch).
What Should Happen?
Sub-agent messages should render in chronological order, top-to-bottom:
- Initial prompt (❯)
- First tool call + result
- First summary
- Second tool call + result
- Second summary
- ...
Steps to Reproduce
- Launch Claude Code (either fullscreen or classic TUI mode)
- Ask Claude to spawn a sub-agent that makes multiple sequential tool calls (not batched). For example: "spawn a sub-agent and have it read 5 files one at a time, summarizing each before reading the next"
- While the sub-agent is running, switch focus between the main conversation and the sub-agent panel (mouse click in fullscreen mode, keyboard navigation in classic mode)
- Observe the sub-agent's expanded output panel
Actual rendering in fullscreen mode (top to bottom):
⏺ File 2 summary: ...
Read 1 file
⏺ File 3 summary: ...
Read 1 file
⏺ File 1 summary: ...
Read 1 file
❯ Read the following 5 files one at a time... <-- initial prompt appears in the MIDDLE
⏺ Thinking for 2s, reading 1 file… <-- first action appears at the bottom
⎿ go.mod
Actual rendering in classic/default mode (top to bottom):
Read 1 file (ctrl+o to expand)
⏺ CLAUDE.md summary...
Read 1 file (ctrl+o to expand)
❯ Read the following 5 files one at a time... <-- initial prompt in the MIDDLE
Thought for 3s, read 1 file (ctrl+o to expand)
⏺ go.mod summary... <-- first result at the bottom
In both cases, the initial prompt should be at the top with all subsequent messages below in chronological order.
Error Messages/Logs
No error messages — purely a rendering/layout issue.
Claude Model
Opus
Is this a regression?
I don't know
Claude Code Version
2.1.159 (Claude Code)
Platform
Other
Operating System
macOS
Terminal/Shell
iTerm2
Additional Information
- macOS 26.5 (Darwin 25.5.0)
- Reproduces in both fullscreen and classic TUI renderers
- In fullscreen mode: switching via mouse click; in classic mode: switching via keyboard navigation
- The bug is about the inline sub-agent expansion in the main CLI conversation, not the separate
claude agentsdashboard view - Possibly related to #59750 (Windows agent TUI elements rendering in wrong vertical positions), though that issue is about the
claude agentsview specifically
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗