You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Session token expires within minutes when multiple subagents are spawned concurrently #37324
When spawning multiple subagents concurrently using the Agent tool with isolation: \"worktree\", some agents fail immediately with "Not logged in · Please run /login" even though the parent session was authenticated moments earlier.
Steps to Reproduce
Start a Claude Code session (authenticated)
Use the Agent tool to spawn 4+ subagents simultaneously with isolation: \"worktree\" and run_in_background: true
Some agents (typically ~50% when spawning 4 at once) fail within seconds with "Not logged in"
Expected Behavior
All subagents should inherit/read the valid session credentials from ~/.claude/ without requiring re-authentication.
Actual Behavior
Some agents fail with "Not logged in · Please run /login" within seconds of being spawned. Running /login in the parent session fixes it temporarily, but the issue recurs on the next batch of concurrent spawns — sometimes within 5 minutes of the previous login.
Environment
Platform: macOS (darwin 25.2.0)
Shell: zsh
Concurrent agents spawned: 4 at a time
Parent session: also running inside a worktree
Hypothesis
Likely a race condition where concurrent subagent processes simultaneously read/write the ~/.claude/ credentials file, causing some to see an invalid/partial auth state.
Impact
Requires frequent manual /login interruptions during parallel agent workflows, which significantly disrupts autonomous multi-agent development pipelines.
Reacted by LARIK, Konstantsin Petrovskiy and Daniel Guzmán Burgos
This is likely a race condition in the auth token refresh mechanism. When multiple subagents read the credential file simultaneously, one reads while another is mid-write during token refresh, getting stale/empty credentials.
Workaround: stagger the agent spawns with a small delay between each.
In your CLAUDE.md:
When spawning multiple agents in parallel, add a 2-second delay between each spawn.
Do not spawn more than 3 agents simultaneously.
Or enforce it with a PreToolUse hook that rate-limits Agent spawns:
We built and open-sourced cozempic — it continuously checkpoints agent team state so even if a session dies mid-flight, subagent results and task status are recoverable. The guard daemon also prunes bloat to keep sessions healthy under multi-agent load. Would love feedback.
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.
Activity
github-actions commentedon Mar 22, 2026
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
yurukusa commentedon Mar 22, 2026
This is likely a race condition in the auth token refresh mechanism. When multiple subagents read the credential file simultaneously, one reads while another is mid-write during token refresh, getting stale/empty credentials.
Workaround: stagger the agent spawns with a small delay between each.
In your CLAUDE.md:
Or enforce it with a PreToolUse hook that rate-limits Agent spawns:
This adds a minimum 3-second gap between agent spawns, reducing the chance of concurrent credential reads.
nethalo commentedon Mar 22, 2026
As a workaround, you can also just run /exit and then "claude --resume " and avoid the /login flow
junaidtitan commentedon Mar 22, 2026
We built and open-sourced cozempic — it continuously checkpoints agent team state so even if a session dies mid-flight, subagent results and task status are recoverable. The guard daemon also prunes bloat to keep sessions healthy under multi-agent load. Would love feedback.
LARIkoz commentedon Mar 23, 2026
Community workaround available: claude-batch — tmux-isolated parallel
claude -pthat prevents auth kickout. Drop-in replacement. See also RFC: #37678feat(plugins): add parallel-batch-safe plugin for auth-safe batch jobs
github-actions commentedon Apr 21, 2026
Closing for now — inactive for too long. Please open a new issue if this is still relevant.
github-actions commentedon May 2, 2026
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.