Environment Variables Reference
Complete reference for all OpenClaw AI environment variables, their defaults, and their relationship to config file settings.
All Environment Variables
| Variable | Default | Description |
|---|---|---|
OPENCLAW_PROVIDER | openai | Default LLM provider (openai, claude, ollama, gemini) |
OPENCLAW_MODEL | gpt-4o | Default model name |
OPENCLAW_OPENAI_KEY | (none) | OpenAI API key |
OPENCLAW_CLAUDE_KEY | (none) | Anthropic Claude API key |
OPENCLAW_GEMINI_KEY | (none) | Google Gemini API key |
OPENCLAW_GROK_KEY | (none) | xAI Grok API key |
OPENCLAW_OLLAMA_URL | http://localhost:11434 | Ollama server base URL |
OPENCLAW_MAX_STEPS | 20 | Default maximum agent execution steps |
OPENCLAW_TIMEOUT | 300 | Default task timeout in seconds |
OPENCLAW_LOG_LEVEL | info | Logging verbosity (debug, info, warn, error) |
OPENCLAW_CONFIG_PATH | ~/.openclaw/config.yaml | Path to config file |
OPENCLAW_PROFILE | default | Active configuration profile name |
OPENCLAW_NO_COLOR | false | Disable ANSI color in terminal output |
OPENCLAW_ALLOWED_TOOLS | all | Comma-separated list of allowed tool packs |
Priority Order
When the same setting is defined in multiple places, OpenClaw uses this priority (highest first):
- CLI flags — e.g.,
--provider claude - Environment variables — e.g.,
OPENCLAW_PROVIDER=claude - Config file values — e.g.,
~/.openclaw/config.yaml - Built-in defaults — hardcoded fallback values
This layered approach means you can run OPENCLAW_PROVIDER=ollama openclaw run "..." to use Ollama for just one command without changing your config file.
.env File Support
OpenClaw automatically loads a .env file from the current working directory if one exists:
# .env file in your project
OPENCLAW_PROVIDER=openai
OPENCLAW_OPENAI_KEY=sk-proj-abc123...
OPENCLAW_MODEL=gpt-4o
OPENCLAW_MAX_STEPS=25
OPENCLAW_LOG_LEVEL=debug# .gitignore — always exclude .env files
echo ".env" >> .gitignoreDocker & Container Setup
Pass environment variables when running OpenClaw in a container:
# docker run with env vars
docker run --rm \
-e OPENCLAW_PROVIDER=openai \
-e OPENCLAW_OPENAI_KEY="sk-proj-..." \
-e OPENCLAW_MODEL=gpt-4o \
-v $(pwd):/workspace \
openclaw/openclaw:latest \
run "Analyze the codebase" --context /workspace# docker-compose.yml
services:
openclaw:
image: openclaw/openclaw:latest
environment:
- OPENCLAW_PROVIDER=openai
- OPENCLAW_OPENAI_KEY=${OPENAI_API_KEY}
- OPENCLAW_MODEL=gpt-4o
volumes:
- ./workspace:/workspace- API Keys Setup — provider-specific key configuration
- openclaw config command
- Config Examples — ready-to-use configurations
Setting Variables Per Operating System
Linux / macOS
# Add to ~/.bashrc or ~/.zshrc for persistence
export OPENCLAW_OPENAI_KEY="sk-proj-..."
export OPENCLAW_DEFAULT_MODEL="gpt-4o-mini"
export OPENCLAW_LOG_LEVEL="info"
# Apply immediately
source ~/.bashrc
# Temporary (current session only)
OPENCLAW_LOG_LEVEL=debug openclaw run "my task"Windows (PowerShell)
# Current session
$env:OPENCLAW_OPENAI_KEY = "sk-proj-..."
$env:OPENCLAW_DEFAULT_MODEL = "gpt-4o-mini"
# Persistent (user-level, survives reboots)
[System.Environment]::SetEnvironmentVariable(
"OPENCLAW_OPENAI_KEY", "sk-proj-...",
[System.EnvironmentVariableTarget]::User
)
# Single-run override
$env:OPENCLAW_LOG_LEVEL="debug"; openclaw run "my task"Docker
# Dockerfile
ENV OPENCLAW_DEFAULT_PROVIDER=openai
ENV OPENCLAW_DEFAULT_MODEL=gpt-4o-mini
ENV OPENCLAW_LOG_LEVEL=info
# Do NOT bake secret keys into Dockerfiles — use --env-file or secrets# docker run with env file (keep .env out of version control)
docker run --env-file .env my-openclaw-image openclaw run "task"Full Environment Variable Reference
| Variable | Default | Description |
|---|---|---|
OPENCLAW_OPENAI_KEY | — | OpenAI API key |
OPENCLAW_ANTHROPIC_KEY | — | Anthropic (Claude) API key |
OPENCLAW_OLLAMA_URL | http://localhost:11434 | Ollama base URL |
OPENCLAW_DEFAULT_PROVIDER | openai | Default LLM provider |
OPENCLAW_DEFAULT_MODEL | gpt-4o-mini | Default model name |
OPENCLAW_MAX_STEPS | 10 | Max autonomous steps per task |
OPENCLAW_TIMEOUT | 120 | API call timeout in seconds |
OPENCLAW_LOG_LEVEL | warning | debug, info, warning, error |
OPENCLAW_CONFIG_PATH | ~/.openclaw/config.yaml | Override config file location |
OPENCLAW_DATA_DIR | ~/.local/share/openclaw | Logs and state storage directory |
OPENCLAW_ALLOW_EXEC | true | Allow shell command execution by agent |
HTTPS_PROXY | — | HTTP/S proxy for all API calls |
Priority Order
OpenClaw resolves configuration in this order (higher wins):
- CLI flags (
--model gpt-4o) - Environment variables (
OPENCLAW_DEFAULT_MODEL) - Project-level
.openclaw.yamlin current directory - User config
~/.openclaw/config.yaml - Built-in defaults
.env File Support
OpenClaw automatically loads a .env file in the current directory if it exists. This is the most convenient method for project-specific secrets:
# myproject/.env
OPENCLAW_OPENAI_KEY=sk-proj-...
OPENCLAW_DEFAULT_MODEL=gpt-4o
OPENCLAW_LOG_LEVEL=info
OPENCLAW_MAX_STEPS=8# .gitignore — NEVER commit .env files
echo ".env" >> .gitignore
echo ".env.*" >> .gitignore
echo "!.env.example" >> .gitignore # commit the example without real values.env.example Template
Check in a sanitized example so team members know which variables to set:
# .env.example (committed to git — no real values)
OPENCLAW_OPENAI_KEY=your-openai-api-key-here
OPENCLAW_ANTHROPIC_KEY=your-anthropic-key-here
OPENCLAW_DEFAULT_PROVIDER=openai
OPENCLAW_DEFAULT_MODEL=gpt-4o-mini
OPENCLAW_MAX_STEPS=10
OPENCLAW_TIMEOUT=120# New team member setup:
cp .env.example .env
nano .env # fill in real valuesPer-Run Variable Override
Override any variable for a single command without changing your config or .env file:
# Linux / macOS: prefix variable before the command
OPENCLAW_DEFAULT_MODEL=claude-3-5-sonnet openclaw run "Review this code"
OPENCLAW_LOG_LEVEL=debug openclaw run "Debug this task"
# Windows PowerShell: set then run
$env:OPENCLAW_DEFAULT_MODEL = "claude-3-5-sonnet"
openclaw run "Review this code"
# Reset after:
Remove-Item Env:OPENCLAW_DEFAULT_MODEL