Home
/
Run AI Coding Agents in Coder
/
Integrating Claude with Coder

Integrating Claude with Coder

Early Access

Note

This functionality is in beta and is evolving rapidly.

When using any AI tool for development, exercise a level of caution appropriate to your use case and environment. Always review AI-generated content before using it in critical systems.

Join our Discord channel or contact us to get help or share feedback.

Overview

This guide shows you how to set up Anthropic's Claude in your Coder workspaces using Claude Code. Claude Code is an AI-powered coding agent built on Claude that helps with development tasks, documentation, and more.

If you're new to AI coding agents in Coder, check out our introduction to AI agents first.

Prerequisites

Before you begin, make sure you have:

Quick setup: Claude Code template module

The easiest way to get started with Claude in Coder is to add the pre-built module to a template.

  1. Create a new Coder template or modify an existing one

  2. Add the Claude Code module to your template's main.tf file:

    module "claude-code" {
      source  = "registry.coder.com/modules/claude-code/coder"
      version = "1.2.1"
    
      agent                   = var.agent  # This connects the module to your agent
      experiment_use_screen   = true       # Enable reporting to Coder dashboard
      experiment_report_tasks = true       # Show tasks in Coder UI
    }
    
  3. After that section, add a template parameter for your API key:

    variable "anthropic_api_key" {
      type        = string
      description = "Anthropic API key for Claude Code"
      sensitive   = true  # This hides the value in logs and UI
      default     = ""
    }
    
  4. Add another section to pass the API key to the module:

    module "claude-code" {
      # ... existing settings from above
      anthropic_api_key = var.anthropic_api_key
    }
    
  5. Push your template:

    coder templates push my-claude-template
    
  6. Create a workspace with this template and provide your API key when prompted.

Authentication options

Customize your Claude setup

You can customize Claude's behavior with additional options:

module "claude-code" {
  # ... basic settings from above
  # full list at https://coder.com/docs/ai-coder/claude-integration#environment-variables-reference

  # Choose a specific Claude model
  model = "claude-3-7-sonnet-20240229"

  # Give Claude specific instructions
  custom_system_prompt = "You are a Python expert focused on writing clean, efficient code."

  # Add special capabilities through MCP
  additional_tools = ["playwright-mcp", "desktop-commander"]

  # Set resource limits
  timeout_seconds = 300  # Maximum time for a single request
}

For the full list of configuration options, consult the module documentation. For advanced configuration using environment variables, use the table in Environment Variables Reference.

Using Claude in your workspace

Once you've created a workspace with the Claude module, you can start using it right away!

After you connect to your workspace (via SSH, VS Code, or the web terminal), you can run your first Claude command in the terminal:

claude "Hello! What can you help me with today?"

Claude responds in your terminal. You'll also notice that this task appears in the Coder dashboard under your workspace.

Everyday coding tasks

Claude is most helpful for these common tasks:

Generating code:

  • Write a simple function:

    claude "Write a function to sort an array in JavaScript"
    
  • Create a complete component:

    claude "Create a React component that displays a list of user profiles"
    

Working with files:

  • Ask Claude to analyze a specific file:

    claude "Explain what this code does" app.js
    

Improve existing code:

claude "Add error handling to this function" user-service.js

Understanding your codebase:

  1. Navigate to your repository:

    cd /path/to/repo
    
  2. Get a high-level overview:

    claude "Help me understand this codebase"
    
  3. Ask about specific parts:

    claude "Explain how authentication works in this app"
    

Advanced workflows

As you get comfortable with Claude, try having it work directly with GitHub issues:

  1. Make sure you have the GitHub CLI:

    which gh || sudo apt-get update && sudo apt-get install -y gh
    
  2. Authenticate (if using external auth with Coder):

    eval "$(coder external-auth url-application github)"
    
  3. Work on an issue directly:

    ISSUE_DESCRIPTION=$(gh issue view 123 --json body -q .body)
    claude "Implement this feature: $ISSUE_DESCRIPTION"
    

See our issue tracker integration guide for more workflows.

Using Claude in VS Code

Using Claude Desktop with Coder (Advanced)

For power users, you can connect Claude Desktop to your Coder workspace:

  1. Install Claude Desktop on your local machine

  2. Use Coder to configure MCP integration:

    # Run this on your local machine (not in the workspace)
    coder exp mcp configure claude-desktop
    
  3. In Claude Desktop, you can now:

    • Connect to your Coder workspaces
    • View your workspace files
    • Run commands in your workspace
    • Monitor agent activities

Learn more about MCP integration in our best practices guide.

Troubleshooting

Having issues with Claude in your workspace? Here are some common solutions:

Authentication issues

If Claude reports authentication errors:

  1. Double-check your API key is correct
  2. Verify the API key has been passed to your workspace
  3. Try running claude config show to see your current configuration

Claude seems slow or crashes

If Claude is running out of memory or seems sluggish:

  1. Increase your workspace's memory allocation
  2. For large requests, try breaking them into smaller, more focused prompts
  3. If using VS Code extension, try the CLI version instead for better performance

Enable debug logging

  1. Check your Claude version:

    claude --version
    
  2. Enable debug logging:

    export CLAUDE_CODE_DEBUG=1
    claude "Test prompt"
    

Security best practices

When using Claude with Coder, keep these security tips in mind:

Environment Variables Reference

The following environment variables can be used to configure and fine-tune Claude's behavior in your Coder workspace. These are particularly useful for troubleshooting and advanced use cases.

VariableDescriptionDefaultRequiredExample
CLAUDE_API_KEYAnthropic API key for authenticationNoneYessk-ant-...
CLAUDE_MODELClaude model to useclaude-3-5-sonnet-20240620Noclaude-3-7-sonnet-20240229
CLAUDE_CODE_DEBUGEnable verbose debug logging0No1
CLAUDE_TIMEOUT_SECONDSMaximum time for a request (seconds)300No600
CODER_AGENT_TOKENToken for Coder Agent authenticationNoneNocoder...
CODER_AGENT_TOKEN_FILEPath to file containing the agent tokenNoneNo/path/to/token
CODER_MCP_APP_STATUS_SLUGIdentifier for status reportingNoneNoclaude
CODER_MCP_CLAUDE_SYSTEM_PROMPTOverride system promptDefault promptNo"You are a Python expert..."
CODER_MCP_CLAUDE_CODER_PROMPTOverride coder promptDefault promptNo"You are a Go specialist..."
CODER_MCP_INSTRUCTIONSCustom instructions for MCP serverNoneNo"Only use approved tools"

Example usage

# Basic configuration
export CLAUDE_API_KEY="sk-ant-your-api-key"
export CLAUDE_MODEL="claude-3-7-sonnet-20240229"

# Performance tuning
export CLAUDE_TIMEOUT_SECONDS=600

# Advanced debug options
export CLAUDE_CODE_DEBUG=1

# Run Claude with custom settings
claude "Write a unit test for this function"

What's next

See an opportunity to improve our docs? Make an edit.