Answer: Use the `env` option to set environment variables for the Claude Code process that runs your session. In TypeScript, `env` replaces the subprocess environment (spread `process.env` to keep inherited variables), while in Python the SDK merges your values over the inherited environment and your values override the inherited ones. Status: Confirmed Entry: tool/claude-code/settings/set-environment-variables-sdk Revision: 1 Digest: sha256:63879f62b3a89b7a (changes whenever the content changes) Timeline: Created: 2026-11-13T03:02:39Z Last changed: 2026-11-13T03:02:39Z Last verified: 2026-11-20T12:16:22Z Next check: 2026-11-21T12:16:22Z Check interval: Daily Expected change: No fixed schedule Data: Field | Value | Source | As of Option name | env | [1] | 2026-11-20 Python behavior | the SDK merges your values over the inherited environment, and your values override the inherited ones | [1] | 2026-11-20 TypeScript example | env: { ...process.env, ANTHROPIC_BASE_URL: "https://gateway.example.com" } | [1] | 2026-11-20 Python example | env={"ANTHROPIC_BASE_URL": "https://gateway.example.com"} | [1] | 2026-11-20 Sources: [1] Anthropic. "Configure your agent". https://code.claude.com/docs/en/agent-sdk/configuration.md Role: primary. Accessed: 2026-11-20T12:16:35Z Retrieved via: DeepSeek Fetch API (Markdown conversion; the original server response was not captured) Quote: "The `env` option sets environment variables for the Claude Code process that runs your session." (Supports: Option name) Quote: "**Python**: the SDK merges your values over the inherited environment, and your values override the inherited ones" (Supports: Python behavior) Quote: "env: { ...process.env, ANTHROPIC_BASE_URL: "https://gateway.example.com" }," (Supports: TypeScript example) Quote: "env={"ANTHROPIC_BASE_URL": "https://gateway.example.com"}," (Supports: Python example) Snapshot SHA-256: 4b75bbe13258318e0ca0322d8d080c4cf9188d0e0de13363d8feb2461908ccaa (captured 2026-11-20T12:16:35Z) Verification: Method: Automated extraction from [1] with deepseek-flash (JSON output, thinking disabled). Every value was checked by code to appear verbatim in a quoted passage of [1]. [1] was retrieved through the DeepSeek Fetch API because a direct request did not return usable content. Cross-check: not-available at 2026-11-20T12:16:22Z. No independent second source is configured for this entry Last successful check: 2026-11-20T12:16:22Z Last attempt: 2026-11-20T12:16:22Z Notes and limitations: Extracted automatically from a single official source (section "Set environment variables"). Related: https://latestn.com/tool/claude-code/settings/set-up-status-line How do I set up a custom status line in Claude Code? https://latestn.com/tool/claude-code/settings/set-working-directory-sdk How do I change the working directory for a Claude Code Agent SDK session? https://latestn.com/tool/claude-code/settings/setting-sources-precedence How do I control which settings sources the Claude Code Agent SDK loads? https://latestn.com/tool/claude-code/settings/session-identity-env-vars Which environment variables are related to Claude Code self-hosted session identity verification? https://latestn.com/tool/claude-code/settings/set-cloud-environment-variables How do I set environment variables for a Claude Code cloud environment? https://latestn.com/tool/claude-code/settings/set-environment-variables How do I set environment variables for Claude Code in my shell or in a settings file? https://latestn.com/tool/ All entries in AI tools Change log: Time | Event | Change | Source 2026-11-13T03:02:39Z | added | Entry created | — Changes for this entry as a feed: https://latestn.com/tool/claude-code/settings/set-environment-variables-sdk/latest Challenge this entry: Open challenges: None How: If a value here is wrong or out of date, send what is wrong and a link to evidence. Challenges are queued and checked against the evidence; they do not change the entry by themselves. If the entry changes as a result, the change log says so. Form: https://latestn.com/dispute/tool/claude-code/settings/set-environment-variables-sdk POST: https://latestn.com/dispute/tool/claude-code/settings/set-environment-variables-sdk with claim, evidence_url, and optionally field and contact (form-encoded or JSON) GET: https://latestn.com/dispute/tool/claude-code/settings/set-environment-variables-sdk?claim={what is wrong}&evidence_url={link} How to cite: LatestN. (2026). How do I set environment variables for a Claude Code Agent SDK session? Revision 1, last verified 2026-11-20T12:16:22Z. https://latestn.com/tool/claude-code/settings/set-environment-variables-sdk (accessed 2026-11-21T09:54:26Z). @misc{LatestN_tool_claude_code_settings_set_environment_variables_sdk_r1, title = {How do I set environment variables for a Claude Code Agent SDK session?}, author = {{LatestN}}, year = {2026}, howpublished = {\url{https://latestn.com/tool/claude-code/settings/set-environment-variables-sdk}}, note = {Revision 1; digest sha256:63879f62b3a89b7a; last verified 2026-11-20T12:16:22Z; accessed 2026-11-21T09:54:26Z} } Reuse: License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/) Attribution: Copying and adapting are allowed, including commercially, if you credit LatestN and link to the entry you used. Each entry ends with a ready-made citation. URL: https://latestn.com/tool/claude-code/settings/set-environment-variables-sdk