Using Claude with ClawdBot

Configure Anthropic Claude for best-in-class coding and analysis. Recommended by ClawdBot creator.

🧠 Why Use Claude with ClawdBot?

Claude is the recommended AI model for ClawdBot, especially for coding tasks.

Advantages

💻

Best for Coding

Superior code generation and debugging

📚

Long Context

200K tokens - entire codebases

💰

Prompt Caching

90% cost reduction on repeated context

🎯

Instruction Following

Excellent at complex multi-step tasks

Claude Models Comparison

Model Input Cost Output Cost Best For
Claude 3.5 Sonnet $3/1M tokens $15/1M tokens Coding, analysis (Recommended)
Claude 3 Opus $15/1M tokens $75/1M tokens Highest quality (expensive)
Claude 3 Haiku $0.25/1M tokens $1.25/1M tokens Fast, cheap responses

🔑 API Setup

Step 1: Get API Key

  1. Go to Anthropic Console
  2. Sign up or log in
  3. Navigate to "API Keys"
  4. Click "Create Key"
  5. Name it "ClawdBot" and copy the key

Step 2: Add Credits

Go to "Billing" and add credits ($5 minimum):

  • $5 - Good for testing (~500 messages)
  • $20 - Moderate use (~2000 messages)
  • $50+ - Heavy use

Step 3: Configure ClawdBot

# Method 1: Environment Variable
export ANTHROPIC_API_KEY="sk-ant-api03-xxx"

# Method 2: Config File
# Edit ~/.clawdbot/config.yaml
providers:
  anthropic:
    apiKey: "sk-ant-api03-xxx"
    model: "claude-3-5-sonnet-20241022"
    
# Method 3: Interactive Setup
clawdbot config set anthropic.apiKey

Step 4: Test Connection

# Test API connection
clawdbot test anthropic

# Send test message
clawdbot chat "Hello Claude!"

🎯 Model Selection

Claude 3.5 Sonnet (Recommended)

providers:
  anthropic:
    model: "claude-3-5-sonnet-20241022"
    maxTokens: 4096
    temperature: 0.7

Best for:

  • ✅ Software development
  • ✅ Code review and debugging
  • ✅ Technical writing
  • ✅ Data analysis
  • ✅ Complex reasoning tasks

Claude 3 Opus (Premium)

providers:
  anthropic:
    model: "claude-3-opus-20240229"

Best for:

  • ✅ Highest quality responses
  • ✅ Creative writing
  • ✅ Complex analysis
  • ⚠️ 5x more expensive than Sonnet

Claude 3 Haiku (Budget)

providers:
  anthropic:
    model: "claude-3-haiku-20240307"

Best for:

  • ✅ Simple questions
  • ✅ Quick responses
  • ✅ High-volume use cases
  • ✅ 12x cheaper than Sonnet

⚙️ Advanced Configuration

Complete Config Example

# ~/.clawdbot/config.yaml
providers:
  default: "anthropic"
  
  anthropic:
    apiKey: "${ANTHROPIC_API_KEY}"
    model: "claude-3-5-sonnet-20241022"
    
    # Generation parameters
    maxTokens: 4096
    temperature: 0.7
    topP: 1.0
    topK: 0
    
    # Prompt caching (recommended!)
    enableCaching: true
    cacheSystemPrompt: true
    
    # Rate limiting
    maxRequestsPerMinute: 50
    maxTokensPerMinute: 40000
    
    # Retry logic
    maxRetries: 3
    retryDelay: 1000  # ms
    
    # Timeout
    timeout: 60000  # ms

Temperature Settings

Temperature Use Case Behavior
0.0 - 0.3 Code, factual answers Deterministic, focused
0.4 - 0.7 General use (default) Balanced creativity
0.8 - 1.0 Creative writing More varied, creative

System Prompts

providers:
  anthropic:
    systemPrompt: |
      You are ClawdBot, a helpful AI assistant.
      
      Guidelines:
      - Be concise but thorough
      - For code, always include comments
      - Cite sources when possible
      - Ask clarifying questions if needed
      
      Capabilities:
      - Browse the web
      - Execute code
      - Read/write files
      - Access user's memory

💾 Prompt Caching (Save 90% on Costs!)

Claude's prompt caching can dramatically reduce costs for repeated context.

How It Works

Cache frequently used context (system prompts, documentation, code) and pay only 10% for cached tokens.

Enable Caching

providers:
  anthropic:
    enableCaching: true
    cacheSystemPrompt: true
    
    # Cache threshold (minimum tokens to cache)
    cacheThreshold: 1024
    
    # Cache TTL
    cacheTTL: 300  # 5 minutes

Cost Comparison

Scenario Without Caching With Caching Savings
100 messages with 10K context $30 $6 80%
1000 messages with 10K context $300 $33 89%

What to Cache

  • ✅ System prompts
  • ✅ Project documentation
  • ✅ Code context
  • ✅ User preferences
  • ❌ User messages (changes every time)

⚡ Optimization Tips

1. Use Appropriate Models

# Route by task type
routing:
  rules:
    - pattern: "code|debug|refactor"
      model: "claude-3-5-sonnet"
    
    - pattern: "quick|simple|yes|no"
      model: "claude-3-haiku"
    
    - pattern: "creative|story|poem"
      model: "claude-3-opus"

2. Optimize Context Window

# Limit conversation history
providers:
  anthropic:
    maxHistoryMessages: 20
    
    # Summarize old messages
    summarizeAfter: 50

3. Batch Requests

# Process multiple items in one request
You: Analyze these 5 code files:
1. [file1.py]
2. [file2.py]
...

# Instead of 5 separate requests

4. Set Spending Limits

In Anthropic Console → Billing → Set monthly budget alerts

5. Monitor Usage

# View usage stats
clawdbot stats anthropic

# Check current month spending
clawdbot billing anthropic

❓ Claude FAQ

How much does Claude cost for typical use?
With Claude 3.5 Sonnet and moderate use (50 messages/day), expect $8-12/month. Enable prompt caching to reduce this by 80-90%.
Is Claude better than GPT-4 for coding?
Generally yes. Claude 3.5 Sonnet excels at code generation, debugging, and understanding complex codebases.
Can I use Claude without API costs?
No, Claude requires API credits. For free AI, use local Ollama models instead.
What's the context window size?
All Claude 3 models support 200K tokens (~150K words or ~500 pages).
How do I switch between Claude models?
Change the model parameter in config.yaml or use runtime switching: clawdbot model set claude-3-haiku

📚 Related Guides