Set Environment Variables for Every Session with env in settings.json
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_ENVorRAILS_ENVso 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.
Log in to leave a comment.
The autoUpdatesChannel setting pins Claude Code to a stable release track that skips versions with major regressions.
The language setting makes Claude respond in your preferred language by default, across every session and project.
The attribution setting lets you customize or completely remove Claude's Co-Authored-By trailer from git commits and pull requests.