Claude + OpenClaw: Complete Setup Guide for Production (2026)
This guide walks through setting up OpenClaw with Anthropic's Claude models—from initial configuration to production deployment.
Why Claude for OpenClaw
Claude (Sonnet and Opus) is well-suited for agentic workflows:
- Strong instruction following — Reliable execution of complex tasks
- Extended context — 200K tokens for large codebases and documents
- Tool use capabilities — Native support for function calling
- Safety features — Built-in refusals for harmful requests
For most OpenClaw use cases, Claude Sonnet provides the best balance of capability, speed, and cost. Claude Opus is better for complex reasoning tasks where latency is acceptable.
Prerequisites
Before starting:
- Anthropic API key — Get one at console.anthropic.com
- OpenClaw installed — Follow the official installation guide
- Node.js 22+ — Required for OpenClaw
Step 1: Configure Your API Key
Add your Anthropic API key to the OpenClaw configuration.
Option A: Environment variable (recommended)
export ANTHROPIC_API_KEY="sk-ant-..."
Option B: Auth profile via CLI
openclaw configure --section model
The interactive wizard will prompt for your Anthropic credentials. You can also set it directly:
openclaw config set auth.profiles.anthropic:default '{"provider":"anthropic","mode":"api_key"}' --strict-json
Option C: Configuration file
In your ~/.openclaw/openclaw.json:
{
env: {
ANTHROPIC_API_KEY: "sk-ant-..."
}
}
Security note: For production, use environment variables or a secrets manager. Don't commit API keys to version control.
Step 2: Select Your Model
Configure Claude as your primary model:
{
agent: {
workspace: "~/.openclaw/workspace",
model: {
primary: "anthropic/claude-sonnet-4-5"
}
}
}
Or via the CLI:
openclaw config set agent.model.primary "anthropic/claude-sonnet-4-5"
Model options:
| Model | Best For | Context | Speed | Cost |
|---|---|---|---|---|
| anthropic/claude-sonnet-4-5 | General use, most tasks | 200K | Fast | $$ |
| anthropic/claude-opus-4-6 | Complex reasoning, analysis | 200K | Slower | $$$$ |
Recommendation: Start with Sonnet. Upgrade to Opus only if you hit capability limits.
Want fallbacks? Set a fallback model in case Anthropic has an outage:
{
agent: {
model: {
primary: "anthropic/claude-sonnet-4-5",
fallbacks: ["anthropic/claude-opus-4-6", "openai/gpt-5.2"]
}
}
}
Step 3: Configure Your Agent
Set your agent's identity and workspace:
{
identity: {
name: "Clawd",
theme: "helpful assistant",
emoji: "🦞"
},
agent: {
workspace: "~/.openclaw/workspace",
model: { primary: "anthropic/claude-sonnet-4-5" }
}
}
OpenClaw uses bootstrap files in your workspace to shape agent behavior:
AGENTS.md— Operating instructions and memorySOUL.md— Persona, boundaries, toneTOOLS.md— Tool usage notes and conventions
Edit these files to define your agent's personality and expertise. They're injected into the agent context at the start of every session.
Step 4: Configure Tools
Control which tools your agent can use:
{
tools: {
allow: ["exec", "read", "write", "edit"],
deny: ["browser"]
}
}
Or via the CLI:
openclaw config set tools.allow '["exec","read","write","edit"]' --strict-json
openclaw config set tools.deny '["browser"]' --strict-json
Security principle: Only enable tools your agent actually needs. Disable everything else.
Step 5: Set Up Model Allowlist
Control which models are available for switching via the /model command:
{
agents: {
defaults: {
models: {
"anthropic/claude-sonnet-4-5": { alias: "sonnet" },
"anthropic/claude-opus-4-6": { alias: "opus" },
"openai/gpt-5.2": { alias: "gpt" }
}
}
}
}
This lets you switch between models on the fly without editing config.
Step 6: Test Locally
Start the OpenClaw gateway:
openclaw gateway run
Test with a message:
openclaw message send "What model are you running?"
Expected response should confirm Claude Sonnet.
Check gateway health:
openclaw status
Verify tools work by asking the agent to list files or run a command.
Step 7: Production Configuration
For production, lock down the gateway:
{
gateway: {
mode: "local",
port: 18789,
bind: "loopback",
auth: {
mode: "token",
token: "your-secure-gateway-token"
},
controlUi: { enabled: false }
},
agent: {
workspace: "~/.openclaw/workspace",
model: {
primary: "anthropic/claude-sonnet-4-5",
fallbacks: ["anthropic/claude-opus-4-6"]
}
},
channels: {
whatsapp: {
allowFrom: ["+15555550123"]
}
}
}
Key production settings:
- Bind to loopback only — no external access without a reverse proxy
- Token auth on the gateway — prevents unauthorized API access
- Disable Control UI — reduces attack surface
- Set
allowFromon channels — only authorized senders can interact
Common Issues
"Model not found" Error
Model refs use provider/model format (split on first /):
- ✅
anthropic/claude-sonnet-4-5 - ❌
claude-sonnet - ❌
anthropic:claude-sonnet-4-5
"Invalid API key" Error
Check that:
- Your key starts with
sk-ant- - The key has not been revoked
- The environment variable is set:
echo $ANTHROPIC_API_KEY - Or your auth profile is configured:
openclaw config get auth
High Latency
If responses are slow:
- Switch from Opus to Sonnet for faster responses
- Reduce context size by limiting workspace scope
- Check your network connection to Anthropic's API
Token Limit Errors
If you hit token limits:
- Use Sonnet (200K context) for large codebases
- Consider breaking tasks into smaller steps
- Use the
/modelcommand to switch to a cheaper model for simpler tasks
Cost Management
Estimated costs (as of 2026):
| Model | Input | Output | 1M tokens |
|---|---|---|---|
| Sonnet | $3 | $15 | ~$9 avg |
| Opus | $15 | $75 | ~$45 avg |
Cost optimization tips:
- Use Sonnet by default — Opus only when needed
- Set fallbacks to cheaper models — Use Gemini Flash or GPT-5.2 as cost-efficient fallbacks
- Cache common responses — Reduce redundant API calls
- Monitor usage — Check Anthropic dashboard regularly
With Clawctl
If you're using Clawctl, Claude configuration is simpler. Sign up at clawctl.com/checkout, and the dashboard setup wizard walks you through it:
- Select Anthropic as your provider
- Paste your API key
- Clawctl validates the connection and deploys
No config files. No environment variables. Just pick your model and go.
Clawctl handles:
- Secure credential storage (AES-256-GCM encrypted)
- Production gateway security
- Token usage monitoring
- Cost alerts