Environment Variables

Configure OpenClaw with environment variables—API keys, tokens, paths

OpenClaw reads several environment variables for API keys, channel tokens, workspace paths, and gateway settings. Use environment variables instead of hardcoding secrets in your config file for better security and portability.

Common Variables

Set these before starting the gateway or in your shell profile (~/.bashrc, ~/.zshrc):

  • ANTHROPIC_API_KEY — Anthropic API key (if not using OAuth)
  • OPENAI_API_KEY — OpenAI API key
  • GOOGLE_GENERATIVE_AI_API_KEY — Google Gemini API key
  • OPENROUTER_API_KEY — OpenRouter API key
  • XAI_API_KEY — xAI (Grok) API key
  • TELEGRAM_BOT_TOKEN, DISCORD_BOT_TOKEN, etc. — Channel tokens (or use Secrets Management)

Workspace & Config Path

Override default paths:

  • OPENCLAW_CONFIG or CLAWDBOT_CONFIG — Path to config JSON
  • OPENCLAW_WORKSPACE — Workspace root (default ~/.openclaw/workspace)
  • OPENCLAW_HOME — Home directory for OpenClaw data

Legacy installs may use CLAWDBOT_* or MOLTBOT_* variants.

Usage

Export variables in your shell or use a .env file with a loader. For production, prefer SecretRef and vault integration over plain environment variables.

Example
export ANTHROPIC_API_KEY="sk-ant-..."
export OPENAI_API_KEY="sk-..."
openclaw start

Reference

Full list of supported variables: docs.openclaw.ai. For channel tokens and gateway auth, see Secrets Management and Configuration Guide.