Answer: When the same variable is set in both your shell and a settings file `env` block, the settings file value applies in most sessions, because Claude Code writes each `env` entry into the process environment, replacing the value inherited from the shell. A few variables are special-cased, and some sessions keep the inherited value instead. Status: Confirmed Entry: tool/claude-code/settings/env-var-precedence Revision: 7 Digest: sha256:989dfa30d4c44e2b (changes whenever the content changes) Timeline: Created: 2026-11-13T03:04:05Z Last changed: 2026-11-20T12:20:31Z (settings file precedence: — → a managed settings entry overrides the same variable in user or project settings) Last verified: 2026-11-20T12:20:31Z Next check: 2026-11-21T12:20:31Z Check interval: Daily Expected change: No fixed schedule Data: Field | Value | Source | As of precedence | the settings file value applies in most sessions | [1] | 2026-11-20 mechanism | Claude Code writes each `env` entry into the process environment, replacing the value inherited from the shell | [1] | 2026-11-20 exceptions | A few variables are special-cased | [1] | 2026-11-20 settings file precedence | a managed settings entry overrides the same variable in user or project settings | [1] | 2026-11-20 Sources: [1] Anthropic. "Environment variables". https://code.claude.com/docs/en/env-vars.md Role: primary. Accessed: 2026-11-20T12:20:31Z Quote: "When the same variable is set in both your shell and a settings file `env` block, the settings file value applies in most sessions." (Supports: precedence) Quote: "Claude Code writes each `env` entry into the process environment, replacing the value inherited from the shell." (Supports: mechanism) Quote: "A few variables are special-cased; the [`env` setting](https://code.claude.com/docs/en/settings-reference#env) lists the exceptions." (Supports: exceptions) Quote: "so a managed settings entry overrides the same variable in user or project settings" (Supports: settings file precedence) Published: 2026-11-20T02:53:00Z Snapshot SHA-256: 5a92055baebcd045c25b5e47ef862490e0db33a9505309b81cadf159ce951572 (captured 2026-11-20T12:20:30Z) 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]. Cross-check: not-available at 2026-11-20T12:20:31Z. No independent second source is configured for this entry Last successful check: 2026-11-20T12:20:31Z Last attempt: 2026-11-20T12:20:31Z Notes and limitations: Extracted automatically from a single official source (section "Precedence"). Related: https://latestn.com/tool/claude-code/settings/ghes-plugin-marketplaces How do I add or pre-register a plugin marketplace hosted on GitHub Enterprise Server in Claude Code? https://latestn.com/tool/claude-code/settings/gitlab-cicd-variables What CI/CD variables and parameters can I configure for Claude Code in GitLab? https://latestn.com/tool/claude-code/settings/hook-locations Where can I configure hooks in Claude Code (which settings files and locations)? https://latestn.com/tool/claude-code/settings/enable-powershell-tool How do I enable the PowerShell tool in Claude Code? https://latestn.com/tool/claude-code/settings/enable-remote-control-all-sessions How do I enable Remote Control for all Claude Code sessions by default? https://latestn.com/tool/claude-code/settings/enable-vim-mode How do I enable Vim keybindings in the Claude Code prompt? https://latestn.com/tool/ All entries in AI tools Change log: Time | Event | Change | Source 2026-11-20T12:20:31Z | changed | settings file precedence: — → a managed settings entry overrides the same variable in user or project settings | [1] 2026-11-20T12:20:31Z | changed | exceptions: — → A few variables are special-cased | [1] 2026-11-20T12:20:31Z | changed | mechanism: — → Claude Code writes each `env` entry into the process environment, replacing the value inherited from the shell | [1] 2026-11-20T12:20:31Z | changed | precedence: — → the settings file value applies in most sessions | [1] 2026-11-20T12:20:31Z | changed | Between settings files: a managed settings entry overrides the same variable in user or project settings → — | [1] 2026-11-20T12:20:31Z | changed | Exception for ANTHROPIC_MODEL and CLAUDE_CODE_AUTO_CONNECT_I: Claude Code reads the variable first and uses the `model` or `autoConnectIde` setting only when the variable is unset → — | [1] 2026-11-20T12:20:31Z | changed | Mechanism: Claude Code writes each `env` entry into the process environment, replacing the value inherited from the shell → — | [1] 2026-11-20T12:20:31Z | changed | Precedence: the settings file value applies in most sessions → — | [1] 2026-11-19T12:16:05Z | changed | Between settings files: — → a managed settings entry overrides the same variable in user or project settings | [1] 2026-11-19T12:16:05Z | changed | Exception for ANTHROPIC_MODEL and CLAUDE_CODE_AUTO_CONNECT_I: — → Claude Code reads the variable first and uses the `model` or `autoConnectIde` setting only when the variable is unset | [1] 2026-11-19T12:16:05Z | changed | Mechanism: — → Claude Code writes each `env` entry into the process environment, replacing the value inherited from the shell | [1] 2026-11-19T12:16:05Z | changed | Precedence: — → the settings file value applies in most sessions | [1] 2026-11-19T12:16:05Z | changed | ANTHROPIC_MODEL precedence: Claude Code reads the variable first → — | [1] 2026-11-19T12:16:05Z | changed | exception variables: A few variables are special-cased → — | [1] 2026-11-19T12:16:05Z | changed | general precedence: the settings file value applies in most sessions → — | [1] 2026-11-18T12:16:00Z | changed | ANTHROPIC_MODEL precedence: — → Claude Code reads the variable first | [1] 2026-11-18T12:16:00Z | changed | exception variables: — → A few variables are special-cased | [1] 2026-11-18T12:16:00Z | changed | general precedence: — → the settings file value applies in most sessions | [1] 2026-11-18T12:16:00Z | changed | Between settings files: a managed settings entry overrides the same variable in user or project settings → — | [1] 2026-11-18T12:16:00Z | changed | ANTHROPIC_MODEL / CLAUDE_CODE_AUTO_CONNECT_IDE precedence: Claude Code reads the variable first → — | [1] 2026-11-18T12:16:00Z | changed | Variable vs settings key precedence: which one Claude Code reads first differs per key → — | [1] 2026-11-18T12:16:00Z | changed | Reason for settings file precedence: Claude Code writes each `env` entry into the process environment, replacing the value inherited from the shell → — | [1] 2026-11-18T12:16:00Z | changed | Precedence (shell vs settings file env): the settings file value applies in most sessions → — | [1] 2026-11-17T12:25:31Z | changed | ANTHROPIC_MODEL / CLAUDE_CODE_AUTO_CONNECT_IDE precedence: — → Claude Code reads the variable first | [1] 2026-11-17T12:25:31Z | changed | Variable vs settings key precedence: — → which one Claude Code reads first differs per key | [1] 2026-11-17T12:25:31Z | changed | Reason for settings file precedence: — → Claude Code writes each `env` entry into the process environment, replacing the value inherited from the shell | [1] 2026-11-17T12:25:31Z | changed | Precedence (shell vs settings file env): — → the settings file value applies in most sessions | [1] 2026-11-17T12:25:31Z | changed | Exception for ANTHROPIC_MODEL and CLAUDE_CODE_AUTO_CONNECT_I: Claude Code reads the variable first and uses the `model` or `autoConnectIde` setting only when the variable is unset → — | [1] 2026-11-17T12:25:31Z | changed | Mechanism: Claude Code writes each `env` entry into the process environment, replacing the value inherited from the shell → — | [1] 2026-11-17T12:25:31Z | changed | Precedence: the settings file value applies in most sessions → — | [1] 2026-11-15T12:20:24Z | changed | Between settings files: — → a managed settings entry overrides the same variable in user or project settings | [1] 2026-11-15T12:20:24Z | changed | Exception for ANTHROPIC_MODEL and CLAUDE_CODE_AUTO_CONNECT_I: — → Claude Code reads the variable first and uses the `model` or `autoConnectIde` setting only when the variable is unset | [1] 2026-11-15T12:20:24Z | changed | Exception: A few variables are special-cased → — | [1] 2026-11-15T12:20:24Z | changed | Mechanism: replacing the value inherited from the shell → Claude Code writes each `env` entry into the process environment, replacing the value inherited from the shell | [1] 2026-11-14T12:16:15Z | changed | Exception: — → A few variables are special-cased | [1] 2026-11-14T12:16:15Z | changed | Model variable precedence: Claude Code reads the variable first and uses the `model` or `autoConnectIde` setting only when the variable is unset → — | [1] 2026-11-14T12:16:15Z | changed | Exceptions: A few variables are special-cased → — | [1] 2026-11-14T12:16:15Z | changed | Mechanism: Claude Code writes each `env` entry into the process environment, replacing the value inherited from the shell → replacing the value inherited from the shell | [1] 2026-11-13T03:04:05Z | added | Entry created | — Changes for this entry as a feed: https://latestn.com/tool/claude-code/settings/env-var-precedence/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/env-var-precedence POST: https://latestn.com/dispute/tool/claude-code/settings/env-var-precedence with claim, evidence_url, and optionally field and contact (form-encoded or JSON) GET: https://latestn.com/dispute/tool/claude-code/settings/env-var-precedence?claim={what is wrong}&evidence_url={link} How to cite: LatestN. (2026). When an environment variable and a settings file both set the same Claude Code behavior, which value takes precedence? Revision 7, last verified 2026-11-20T12:20:31Z. https://latestn.com/tool/claude-code/settings/env-var-precedence (accessed 2026-11-21T09:55:05Z). @misc{LatestN_tool_claude_code_settings_env_var_precedence_r7, title = {When an environment variable and a settings file both set the same Claude Code behavior, which value takes precedence?}, author = {{LatestN}}, year = {2026}, howpublished = {\url{https://latestn.com/tool/claude-code/settings/env-var-precedence}}, note = {Revision 7; digest sha256:989dfa30d4c44e2b; last verified 2026-11-20T12:20:31Z; accessed 2026-11-21T09:55:05Z} } 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/env-var-precedence