claude-code - 💡(How to fix) Fix setup-token: parallel `claude -p` spawns sharing CLAUDE_CODE_OAUTH_TOKEN see ~5-10s server-side serialization tax (different tokens unaffected) [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#54999Fetched 2026-05-01 05:48:53
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Author
Participants
Timeline (top)
labeled ×4

When two or more claude -p ... spawns run in parallel and share a single CLAUDE_CODE_OAUTH_TOKEN (issued by claude setup-token), one runs at normal latency (~6s) and the other(s) experience a consistent ~10-16s tax. With distinct tokens (different setup-token-issued tokens for different accounts), parallel runs are clean (~8s each).

The serialization is server-side, keyed on Bearer-token identity. Local syscalls are identical between the fast and slow paths; both processes connect to api.anthropic.com simultaneously; the server delays response on one of them. Likely the same family as #54443 / #27933 / #25609 but with setup-token the failure mode is slow rather than failed (no refresh dance to race).

Root Cause

When two or more claude -p ... spawns run in parallel and share a single CLAUDE_CODE_OAUTH_TOKEN (issued by claude setup-token), one runs at normal latency (~6s) and the other(s) experience a consistent ~10-16s tax. With distinct tokens (different setup-token-issued tokens for different accounts), parallel runs are clean (~8s each).

The serialization is server-side, keyed on Bearer-token identity. Local syscalls are identical between the fast and slow paths; both processes connect to api.anthropic.com simultaneously; the server delays response on one of them. Likely the same family as #54443 / #27933 / #25609 but with setup-token the failure mode is slow rather than failed (no refresh dance to race).

Fix Action

Fix / Workaround

Workaround for users with multiple subscription accounts: round-robin across distinct tokens (1 token per account). Workaround for single-account users: serialize spawns at the dispatch layer.

Code Example

# Mint two distinct setup-tokens (or use the same one twice).
# Stash as TOKEN_A and TOKEN_B.

# Same-token parallel:
mkdir /tmp/repro && cd /tmp/repro
for i in $(seq 1 10); do
  (time env CLAUDE_CODE_OAUTH_TOKEN="$TOKEN_A" claude -p "Reply: A" </dev/null > a$i.out 2>&1) 2>&1 | grep real &
  (time env CLAUDE_CODE_OAUTH_TOKEN="$TOKEN_A" claude -p "Reply: B" </dev/null > b$i.out 2>&1) 2>&1 | grep real &
  wait
  echo "trial $i done"
done

# Result: 9/10 trials, A=5.8-8.2s and B=9.1-15.6s (mean B-A delta ≈ 4s)

# Different-token parallel control:
for i in $(seq 1 10); do
  (time env CLAUDE_CODE_OAUTH_TOKEN="$TOKEN_A" claude -p "Reply: A" </dev/null >/dev/null 2>&1) 2>&1 | grep real &
  (time env CLAUDE_CODE_OAUTH_TOKEN="$TOKEN_B" claude -p "Reply: B" </dev/null >/dev/null 2>&1) 2>&1 | grep real &
  wait
done

# Result: clean ~8s each.
RAW_BUFFERClick to expand / collapse

Summary

When two or more claude -p ... spawns run in parallel and share a single CLAUDE_CODE_OAUTH_TOKEN (issued by claude setup-token), one runs at normal latency (~6s) and the other(s) experience a consistent ~10-16s tax. With distinct tokens (different setup-token-issued tokens for different accounts), parallel runs are clean (~8s each).

The serialization is server-side, keyed on Bearer-token identity. Local syscalls are identical between the fast and slow paths; both processes connect to api.anthropic.com simultaneously; the server delays response on one of them. Likely the same family as #54443 / #27933 / #25609 but with setup-token the failure mode is slow rather than failed (no refresh dance to race).

Reproduction (10/10 trials show the pattern)

CLI v2.1.123 on Linux x86_64.

# Mint two distinct setup-tokens (or use the same one twice).
# Stash as TOKEN_A and TOKEN_B.

# Same-token parallel:
mkdir /tmp/repro && cd /tmp/repro
for i in $(seq 1 10); do
  (time env CLAUDE_CODE_OAUTH_TOKEN="$TOKEN_A" claude -p "Reply: A" </dev/null > a$i.out 2>&1) 2>&1 | grep real &
  (time env CLAUDE_CODE_OAUTH_TOKEN="$TOKEN_A" claude -p "Reply: B" </dev/null > b$i.out 2>&1) 2>&1 | grep real &
  wait
  echo "trial $i done"
done

# Result: 9/10 trials, A=5.8-8.2s and B=9.1-15.6s (mean B-A delta ≈ 4s)

# Different-token parallel control:
for i in $(seq 1 10); do
  (time env CLAUDE_CODE_OAUTH_TOKEN="$TOKEN_A" claude -p "Reply: A" </dev/null >/dev/null 2>&1) 2>&1 | grep real &
  (time env CLAUDE_CODE_OAUTH_TOKEN="$TOKEN_B" claude -p "Reply: B" </dev/null >/dev/null 2>&1) 2>&1 | grep real &
  wait
done

# Result: clean ~8s each.

What the local side does

strace -f -e trace=openat,connect,flock,fcntl shows the env-var spawn and the ~/.claude/.credentials.json spawn make nearly identical syscalls. No local lock contention. No extra file IO on the env-var path. Both spawns connect to api.anthropic.com within milliseconds of each other. The variance is on the server side.

Operational impact

For headless / cron / CI use cases (the documented target of setup-token), parallel-spawn workloads sharing a single token take a measurable latency hit. Not a hang in v2.1.123 — just consistent slowness on N-1 of N parallel spawns.

Workaround for users with multiple subscription accounts: round-robin across distinct tokens (1 token per account). Workaround for single-account users: serialize spawns at the dispatch layer.

Environment

  • CLI: 2.1.123
  • OS: Linux x86_64
  • ~/.claude/.credentials.json: present, fresh (CLI silently refreshes hourly)
  • Token format: sk-ant-oat01- + 95-char tail per documented setup-token output
  • No apiKeyHelper configured. No ANTHROPIC_API_KEY. No ANTHROPIC_AUTH_TOKEN.

Related

  • #54443 (concurrent OAuth, 2026-04-28) — closest existing report
  • #27933, #25609 (OAuth refresh races, closed) — same family, refresh-token variant
  • #11639 (apiKeyHelper TTL cache) — adjacent

extent analysis

TL;DR

Using distinct tokens for parallel claude spawns can mitigate the server-side serialization issue causing a latency hit.

Guidance

  • When running multiple claude spawns in parallel, use a separate CLAUDE_CODE_OAUTH_TOKEN for each spawn to avoid server-side serialization.
  • For users with multiple subscription accounts, round-robin across distinct tokens (1 token per account) to minimize latency.
  • For single-account users, consider serializing spawns at the dispatch layer as a workaround.
  • Verify the fix by running the reproduction script with distinct tokens and checking for consistent latency across all spawns.

Example

No code snippet is provided as the issue is related to token management and server-side behavior.

Notes

The provided workaround may not be suitable for all use cases, and the root cause of the server-side serialization issue is not explicitly stated. Further investigation may be necessary to determine the underlying cause.

Recommendation

Apply the workaround of using distinct tokens for parallel claude spawns, as it has been shown to mitigate the latency issue in the provided reproduction script.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix setup-token: parallel `claude -p` spawns sharing CLAUDE_CODE_OAUTH_TOKEN see ~5-10s server-side serialization tax (different tokens unaffected) [1 participants]