Feature Request: Extend Environment Variable Expansion to `settings.json` files

Status Open
Maintainer reply None cached
Activity 14 comments · opened Jul 24, 2025

Title: Feature Request: Extend Environment Variable Expansion to settings.json files

Body:

Is your feature request related to a problem? Please describe.

Currently, managing secrets (like API keys) or environment-specific configurations (like webhook URLs for hooks) in settings.json files is challenging. To maintain security and flexibility, these values should not be hardcoded and committed to version control. This makes it difficult to use claude-code effectively in team environments or CI/CD pipelines where configuration is often supplied via the environment.

I've noticed that claude-code already has excellent support for environment variable expansion in .mcp.json files, as detailed in the MCP documentation. However, this valuable feature does not appear to be available in the main settings.json files (~/.claude/settings.json, .claude/settings.json, etc.). This inconsistency limits the ability to configure other core features, like hooks or authentication helpers, in a secure and portable way.

Describe the solution you'd like

I propose extending the existing environment variable expansion mechanism to all settings.json files. The implementation should recursively parse the JSON structure and replace any string value containing $VAR_NAME or ${VAR_NAME} with the corresponding value from the environment.

This would bring the powerful configuration capabilities already present for MCP servers to all aspects of claude-code configuration.

Example Usage

With this feature, a .claude/settings.json file could look like this:

{
  "apiKeyHelper": "/path/to/script-that-uses-api-key.sh",
  "env": {
    "ANTHROPIC_API_KEY": "${CLAUDE_CODE_API_KEY_FROM_ENV}"
  },
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash(git commit*)",
        "hooks": [
          {
            "type": "command",
            "command": "curl -X POST $TEAM_WEBHOOK_URL -d 'A commit is being made!'"
          }
        ]
      }
    ]
  }
}

In this example:

  • ${CLAUDE_CODE_API_KEY_FROM_ENV} would be replaced by the value of the CLAUDE_CODE_API_KEY_FROM_ENV environment variable, which can be used by the apiKeyHelper script.
  • $TEAM_WEBHOOK_URL in the hook command would be replaced by the value of the TEAM_WEBHOOK_URL environment variable.

Why is this feature valuable?

  • Enhanced Security: Secrets like API keys can be managed via environment variables or a secret manager, preventing them from being committed to source control.
  • CI/CD Integration: Simplifies running claude-code in automated pipelines where configurations are passed as environment variables.
  • Improved Flexibility for Teams: Allows a single, shared .claude/settings.json to be committed to a repository, while each developer can provide their personal secrets or environment-specific values locally.
  • Configuration Consistency: Aligns the behavior of settings.json with the existing, useful functionality of .mcp.json.

Prior Art / Reference

The best reference is claude-code's own implementation for .mcp.json files. Additionally, this is a standard feature in many modern developer CLI tools, such as the Google Gemini CLI, which demonstrates its utility in the ecosystem.

Thank you for considering this enhancement

View original on GitHub ↗

14 Comments

ericfitz · 11 months ago

I'd like to specifically configure things in settings.local.json like:

"read($TMPDIR/*)",
bendavis78 · 10 months ago

This would be useful in ~/.claude.json as well

gabrielbryk · 9 months ago

Bump this, would love var expansion in .claude.json so i can keep sensitive vars out of files

Nucs · 8 months ago

This is relatively a small feature, can we have this?
Bump, nothing better than having more control via settings over claude code's behavior.

github-actions[bot] · 7 months ago

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

PaulRBerg · 7 months ago

please keep active

shitchell · 6 months ago

I would personally love env.PATH = ".claude/bin/:$PATH". I have a few wrapper scripts I like claude to use that offer more reliable security through parsing arguments as an array (vs PerToolUse parsing a command string via regex), but I cannot use those in team projects in a portable way.

Resteklicken · 4 months ago

This is really important for our team, please implement it.

ahammond · 3 months ago
additionalDirectories: [$RELATED_REPO_MAIN_BRANCH_WORKTREE]

would help enormously.

Nucs · 3 months ago

Anthropic will release 10 features a month but wont implement a one-liner feature

roothider · 3 months ago

is this fixed?

pedrolp85 · 2 months ago

I think this feature is much needed

additionalDirectories: [${ENV}/your_repo]

dr-at-agi · 2 months ago

This would be incredibly useful.

nicoobkio · 1 month ago

We need this