Team agents fail to start: tmux send-keys race condition with shell initialization
Summary
When spawning team agents via Teammate tool, the agent processes fail to start because tmux send-keys sends the command before the shell (zsh) in the newly created tmux pane has finished initializing.
Steps to Reproduce
- Start Claude Code
- Use the
Teammatetool to spawn a team (spawnTeam) - Use the
Tasktool withteam_nameto spawn teammates - Observe the tmux panes created for each teammate
Expected Behavior
Each tmux pane should execute the agent command and start the Claude Code agent process.
Actual Behavior
The tmux panes are created and the command text appears in each pane, but the command is never actually executed. The shell prompt (~ >) appears immediately, indicating the shell became interactive but the command was not processed. The agent processes never start.
Screenshot showing the issue (3 agent panes all showing the command text but dropped to shell prompt):
── zsh ──
n-research --agent-name geography-researcher --team-name japan-research --agent-color blue --parent-session-id cc486c6d-c672-4b07-835e-fc03eb419c4b --agent-type general-purpose --model haiku
~ > 08:35:40
All 3 panes show the same pattern: command text displayed but not executed.
Root Cause Analysis
Looking at the binary source, the flow is:
tmux split-windowcreates a new panetmux send-keysimmediately sends the agent command + Enter
There appears to be no delay or readiness check between creating the pane and sending keys. When using zsh (which loads .zshrc, plugins, etc.), the shell initialization takes time. The send-keys arrives before zsh is ready to accept input, so the keystrokes are either lost or displayed without execution.
Suggested Fix
Options:
- Add a small delay (e.g.,
sleep 0.5) betweensplit-windowandsend-keys - Use
tmux split-window "command"to pass the command directly as part of pane creation (this runs the command as the pane's initial process) - Poll for shell readiness before sending keys (e.g., check if the pane has a prompt)
Environment
- Claude Code version: 2.1.32
- OS: macOS (Darwin 25.2.0)
- Shell: zsh
- tmux: installed via Homebrew
13 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
This is exactly the issue I have, I don't understand why it uses send-keys instead of just a command
I also see this issue, I suspect that zsh users with oh-my-zsh or other plugins that take half a second or a second to initialize are receiving the command before the shell has initialized.
I experiment the same issue with bash. Maybe a big .bashrc (that's the explanation of Claude Code itself)
great diagnosis!
i have the same condition, i had to switch to just using agents without the tmux panes.
I tried trimming back on zsh stuff but still doesn't start.
there's no way to 'up-arrow' and run the command either.
guess there's no easy way to modify those commands to run in a vanilla shell?
Same condition, using zsh. Apparently using starship makes the shell initialization slow enough (like maybe 1s latency in init) that this issue manifests. When telling about this issue to the main context, it applies wait times and then it works properly with invoking the agent teams in tmux panels. This clearly seems to be a timing issue.
to add insult to injury... claude will keep asking me to install tmux or the iterm extensions
sometimes they will run as background tasks but often it will keep prompting.
I'm using
claude --teammate-mode in-processand added this to both local and
~/.claude/settings.jsonany other workarounds to force parallel but background?
https://code.claude.com/docs/en/agent-teams.md
Hey! I ran into a similar pattern in our bug knowledge base and thought this might help.
What's happening: Race condition between tmux send-keys and shell initialization - the command is sent before zsh/bash has finished loading .zshrc/.bashrc and plugins, causing the command to be lost
What worked for us:
Add a delay or shell readiness check before sending keys, or use tmux's command execution parameter instead of send-keys
Steps:
Hope this helps! Let me know if it doesn't match your case — happy to dig deeper. 🦞
---
<sub>🦞 Confucius Debug — community knowledge base for AI agent bugs. Free to search via MCP.</sub>
@sstklen where would those changes be added?
it looks like typescript, not any env settings. are you suggesting modifying the claude code .. code?
or is this an additional post-hook we can run after a pane is triggered to open?
or is this a bot generated comment?
Fair question, @dcsan — I should have been clearer. Those TypeScript snippets describe what the fix would look like inside Claude Code's source. They're not something you can patch yourself since the tmux spawning logic is in the compiled binary.
For practical workarounds right now:
--teammate-mode in-process— you mentioned you're already using this, which bypasses tmux entirely. This is the most reliable option..zshrccan help the shell initialize before send-keys fires..zshrcguard — add[[ -n "$TMUX" ]] && returnearly in.zshrcto skip heavy init when spawned inside tmux panes.The real fix needs to come from Anthropic's side (using
tmux split-window 'command'instead of send-keys). Apologies for the confusion in my earlier comment.yes i did some claudigging today
Use a faster shell for tmux panes
this was the fix that finally worked for me:
in ~/.tmux.conf:
set other shell
i found this got processes killed
zsh quick exit
add this to the top of your
.zshrcbut actually cc runs with a different env vars and ... had issues
Option 3: tmux hook to add a delay
(This is heavy-handed and may affect other tmux usage.)
Add to ~/.tmux.conf:
This forces a 300ms pause after every split-window, giving the shell time to init before send-keys arrives.
Wait for the official fix
Closing for now — inactive for too long. Please open a new issue if this is still relevant.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.