$ recombobulate _
home / tips / set-environment-variables-for-every-session-with-env-in-settingsjson
0

Set Environment Variables for Every Session with env in settings.json

bagwaa @bagwaa · Mar 26, 2026 · Configuration
set-environment-variables-for-every-session-with-env-in-settingsjson

If you need an environment variable available every time Claude Code runs a Bash command, the env key in settings.json is the cleanest way to set it. No shell profile changes required, and it works regardless of how Claude Code is launched.

{
  "env": {
    "NODE_ENV": "development",
    "RAILS_ENV": "test",
    "CLAUDE_CODE_ENABLE_TELEMETRY": "1",
    "OTEL_METRICS_EXPORTER": "otlp"
  }
}

Add this to ~/.claude/settings.json to apply the variables across all your projects, or to .claude/settings.json in a specific repo to scope them to that project only.

Common uses:

  • Setting NODE_ENV or RAILS_ENV so test commands work without extra flags
  • Enabling telemetry exporters for observability integrations
  • Passing a custom npm registry or proxy URL to all Bash tool calls

The variables are applied to every session Claude Code starts. They supplement the environment Claude inherits from your shell rather than replacing it.

If you need a variable only in the current project and want to keep it out of version control, use .claude/settings.local.json instead (this file is gitignored by default):

{
  "env": {
    "DATABASE_URL": "postgres://localhost/myapp_dev"
  }
}

Note that the env key in settings is separate from the ANTHROPIC_API_KEY and other variables used to configure Claude Code itself. Those belong directly in your shell environment.

The env key is the zero-friction way to make project environment variables available to every Bash tool call.


via Claude Code Settings

~/recombobulate $ tip --comments --count=0

Log in to leave a comment.

~/recombobulate $ tip --related --limit=3
0
Switch to the Stable Update Channel with autoUpdatesChannel

The autoUpdatesChannel setting pins Claude Code to a stable release track that skips versions with major regressions.

bagwaa @bagwaa · 1 hour ago
0
Set Claude's Response Language with the language Setting

The language setting makes Claude respond in your preferred language by default, across every session and project.

bagwaa @bagwaa · 1 hour ago
0
Customize or Remove Claude's Git Attribution with the attribution Setting

The attribution setting lets you customize or completely remove Claude's Co-Authored-By trailer from git commits and pull requests.

bagwaa @bagwaa · 1 hour ago