Background Claude Code sessions that lose your gateway now stop first
Version 2.1.326 makes a background session stop before any model request when it cannot get the gateway URL you exported in your shell. The cause is where the supervisor gets its environment, and why ANTHROPIC_BASE_URL belongs in a settings file's env block.

Claude Code 2.1.326, published on November 16, 2026, fixed a quiet way to spend money in the wrong place. When a background session lost the gateway URL you exported in your shell, older builds kept going; it now stops before sending any model request and says why.
Three situations trigger it: after the background service crashes, when you reopen the session from a different folder, and when the background service itself runs without that variable. It will not guess an endpoint, and it will not silently fall back to another sign-in.
This article follows the 2.1.326 CHANGELOG, the agent view documentation, Connecting Claude Code to an LLM gateway and the error reference, checked on November 17, 2026. I have not reproduced a crash or a cross-folder reopen, and I did not run these commands on your machine; the reasoning below comes from the documentation, and the verification steps are yours to run where they matter.

Who sends the request: interactive and background sessions differ
Running claude in a terminal ties the process to that terminal. Every session listed in agent view is a background session, hosted by a background service called the supervisor, which is why it survives closing the window. The Session kind row in /status tells them apart: background job · attached or background job · unattended for a background session, interactive otherwise.
That difference is the source of the problem. The supervisor starts the first time you background a session or open agent view. After that, each session is its own Claude Code process spawned by the supervisor. A variable you export lives only in that terminal and the processes it starts; a supervisor that did not start from that terminal gives later session processes nothing.
User reports show the same shape. #87255 describes a Vertex gateway setup: the daemon inherited the full environment, but the worker running the conversation lacked ANTHROPIC_VERTEX_BASE_URL and CLAUDE_CODE_SKIP_VERTEX_AUTH, so every request failed with Could not load the default credentials. A maintainer marked it fixed in 2.1.251 on November 14. #66014 is the mirror image: moving between sessions in agent view could let one session inherit another's ANTHROPIC_* variables and quietly change its model aliases. Both point the same way: a background session's environment does not come only from the terminal in front of you.
When a shell export still reaches the session
The documentation is specific. A gateway exported in your shell reaches a background session, along with the credential and any ANTHROPIC_CUSTOM_HEADERS exported beside it, only when the supervisor was itself started from a shell that exported the same gateway — and only in these cases:
| What you do | Shell-exported gateway carries over |
|---|---|
Background the current session with ← or /background | Yes |
| Dispatch a new session into the directory you are in | Yes |
| Attach to or reply to a stopped session in that directory | Yes |
Restart a session there with claude respawn | Yes |
| Dispatch to another directory, wake a session from one, or let the service restart it after a crash | Not guaranteed; it stops and says so |
On one machine in one folder, the export can look reliable all day. The gap appears when you change folders, reopen, or restart after a crash — the moments you are least likely to notice.
What changed in 2.1.326
The release note says background sessions that lost the shell-exported gateway after a crash, after a reopen from another folder, or when the background service lacks it "now stop before any model request."
Be careful here: the note does not say where older builds sent those requests. What is certain is that they no longer continue with a missing gateway. Whether the request failed outright or reached another credential path depended on the sign-in and the version in use, and I will not guess.
For anyone routing through a gateway, the change turns "spend went to an endpoint you did not intend" into a stop you can read. The cost is that you now have to fix the configuration yourself. The error already had a name: No LLM gateway: a gateway set in your shell isn't passed to a session opened from another folder. Before v2.1.302 the same situation showed Not logged in · Please run /login, without naming the folder at all.
The fix: put the gateway in a settings file's env block
The documentation's advice is direct: any gateway that background sessions must always use belongs in a settings file's env block, not in your shell. When the same variable is set in both, the settings-file value applies in most sessions, because Claude Code writes each env entry into the process environment and replaces the inherited value.
The user-level file ~/.claude/settings.json covers every project:
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.nbility.ai",
"ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY",
"ANTHROPIC_MODEL": "claude-sonnet-4-6"
}
}
For one project only, use .claude/settings.local.json, which Claude Code keeps out of Git when it creates the file. Do not put the key in a committed .claude/settings.json: that file ships with the repository to everyone who clones it.
The credential itself has a sturdier option. When the key rotates or comes from a vault, point apiKeyHelper at a script that prints only the key to stdout, instead of leaving plaintext in a settings file. ANTHROPIC_AUTH_TOKEN travels in Authorization: Bearer and ANTHROPIC_API_KEY in x-api-key; picking the wrong one against a compatible service such as Nbility returns a 401, and connecting Claude Code to a third-party API walks through that distinction.
If you are not sure which files already define your gateway, do not move every variable at once. The same 2.1.326 release added a /status row that says when your provider or an environment variable turns features off. Together with the Base URL, Auth token and API key rows, it shows which endpoint and credential the current session is using. After an edit, that is a better check than echo $ANTHROPIC_BASE_URL.
How to confirm the change
- Start
claudein a new terminal and run/status. The Base URL should be your gateway, and the Auth token or API key row should nameANTHROPIC_AUTH_TOKEN,ANTHROPIC_API_KEYorapiKeyHelper. ALogin methodrow pointing at a claude.ai account means the credential did not arrive. - Send a short message that does not read files; a normal reply confirms the connection.
- Move the session to the background with
←or/background, open agent view, attach back and send another message. - From a different directory, run
claude attachorclaude respawn <session ID>once and checkBase URLin/statusagain. This is the step most likely to expose the problem, and it is exactly the path that failed in older builds. - To inspect the service itself, run
claude daemon status. It reports whether the supervisor is reachable, its process ID and version, the socket directory and how many background sessions are live.
What to do about the two errors
No LLM gateway: opened from another folder · respawn from ~/project means you dispatched, woke or restarted the session from a folder other than the one named. There are two paths:
- Gateway in a settings file: run
claude respawn <id>from any directory. The restarted session reads~/.claude/settings.jsonor that project's.claude/settings.local.json. - Gateway only exported in a terminal:
cdinto the folder in the message from a terminal that has the exports, then runclaude respawn <id>. If the supervisor was not started from that terminal, restart the supervisor first and run the command again.
Could not resolve authentication method at dispatch, while interactive sessions work, means the worker that received the dispatch had no credential; background sessions get theirs from the supervisor. Restart it:
claude daemon stop --any --keep-workers
Within about a minute, run claude agents or claude --bg to start a fresh supervisor. If you authenticate with a variable such as ANTHROPIC_API_KEY rather than /login, run that command from a shell where the variable is set.
Boundaries worth knowing
- Version mismatch:
claude daemon statuswarns when the running supervisor is on a different version than theclaudeyou invoked, which is common after an automatic update. Runclaude daemon stop --anyto pick up the new version. The 2.1.326 fix only applies when the running build includes it. - The supervisor stops: on macOS and Linux, sessions stop about a minute after the supervisor is ended from outside Claude Code. Saved conversations stay on disk, and attaching resumes them.
- Turning background sessions off: set
disableAgentView: trueorCLAUDE_CODE_DISABLE_AGENT_VIEW. When a session keeps picking up another session's provider environment, this is the simplest isolation, and a commenter in #66014 chose it. - Cloud-provider gateways: if you route through
CLAUDE_CODE_USE_VERTEXwithANTHROPIC_VERTEX_BASE_URLandCLAUDE_CODE_SKIP_VERTEX_AUTHinstead ofANTHROPIC_BASE_URL, the endpoint and flag are forwarded as a pair. A stale variable can still be overridden from theenvblock with an empty string, such as"CLAUDE_CODE_USE_VERTEX": "", which Claude Code treats as unset for provider selection. - Nonessential traffic: the gateway carries model requests. The gateway connection guide notes that version checks and telemetry go elsewhere; on a network that only allows the gateway, add
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFICto the sameenvblock.
What this means for background work through Nbility
When ANTHROPIC_BASE_URL points at https://api.nbility.ai, whether a background session receives that address decides which account your usage lands on. Putting it in the env block means the route is the same no matter which folder you dispatched from or how many times the session restarted. That is steadier than repeating export in every terminal, and it removes "which profile was I supposed to source on this machine" from the troubleshooting list.
If you are bringing Claude Code back to mainland China, separate the network layer from the configuration layer first; taking Claude Code back to mainland China covers the other path. This article only covers why a gateway address fails to reach a background session.
FAQ
Do I have to switch to settings.json after upgrading to 2.1.326? No. Shell exports still work for interactive use in one folder. Move them into a settings file when you dispatch to other folders or let sessions run in the background.
The shell and settings.json both set the same variable. Which wins? The settings-file value in most sessions. A few variables are special-cased; the environment variables reference is authoritative.
A background session stopped with No LLM gateway. Did I lose the conversation? The conversation is saved on disk. Running claude respawn <id> from the right folder continues it, and completed work does not need to rerun.
Will a scheduled job quietly spend against another account overnight? That is what this fix prevents: it stops before sending a request instead of running without the gateway. Still write the gateway into your configuration and check /status once in a while.


