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 20+ — Required for OpenClaw
Step 1: Configure Your API Key
Add your Anthropic API key to the OpenClaw configuration:
Option A: Environment variable (recommended for production)
export ANTHROPIC_API_KEY="sk-ant-..."
Option B: Configuration file
In your openclaw.json:
{
"credentials": {
"anthropic": {
"apiKey": "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 the Claude model in your agent settings:
{
"agents": {
"list": [
{
"id": "main",
"model": "anthropic/claude-sonnet-4-5",
"workspace": "/path/to/your/workspace"
}
]
}
}
Model options:
| Model | Best For | Context | Speed | Cost |
|---|---|---|---|---|
| claude-sonnet-4-5 | General use, most tasks | 200K | Fast | $$ |
| claude-opus-4 | Complex reasoning, analysis | 200K | Slower | $$$$ |
Recommendation: Start with Sonnet. Upgrade to Opus only if you hit capability limits.
Step 3: Configure System Prompt
Set your agent's behavior and personality:
{
"agents": {
"list": [
{
"id": "main",
"model": "anthropic/claude-sonnet-4-5",
"systemPrompt": "You are a helpful AI assistant for software development. You have access to the filesystem and can run shell commands. Be concise and technical. Ask clarifying questions when requirements are ambiguous."
}
]
}
}
Tips for effective system prompts:
- Be specific about the agent's role
- Define boundaries (what it should/shouldn't do)
- Set tone and communication style
- Include relevant context about your domain
Step 4: Enable Tools
Configure which tools your agent can use:
{
"agents": {
"list": [
{
"id": "main",
"model": "anthropic/claude-sonnet-4-5",
"tools": {
"filesystem": {
"enabled": true,
"allowedPaths": ["/home/user/projects"]
},
"shell": {
"enabled": true,
"allowedCommands": ["git", "npm", "node", "python"]
},
"browser": {
"enabled": false
}
}
}
]
}
}
Security principle: Only enable tools your agent actually needs. Disable everything else.
Step 5: Set Token Limits
Prevent runaway costs with token limits:
{
"agents": {
"list": [
{
"id": "main",
"model": "anthropic/claude-sonnet-4-5",
"tokenLimits": {
"maxInputTokens": 100000,
"maxOutputTokens": 4096,
"maxTokensPerDay": 1000000
}
}
]
}
}
Considerations:
- Higher limits allow more complex tasks
- Lower limits control costs
- Daily limits prevent billing surprises
Step 6: Test Locally
Start OpenClaw and verify the setup:
openclaw start
Test with a simple prompt:
openclaw chat "What model are you running?"
Expected response should confirm Claude Sonnet.
Test tool access:
openclaw chat "List the files in the current directory"
Verify the agent can use the filesystem tool.
Step 7: Production Configuration
For production deployment, add security settings:
{
"gateway": {
"host": "127.0.0.1",
"port": 3000,
"authToken": "your-secure-token",
"controlUI": false,
"mdns": false
},
"agents": {
"list": [
{
"id": "main",
"model": "anthropic/claude-sonnet-4-5",
"workspace": "/app/workspace"
}
]
},
"security": {
"promptDefense": true,
"egressControl": {
"enabled": true,
"allowedDomains": [
"api.anthropic.com",
"api.github.com"
]
}
}
}
Common Issues
"Model not found" Error
Verify your model string is correct:
- ✅
anthropic/claude-sonnet-4-5 - ❌
claude-sonnet - ❌
anthropic:claude-sonnet-4-5
"Invalid API key" Error
Check that:
- The key starts with
sk-ant- - The key has not been revoked
- The environment variable is set correctly
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:
- Increase
maxOutputTokensfor longer responses - Use Sonnet (200K context) for large codebases
- Consider breaking tasks into smaller steps
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 daily token limits — Prevent billing surprises
- 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
- Production security settings
- Token usage monitoring
- Cost alerts