claude-code - 💡(How to fix) Fix [FEATURE] Split Startup and Runtime env in settings.json

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Root Cause

I often need to differentiate between the environment variables present at Claude Code startup and those actually required at runtime. Hooks and LLM requests can partially address this, but they don't trigger reliably every time. Previously (at least through Claude Code v2.1.77), this wasn't an issue because settings.json was loaded after startup, allowing runtime overrides. However, as of Claude Code v2.1.114, that behaviour has changed, requiring me to manage these differences manually.

Fix Action

Fix / Workaround

Current workaround is using hooks, requests to LLM to change internal env var.

RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing requests and this feature hasn't been requested yet
  • This is a single feature request (not multiple features)

Problem Statement

I often need to differentiate between the environment variables present at Claude Code startup and those actually required at runtime. Hooks and LLM requests can partially address this, but they don't trigger reliably every time. Previously (at least through Claude Code v2.1.77), this wasn't an issue because settings.json was loaded after startup, allowing runtime overrides. However, as of Claude Code v2.1.114, that behaviour has changed, requiring me to manage these differences manually.

Proposed Solution

I'd like to propose adding a new field in settings.json (something like "runtime_env") that allows defining/redefining environment variables to be set within the Claude Code process after startup, rather than being inherited from the shell environment at launch time.

Alternative Solutions

Current workaround is using hooks, requests to LLM to change internal env var.

Priority

High - Significant impact on productivity

Feature Category

Configuration and settings

Use Case Example

Main reason is to hide CLAUDE_CODE_OAUTH_TOKEN env var.

Additional Context

No response

extent analysis

TL;DR

Consider adding a custom hook or modifying the existing settings.json loading mechanism to support runtime environment variable overrides.

Guidance

  • Review the changes introduced in Claude Code v2.1.114 to understand the new settings.json loading behavior and how it affects environment variable inheritance.
  • Explore the possibility of using hooks to set environment variables at runtime, as mentioned in the Alternative Solutions section.
  • Investigate the feasibility of adding a new field to settings.json, such as "runtime_env", to define environment variables that should be set after startup.
  • Evaluate the security implications of exposing environment variables like CLAUDE_CODE_OAUTH_TOKEN and consider alternative approaches to hiding sensitive information.

Example

No code example is provided due to the lack of specific technical details.

Notes

The proposed solution requires further discussion and consideration of the potential impact on the Claude Code architecture and security. The Alternative Solutions section mentions using hooks and LLM requests, but their reliability is uncertain.

Recommendation

Apply workaround: Utilize hooks to set environment variables at runtime, as this approach is already mentioned in the issue and may provide a temporary solution until a more permanent fix is implemented.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [FEATURE] Split Startup and Runtime env in settings.json