Claude turns fail in new worktrees: 90s `setMcpServers` limit is shorter than SessionStart hooks #23151
What happened#
Every new Claude thread that T3 Code starts in a fresh worktree of one of my repos fails with:
The provider could not start this turn. Retry the turn; if it keeps failing, check the provider setup and server logs.
The server trace has the real cause:
ProviderAdapterTurnStartError: Failed to start run run:thread:<id>:ordinal:1 on claudeAgent provider thread ...
[cause]: ClaudeAgentSdkQueryRunnerError: Claude Agent SDK query failed.
[cause]: Error: Claude Code did not answer the MCP server registration. (method: setMcpServers)
It started mid-day today and now happens on every new worktree thread. Follow-up turns in existing threads, and threads in the main checkout, still work. I switched from nightly to the stable channel and it still happens. I had to move to the Claude Code CLI to keep working.
Root cause (reproduced)#
The repo's .claude/settings.json has a SessionStart hook, matcher startup and "timeout": 600. In a linked worktree, the hook runs the repo's worktree setup script, which installs dependencies, builds types and so on. In the main checkout it exits immediately.
Claude Code doesn't answer the SDK's setMcpServers control request until startup, including SessionStart hooks, has finished. T3 waits for that with a hard-coded limit:
const CLAUDE_MCP_REGISTRATION_TIMEOUT = "90 seconds";
...
queryRuntime.setMcpServers(mcpServers) ... timeoutOrElse({
duration: CLAUDE_MCP_REGISTRATION_TIMEOUT,
orElse: () => fail(queryRunnerError("Claude Code did not answer the MCP server registration.", "setMcpServers"))
})
So whenever a legitimate SessionStart hook takes more than 90 seconds, the turn fails. The user also has no way to tell the cause is a hook.
Reproduction without T3, in a fresh git worktree add --detach of the same repo:
claude -p "reply ok" wall time | |
|---|---|
| main checkout (hook exits immediately) | 9s |
| fresh worktree, first start (hook runs setup) | 91s |
| same worktree, second start (setup cached) | 10s |
Startup times of ClaudeAgentSdkQueryRunner.open from server.trace.ndjson today:
14:14 Success 64968ms <- already near the limit
14:54 Success 59128ms
15:42 Failure 90002ms
15:44 Failure 90003ms
15:50 Failure 90003ms
15:59 Failure 90003ms
16:02 Success 3054ms (non-worktree thread)
16:08 Failure 90002ms
My guess about why it started today: dependency manifest changes pulled mid-day invalidated the setup script's cached install, so first-start setup went from about 60s to more than 90s. The 90s limit was already marginal for this repo.
T3 shows no "Setting up worktree" hook status, so all the user sees is a long spinner and then a generic provider error.
Expected#
One or more of:
- Don't apply a 90s limit to
setMcpServerswhile Claude Code is still running SessionStart hooks. Respect the hook's configuredtimeout, or make the limit configurable. - Show hook progress or
statusMessagewhile the provider starts, so it doesn't look like a hang. - When it does time out, say that Claude Code was still starting up (for example, running SessionStart hooks) instead of showing the generic "provider could not start this turn".
Related#
- #22198: same
CLAUDE_MCP_REGISTRATION_TIMEOUTfailure with a different trigger (hung OpenCode subagent), plus the stuck-thread recovery problem it can cause. - #20828 / #21608: the generic error hides the underlying cause.
- #14244: no "starting agent" state while the provider starts.
Workarounds#
- Start the thread in the main checkout or in an already-set-up worktree.
- Run the repo's setup as a T3 project setup script so the hook finds a warm cache. (Not verified.)
Environment#
- T3 Code (Beta) desktop 0.1.1, stable channel (also seen on nightly earlier today)
- macOS 27.0.1, Apple Silicon
- Claude Code CLI 2.1.306 → 2.1.307 (failed on both)
- Provider: claudeAgent, claude-opus-5-5
Stopgap that works today (verified), for anyone blocked on this until #23202 ships
Configure a blocking project setup script in T3 Code that runs the same setup your SessionStart hook runs. T3 waits for a
runOnWorktreeCreatescript withasync: falsewithout any timeout before it starts the agent, so by the time Claude's hook runs, the install is cached and the hook finishes in a few seconds — well under the 90ssetMcpServersdeadline.In my case (repo hook =
.agents/scripts/setup-worktree.sh, cold worktree ≈ 60sbun install+ type generation):Before With blocking setup script T3 setup stage — ~105s, awaited, no limit SessionStart hook 65–90s (full install) 5.0s (install skipped, cached) ClaudeAdapterV2.startTurn66s, or 90s timeout 5.9s How to set it:
- UI: project sidebar → "Add project script" → command = your setup script, enable Run on worktree create, and make it blocking (
async: false; the default is async, which does not help because the agent starts while the script is still running). - Or settings file:
~/.t3/userdata/settings.json(the server fs-watches it, no restart needed):
"projectSettingsOverrides": { "<projectId>": { "defaultProjectScripts": [{ "id": "worktree-setup", "name": "Worktree setup (blocking)", "command": "./.agents/scripts/setup-worktree.sh", "icon": "configure", "runOnWorktreeCreate": true, "async": false }] } }One gotcha that cost me a round-trip: with
projectSettingsFolded: true(the current default),resolveProjectScriptsonly readsprojectSettingsOverrides[projectId].defaultProjectScripts(or the environment default) and ignores the project's legacyscriptsfield — so setting scripts viat3_project_updatefrom an agent has no effect. Use the UI or the override above.Side benefits: setup progress shows as a stage in the thread, and a failing setup produces "Setup script exited with N" instead of the generic provider error. I'll keep it even after the timeout fix lands.
- UI: project sidebar → "Add project script" → command = your setup script, enable Run on worktree create, and make it blocking (
Another trigger for the same 90 s
setMcpServerslimit: no repo hook, but a large global Claude Code config on a loaded machine.- T3 Code Nightly
0.1.3-nightly.20261023.3566, macOS arm64, Claude Code with Opus 5.5. - Scheduled tasks (2 min interval), each run in a fresh worktree. The repo has no
.claude/hooks.
ClaudeAgentSdkQueryRunner.openfromserver.trace.ndjson, 15:41 to 17:02 local time:Result Count Duration Success 5 33 s to 77 s Failure 12 90.0 s each, Claude Code did not answer the MCP server registration.claude -ptime to theinitmessage, same user config:Config Time to init Full: 44 MCP servers (11 connected, 10 failed, 23 needs-auth), 131 plugins 48.5 s --strict-mcp-config12.3 s Load average was about 250 on 16 cores at the time, so a 48 s start can pass 90 s. Please check that #23202 also covers slow MCP connection and slow machines, not only slow SessionStart hooks.
- T3 Code Nightly
Another trigger for the same 90 s
setMcpServerslimit: memory pressure in the agent slice from one runaway agent child. There's no slow hook and no fresh worktree involved.Environment
- Server: T3 Code
0.1.3-nightly.20261023.3566, background service (systemd user unit), Linux x64 (Ubuntu on WSL2), 32 GB RAM, 8 GB swap - Client: desktop app Nightly
0.1.3-nightly.20261023.3566on macOS arm64, connected to that remote server - Claude Code
2.1.309, Opus 5.5
What happened
A long-running thread had its Claude process idle-closed hours earlier, so the next turn needed a fresh
claude --resumelaunch. That turn, and the retry, both failed after about 90 s with "The provider could not start this turn". The trace shows the same cause as in this issue:ClaudeAdapterV2.startTurn 90071 ms Failure ClaudeAgentSdkQueryRunner.open 90037 ms [cause]: Error: Claude Code did not answer the MCP server registration.ClaudeAgentSdkQueryRunner.openoutcomes on that server:Time (UTC) Duration Result 13:28 to 13:35, 5 opens 0.5 to 0.7 s Success 13:39:07 90 095 ms Failure 13:41:49 90 037 ms Failure 13:43:34 90 066 ms Failure Turns in threads whose Claude process was already running kept working the whole time, which made it look thread-specific.
Cause
Around 13:30 an agent in another thread ran a
railway updeploy. That process grew to about 21 GB RSS and stayed there. It ran inside that thread'st3code-claude-*.scope, underapp-t3code-agents.slice:app-t3code-agents.slice MemoryCurrent=27.56 GB MemoryHigh=27.21 GB MemoryMax=29.36 GB memory.events: high 932049, max 0, oom 0, oom_kill 0 Swap: 8192 / 8192 MB usedThe slice sat above
MemoryHighwithout ever reachingMemoryMax, so the kernel throttled every process in it and no OOM kill ever fired. Already-running Claude processes stayed slow but usable. A freshly spawned CLI (about 290 MB resident) couldn't get through startup within 90 s, sosetMcpServerstimed out every time. Nothing in the UI or the error points at memory pressure or at the other thread's child process.What would have helped
- The fix in #23202 (not tying session survival to a fixed 90 s registration window) would likely cover this too.
- When a Claude start times out, surface agent-slice pressure (
memory.eventshighgrowing, orMemoryCurrent > MemoryHigh) in the error, plus the largest process in the slice and which thread owns it. Here the culprit was one process in another thread's scope. - This is related to #18350 (closed): MemoryHigh stalls without an OOM kill.
Diagnosed and written by Claude Opus 5.5 (Claude Code) via
t3 triage.- Server: T3 Code
Another trigger for the same 90 s
setMcpServerslimit: resuming a very large Claude session. This one also shows a gap in the fallback.- T3 Code Nightly
0.1.3-nightly.20261023.3566, Linux x64 background service, Claude Code2.1.314, Opus 5.5. - A long-lived thread (~520 runs). Its native Claude session JSONL had grown to 939 MB (27,665 lines, none malformed).
What happened
- Two follow-up turns, 3 minutes apart, each failed after 90 s with
ClaudeAgentSdkQueryRunnerError→Claude Code did not answer the MCP server registration.T3 had launched Claude within ~2.4 s each time. The Claude process then used ~98 s of CPU (peak 660 MB) before the timeout, so Claude was busy, not idle. - Retrying didn't help. T3 falls back to a fresh native session only when
resumeThreadfails. A registration timeout insidestartTurnon a resumed session isn't treated as a resume failure, so each retry resumed the same session and hit the same timeout. - The thread recovered only by accident. The next turn found the handoffs left
pendingby the failed turns, failed resume withreason: 'uncertain_history_delivery', and opened a fresh session with a full-thread summary. That session registered in 3.3 s.
We couldn't make the hang happen on demand. Isolated copies of the same 939 MB session, run with T3's exact flags, registered in 0.9–2.9 s, and earlier resumes of the same session at a similar size took about 4 s. So size alone isn't the whole cause. On the same host, 8 other runs with small sessions (2.5–14 MB) hit the same error.
Suggestion, alongside a configurable or longer limit: treat a
setMcpServerstimeout on a resumed session likeresume_failed, and retry once on the same run with a fresh session and a context handoff. That would have turned two failed turns and a manual nudge into one slow turn. It also covers the stale-pending-marker path described in #22198, because the timeout happens before the prompt is sent.- T3 Code Nightly
Another trigger for the same 90 s
setMcpServerslimit: memory thrashing inside the agents slice. No hooks are involved and the session is healthy.Setup: T3 Code 0.1.7 (
t3 serveon a Linux VPS, 8 GB RAM, 4 vCPU), Claude Code 2.1.319, Opus 5.5. There are no SessionStart hooks anywhere (user and project settings have none).What happened (UTC, 2026-11-08):
- At 21:44:48 the client sent an "on return" idle
/compact(run 53), with the user's message queued behind it.ClaudeAgentSdkQueryRunner.openhitorchestration-v2.claude-mcp-registration-timeoutat 90 s, retried, and was then interrupted ("Skipped compaction to send a queued message"). - Run 54 (the user's message) timed out twice, at 21:48:03 and 21:49:34 (180 s total), and failed with
Claude timed out while registering its MCP tools. - Four
t3code-claude-*.scopeunits were started for this thread in four minutes. Other threads'opencalls that day took 1–2 s. - No request reached the T3 MCP HTTP endpoint during that window. Claude never got far enough to connect to
t3-code.
Why: the host was thrashing.
sarfor 21:40–22:00 shows load going from 0.5 to 28, 52% system CPU, 230–400 MB/s of page-ins and about 2,500 major faults/s. Disk swap use rose, but most of the I/O was file refaults:app-t3code-agents.slicehasMemoryHigh= max(total − 6 GiB, total/2) ≈ 3.8 GiB on this box. It peaked at 4.17 GiB, andmemory.eventsshowshigh 184131594.- The parent user slice had an admin-set
MemorySwapMax=1G.memory.swap.eventsshowsmax/fail ≈ 306M, andworkingset_refault_fileis about 3.6 billion pages. Once swap was full, reclaim could only evict file pages, so Claude's ~340 MB binary was constantly refaulted and the CLI could not answer the control request within 90 s.
Reproduced afterwards: with the host idle again, the same session resumed with the exact T3 arguments (
--resume --fork-session) answersinitializeandmcp_set_servers(including an HTTP server) in 0.8–0.9 s. So the session and its 35 MB transcript are fine. Raising the slice's swap quota stopped the refault storm on our side.Notes for the fix:
- Under memory pressure, each timeout and retry spawns a fresh Claude process, which adds memory to an already throttled slice. A longer deadline (#23202) would also avoid this cascade.
- The error could mention host or slice memory pressure when the agents slice is over
MemoryHigh(or its PSIfullis high). As it stands, the user has no hint that the cause is outside Claude. - A per-environment setting for the deadline would let small servers opt out of the fixed 90 s.
- At 21:44:48 the client sent an "on return" idle
Another trigger for the same 90 s
setMcpServerslimit: CPU saturation. Fresh sessions also get no retry. There are no hooks, no new worktree, no memory pressure, and no large session.Setup: T3 Code
0.1.8-nightly.20261109.4399, Linux x64 (WSL2, 12 cores, 11 GB RAM), Claude Code with Opus 5.5. About 13 MCP servers and claude.ai connectors are configured globally.What happened (2026-11-09):
- 23
orchestration-v2.claude-mcp-registration-timeoutwarnings across 6 threads in one day. - Each failed
ClaudeAgentSdkQueryRunner.openspan took about 99 s. The provider event log has no CLI events between the previousquery.closeand the timeout. The CLI did not reach init. - During the failures, the load average was 33 to 41 on 12 cores from CPU-bound test jobs (about 8 Python workers at 100%+ each). Memory had 6 GB available.
- At normal load, the same threads start in 1 to 7 s.
- A scheduled task with
freshSession: trueand a 10-minute interval took most of the failures, because each tick starts a newclaudeprocess.
Gap in the fallback: the single retry applies only to resumed sessions:
retry$3({ times: 1, while: (error) => input.options.resume !== void 0 && isClaudeMcpRegistrationTimeoutError(error.cause) })So scheduled-task runs with
freshSession: true, andfreshContextsends, fail on the first timeout. The scheduled run is then marked failed and is not retried.Workaround: cap the CPU-bound jobs so the load stays near the core count, and space scheduled-task ticks farther apart.
Requests:
- Make the limit configurable.
- Retry fresh sessions with a backoff, not only resumed ones.
- Retry a scheduled-task run once on this error before it is marked failed.
- 23
tanstack-source added labelsbug
Note
🤖 Claude Fable 5.2 responding on behalf of Theo
#30166 merged as
86e2cb2. It fixes this for startups that take up to 5 minutes.The 90 second limit now starts after Claude Code finishes startup, so it covers only MCP registration. Startup, which includes SessionStart hooks, has a separate 5 minute limit.
Measured through
ClaudeAgentSdkQueryRunner.openwith the real Claude CLI (2.1.322) and Agent SDK 0.3.321:Case Before After the merge SessionStart/startuphook that sleeps 100sfails at 90.2s (reproduced above) opens after 100.3s CLI boot delayed 95s fails at 90.0s with "Claude timed out while registering its MCP tools" opens after 95.3s, and the turn completes Not fixed: a startup that takes more than 5 minutes still fails, now with "Claude timed out while starting up". A hook with
timeout: 600that uses more than 5 minutes is in that group.Not tested: the memory pressure and large session reports above. If the delay in those cases is in CLI startup, the new limit covers them up to 5 minutes.
This is merged to
main. It is not in a release yet.This is the same problem as #30166, so I'm closing it in favour of that one. If it is different, say how and it will be reopened.
juliusmarminge closed this
Sign in to join this conversation.
Reproduced on main b5a226e49c, Linux x64, web dev client, Claude Code 2.1.303 / Opus 5.5, isolated state. A fixture repository uses a
SessionStart/startupcommand hook withtimeout: 600; its main checkout exits immediately and a fresh linked worktree takes 105 seconds.Sending
reply okin the app succeeds in the main checkout. The fresh-worktree turn fails inClaudeAgentSdkQueryRunner.openat 90,209 ms withClaude Code did not answer the MCP server registration.while the hook is still running. Direct CLI in the main checkout succeeds in 12.7 seconds. The reporter’s private setup script and macOS desktop were not tested.