Team agent CLI flags (--team-name, --agent-id) not exposed as environment variables
Bug Description
When Claude Code spawns tmux team agents, it passes --team-name and --agent-id as CLI flags but does not expose them as environment variables (CLAUDE_TEAM_NAME, CLAUDE_AGENT_ID). This makes it impossible for hooks and user scripts to detect team context without parsing the process tree.
Steps to Reproduce
- Configure
teammateMode: "tmux"in~/.claude/settings.json - Create a team with
TeamCreateand spawn a teammate - In the teammate's session, run:
````
echo "CLAUDE_AGENT_ID=$CLAUDE_AGENT_ID CLAUDE_TEAM_NAME=$CLAUDE_TEAM_NAME"
- Both variables are empty
Observed tmux launch command
cd /Users/user/project && env CLAUDECODE=1 CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1 \
/path/to/claude --agent-id tester@hook-test --agent-name tester \
--team-name hook-test --agent-color blue --parent-session-id <uuid> --model claude-opus-4-6
Note: only CLAUDECODE and CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS are set via env. The --team-name and --agent-id flags are CLI args only — not propagated to the shell environment.
Expected Behavior
The following environment variables should be set for team agent processes:
| Variable | Value | Source |
|----------|-------|--------|
| CLAUDE_TEAM_NAME | hook-test | --team-name flag |
| CLAUDE_AGENT_ID | tester@hook-test | --agent-id flag |
| CLAUDE_AGENT_NAME | tester | --agent-name flag |
These should be available to:
- Hook scripts (PermissionRequest, PreToolUse, etc.)
- Bash tool commands
- Any child process spawned by the agent
Workaround
Parse the parent process command line to extract team flags:
PARENT_ARGS=$(ps -ww -p "$PPID" -o args= 2>/dev/null || true)
if [[ "$PARENT_ARGS" == *"--team-name"* ]]; then
IS_TEAM=true
fi
This is fragile and platform-dependent (macOS ps requires -ww for full args). Environment variables would be the standard, reliable mechanism.
Related
- #23983 — PermissionRequest hooks not triggered for subagent permission requests (compound issue: even if hooks fired, team detection via env vars wouldn't work)
Environment
- Claude Code v2.1.77
- macOS (Darwin 25.2.0)
teammateMode: "tmux"
🤖 Generated with Claude Code
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗