{"slug": "exporting-anthropic-base-url-does-not-reach-the-claude-code-panel-in-vscode", "title": "Exporting ANTHROPIC_BASE_URL does not reach the Claude Code panel in VSCode", "summary": "A developer has created a toolkit to synchronize environment variables between the Claude Code CLI and the VSCode extension panel, addressing the issue that the panel ignores shell exports like ANTHROPIC_BASE_URL. The toolkit manages a specific set of six variables in VSCode's settings.json with backup and restore, while the CLI wrapper routes per-process without persisting changes. The solution is designed around the asymmetry between the terminal's process scope and the panel's machine scope.", "body_md": "`export ANTHROPIC_BASE_URL=http://127.0.0.1:20128`\n\nin your shell routes the `claude`\n\nCLI to a local endpoint. Open the Claude Code panel in VSCode in the same project and it still talks to Anthropic directly. The two live on different environment surfaces, and that is the whole problem.\n\nThe CLI reads the environment of the process you started it from. The VSCode panel does not: the extension spawns its agent process from the VSCode window process, so its environment is whatever VSCode itself was started with — the desktop/login environment, not the shell you typed `export`\n\ninto five seconds ago.\n\nTwo consequences that bite in opposite directions:\n\nThe escape hatch the extension gives you is a settings key, `claudeCode.environmentVariables`\n\n, which is a list of `{name, value}`\n\npairs injected into the agent process. You can check what your panel actually sees right now — this runs anywhere `jq`\n\ndoes:\n\n```\n# macOS\nS=\"$HOME/Library/Application Support/Code/User/settings.json\"\n# Linux:   S=\"$HOME/.config/Code/User/settings.json\"\n# Windows: S=\"$APPDATA/Code/User/settings.json\"\n\njq -r '.[\"claudeCode.environmentVariables\"] // []\n  | if length == 0\n    then \"panel env: (none set) -> extension inherits the VSCode process env\"\n    else (.[] | \"\\(.name)=\\(if .name|test(\"TOKEN|KEY\") then \"***\" else .value end)\")\n    end' \"$S\"\n```\n\nOn a machine that has never been switched, that prints the `(none set)`\n\nline. That is the honest answer to \"why is my panel ignoring the variable\".\n\n`claudeCode.environmentVariables`\n\nis a plain array in your user `settings.json`\n\n, and hand-editing it has three failure modes I hit before writing anything:\n\n`ANTHROPIC_BASE_URL`\n\nbehind while removing the token and the panel points at a router with no credential.`NODE_EXTRA_CA_CERTS`\n\n— is one careless overwrite away from gone.So the toolkit I ended up with treats the array as *partly* owned. It manages exactly six names:\n\n```\nANTHROPIC_BASE_URL\nANTHROPIC_AUTH_TOKEN\nANTHROPIC_API_KEY\nANTHROPIC_MODEL\nANTHROPIC_SMALL_FAST_MODEL\nCLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC\n```\n\nEntries whose name is not on that list are read, kept aside, and written back untouched. Before any write it copies `settings.json`\n\nto `settings.json.bak-claude-router`\n\n, and if serialisation throws it restores the backup and exits non-zero rather than leaving you with half a settings file.\n\n```\n& \"$env:USERPROFILE\\.claude\\9router\\vscode-switch.ps1\" on      # inject the six\n& \"$env:USERPROFILE\\.claude\\9router\\vscode-switch.ps1\" status  # print base URL + model, never the token\n& \"$env:USERPROFILE\\.claude\\9router\\vscode-switch.ps1\" off     # remove only the six\n```\n\n`on`\n\nand `off`\n\nneed a **Developer: Reload Window** afterwards — the agent process reads its environment once at spawn.\n\nFor the CLI the right scope is the narrow one, so there routing is per-process and nothing is persisted:\n\n```\nclaude                    # default Anthropic connection\nclaude-9router            # same CLI, routed\nclaude-9router --resume   # normal Claude CLI arguments pass through\n```\n\n`claude-9router`\n\nsets the variables inside its own process, unsets `ANTHROPIC_API_KEY`\n\nso a leftover key cannot win over the router token, then execs `claude`\n\n. Close the window and the routing is gone. Nothing in `~/.claude`\n\nis rewritten.\n\nThat asymmetry is deliberate and it is the actual design decision: the terminal gets process scope because a shell is cheap to start, the panel gets machine scope with an explicit on/off because the extension gives no narrower hook. Cost of the second: you cannot have one routed window and one direct window at the same time. If you need both, use the panel for one and `claude-9router`\n\nin a terminal for the other.\n\nThe endpoint is a [9Router](https://github.com/decolua/9router) instance, whose Anthropic-compatible `/v1/messages`\n\nfronts a long list of providers. The toolkit hard-codes none of them; it reads a gitignored local file:\n\n```\n{\n  \"baseUrl\": \"http://127.0.0.1:20128\",\n  \"authToken\": \"your-9router-api-key\",\n  \"mainModel\": \"provider/model-id\",\n  \"smallFastModel\": \"provider/smaller-model-id\"\n}\n```\n\nLimits, stated plainly:\n\nCode, tests and setup guide: ** https://github.com/vinhnguyenthanhdn/claude-router** (MIT).\n\nThe open gap is the platform one: the Windows paths are the only ones implemented and tested, and porting is work I have not done. Three issues are scoped and open:\n\n`claude-9router.ps1`\n\nIf you only want to confirm the diagnosis rather than write code: run the `jq`\n\nsnippet above on your machine and tell me what your panel is actually inheriting. That answer is useful on its own.", "url": "https://wpnews.pro/news/exporting-anthropic-base-url-does-not-reach-the-claude-code-panel-in-vscode", "canonical_source": "https://dev.to/vinhnguyenthanhdn/exporting-anthropicbaseurl-does-not-reach-the-claude-code-panel-in-vscode-49n9", "published_at": "2026-08-15 16:56:49+00:00", "updated_at": "2026-08-15 17:12:00.235157+00:00", "lang": "en", "topics": ["developer-tools"], "entities": ["Anthropic", "VSCode", "Claude Code", "9Router"], "alternates": {"html": "https://wpnews.pro/news/exporting-anthropic-base-url-does-not-reach-the-claude-code-panel-in-vscode", "markdown": "https://wpnews.pro/news/exporting-anthropic-base-url-does-not-reach-the-claude-code-panel-in-vscode.md", "text": "https://wpnews.pro/news/exporting-anthropic-base-url-does-not-reach-the-claude-code-panel-in-vscode.txt", "jsonld": "https://wpnews.pro/news/exporting-anthropic-base-url-does-not-reach-the-claude-code-panel-in-vscode.jsonld"}}