Team agents fail to start: tmux send-keys race condition with shell initialization

Status Closed — not planned
Reported on v2.1.32
Maintainer reply None cached
Activity 13 comments · opened Feb 5, 2026 · closed Mar 25, 2026

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

  1. Start Claude Code
  2. Use the Teammate tool to spawn a team (spawnTeam)
  3. Use the Task tool with team_name to spawn teammates
  4. 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:

  1. tmux split-window creates a new pane
  2. tmux send-keys immediately 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) between split-window and send-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

View original on GitHub ↗

13 Comments

github-actions[bot] · 6 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/23465
  2. https://github.com/anthropics/claude-code/issues/23456
  3. https://github.com/anthropics/claude-code/issues/23415

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

dtabuenc · 6 months ago

This is exactly the issue I have, I don't understand why it uses send-keys instead of just a command

oathead · 6 months ago

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.

sandroden · 6 months ago

I experiment the same issue with bash. Maybe a big .bashrc (that's the explanation of Claude Code itself)

dcsan · 6 months ago

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?

therolle · 6 months ago

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.

dcsan · 6 months ago

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-process

and added this to both local and ~/.claude/settings.json

{
  "teammateMode": "in-process"
}

any other workarounds to force parallel but background?

https://code.claude.com/docs/en/agent-teams.md

sstklen · 6 months ago

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:

  1. Option 1: Add a configurable delay (1-3 seconds) between tmux split-window and send-keys
  2. Option 2: Replace send-keys approach with tmux split-window -c 'command' to execute directly
  3. Option 3: Send a shell readiness probe before the actual command
  4. Option 4: Use tmux new-session or new-window with command parameter instead of send-keys
  5. Add environment variable TMUX_DELAY_MS for users with slow shell initialization
// Replace this pattern:
// tmux split-window
// tmux send-keys 'command' Enter

// With this:
const delay = process.env.TMUX_DELAY_MS || 2000;
await new Promise(resolve => setTimeout(resolve, delay));
// OR better:
tmux split-window 'command'
// OR:
tmux split-window -c 'bash -c "command"'

Hope this helps! Let me know if it doesn't match your case — happy to dig deeper. 🦞

_Disclosure: This analysis is from Confucius Debug, an AI-powered community KB for agent bugs. Please verify before applying._

---
<sub>🦞 Confucius Debug — community knowledge base for AI agent bugs. Free to search via MCP.</sub>

dcsan · 6 months ago

@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?

sstklen · 6 months ago

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.
  • Trim shell init — if you do want tmux mode, stripping heavy plugins (oh-my-zsh, starship, etc.) from your .zshrc can help the shell initialize before send-keys fires.
  • Lightweight .zshrc guard — add [[ -n "$TMUX" ]] && return early in .zshrc to 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.

dcsan · 6 months ago

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-option -g default-shell /bin/zsh
  # But for new panes, use a fast shell:
  set-option -g default-command "bash --norc --noprofile"

set other shell

i found this got processes killed

  # Before running claude, override the default shell tmux uses
  export SHELL=/bin/bash
  claude

zsh quick exit

add this to the top of your .zshrc
but actually cc runs with a different env vars and ... had issues

# Skip heavy init for tmux-spawned Claude agent panes
if [[ -n "$CLAUDE_AGENT" || -n "$CLAUDE_CODE_AGENT" ]]; then
  # minimal PATH setup only
  # echo "claude startup"
  return
fi

Option 3: tmux hook to add a delay

(This is heavy-handed and may affect other tmux usage.)

Add to ~/.tmux.conf:

  # Add slight delay after pane creation before accepting input
  set-hook -g after-split-window "run-shell 'sleep 0.3'"

This forces a 300ms pause after every split-window, giving the shell time to init before send-keys arrives.

Wait for the official fix

github-actions[bot] · 5 months ago

Closing for now — inactive for too long. Please open a new issue if this is still relevant.

github-actions[bot] · 5 months ago

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.