# Environment Variables Documentation

OpenClaw manages environment variables through a hierarchical system that respects existing values without overriding them.

## Loading Priority

The system follows a specific precedence order from highest to lowest priority:

1. **Process environment** - Variables already present in the parent shell/daemon
2. **Local `.env` file** - Located in the current working directory
3. **Global `.env` file** - Found at `~/.openclaw/.env`
4. **Configuration file settings** - The `env` block in `~/.openclaw/openclaw.json`
5. **Shell environment import** - Optional login-shell variables when enabled

## Configuration Methods

You can define variables directly within the config file using two equivalent approaches:

```json5
{
  env: {
    OPENROUTER_API_KEY: "sk-or-...",
    vars: {
      GROQ_API_KEY: "gsk-...",
    },
  },
}
```

Shell environment import capability allows the system to run your login shell and import only missing expected keys.

## Variable Substitution

Config files support variable references using `${VAR_NAME}` syntax within string values, enabling dynamic configuration based on environment settings.

## Related Resources

The documentation links to gateway configuration guides, FAQ materials about env var loading, and models overview pages for additional context.
