All Environment Variables

VariableDefaultDescription
OPENCLAW_PROVIDERopenaiDefault LLM provider (openai, claude, ollama, gemini)
OPENCLAW_MODELgpt-4oDefault 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_URLhttp://localhost:11434Ollama server base URL
OPENCLAW_MAX_STEPS20Default maximum agent execution steps
OPENCLAW_TIMEOUT300Default task timeout in seconds
OPENCLAW_LOG_LEVELinfoLogging verbosity (debug, info, warn, error)
OPENCLAW_CONFIG_PATH~/.openclaw/config.yamlPath to config file
OPENCLAW_PROFILEdefaultActive configuration profile name
OPENCLAW_NO_COLORfalseDisable ANSI color in terminal output
OPENCLAW_ALLOWED_TOOLSallComma-separated list of allowed tool packs

Priority Order

When the same setting is defined in multiple places, OpenClaw uses this priority (highest first):

  1. CLI flags — e.g., --provider claude
  2. Environment variables — e.g., OPENCLAW_PROVIDER=claude
  3. Config file values — e.g., ~/.openclaw/config.yaml
  4. Built-in defaults — hardcoded fallback values
💡
Use This for Environment Overrides

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" >> .gitignore

Docker & 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
💡
See Also

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

VariableDefaultDescription
OPENCLAW_OPENAI_KEYOpenAI API key
OPENCLAW_ANTHROPIC_KEYAnthropic (Claude) API key
OPENCLAW_OLLAMA_URLhttp://localhost:11434Ollama base URL
OPENCLAW_DEFAULT_PROVIDERopenaiDefault LLM provider
OPENCLAW_DEFAULT_MODELgpt-4o-miniDefault model name
OPENCLAW_MAX_STEPS10Max autonomous steps per task
OPENCLAW_TIMEOUT120API call timeout in seconds
OPENCLAW_LOG_LEVELwarningdebug, info, warning, error
OPENCLAW_CONFIG_PATH~/.openclaw/config.yamlOverride config file location
OPENCLAW_DATA_DIR~/.local/share/openclawLogs and state storage directory
OPENCLAW_ALLOW_EXECtrueAllow shell command execution by agent
HTTPS_PROXYHTTP/S proxy for all API calls

Priority Order

OpenClaw resolves configuration in this order (higher wins):

  1. CLI flags (--model gpt-4o)
  2. Environment variables (OPENCLAW_DEFAULT_MODEL)
  3. Project-level .openclaw.yaml in current directory
  4. User config ~/.openclaw/config.yaml
  5. 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 values

Per-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