HomeRun AI Coding Agents in CoderIntegrating Claude with Coder

Integrating Claude with Coder

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:

    # Add Claude Code module for integration module "claude-code" { source = "registry.coder.com/modules/claude-code/coder" version = "1.2.1" # Required - connects to your workspace agent agent_id = coder_agent.main.id # Enable dashboard integration experiment_use_screen = true experiment_report_tasks = true } # Set environment variables for Claude configuration resource "coder_env" "claude_api_key" { agent_id = coder_agent.main.id name = "CLAUDE_API_KEY" value = var.anthropic_api_key }
  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. With the coder_env resource above, your API key is already properly configured. No additional code is needed.

  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

We recommend this method for getting started.

Get your API key from the Anthropic Console and use it as shown in the quick setup above.

Customize your Claude setup

You can customize Claude's behavior with additional environment variables:

# Set environment variables to customize Claude behavior # Authentication resource "coder_env" "claude_api_key" { agent_id = coder_agent.main.id name = "CLAUDE_API_KEY" value = var.anthropic_api_key } # Choose a specific Claude model (use Sonnet for best performance) resource "coder_env" "claude_model" { agent_id = coder_agent.main.id name = "CLAUDE_MODEL" value = "claude-3-sonnet-20240229" } # Custom instructions resource "coder_env" "claude_system_prompt" { agent_id = coder_agent.main.id name = "CODER_MCP_CLAUDE_SYSTEM_PROMPT" value = "You are a Python expert focused on writing clean, efficient code." } # Add special capabilities through MCP resource "coder_env" "claude_mcp_instructions" { agent_id = coder_agent.main.id name = "CODER_MCP_INSTRUCTIONS" value = "Use playwright-mcp and desktop-commander tools when available" } # Claude Code module with dashboard integration module "claude-code" { # ... basic settings from above source = "registry.coder.com/modules/claude-code/coder" agent_id = coder_agent.main.id experiment_use_screen = true experiment_report_tasks = true }

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

If you use VS Code on your local machine with the Remote SSH extension:

  1. Install the Claude extension in your local VS Code.
  2. Configure it with your Anthropic API key.
  3. Connect to your Coder workspace via Remote SSH.
  4. Use Claude directly within VS Code while working with your remote files.

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