Skip to content

docs: add comprehensive Claude integration guide #17659

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add example dockerfile main.tf
  • Loading branch information
EdwardAngert committed May 7, 2025
commit 10ce4a0925a584f3c9fb03a2c30b876a23aed3c3
72 changes: 49 additions & 23 deletions docs/ai-coder/claude-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,24 @@ The easiest way to get started with Claude in Coder is to add the
1. Add the Claude Code module to your template's `main.tf` file:

```hcl
# Add Claude Code module for integration
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
# 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
}
```

Expand All @@ -54,14 +65,7 @@ The easiest way to get started with Claude in Coder is to add the
}
```

1. Add another section to pass the API key to the module:

```hcl
module "claude-code" {
# ... existing settings from above
anthropic_api_key = var.anthropic_api_key
}
```
1. With the `coder_env` resource above, your API key is already properly configured. No additional code is needed.

1. Push your template:

Expand Down Expand Up @@ -119,24 +123,46 @@ module "claude-code" {

## Customize your Claude setup

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

```hcl
module "claude-code" {
# ... basic settings from above
# full list at https://coder.com/docs/ai-coder/claude-integration#environment-variables-reference
# Set environment variables to customize Claude behavior

# Choose a specific Claude model
model = "claude-3-7-sonnet-20240229"
# Authentication
resource "coder_env" "claude_api_key" {
agent_id = coder_agent.main.id
name = "CLAUDE_API_KEY"
value = var.anthropic_api_key
}

# Give Claude specific instructions
custom_system_prompt = "You are a Python expert focused on writing clean, efficient code."
# 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"
}

# Add special capabilities through MCP
additional_tools = ["playwright-mcp", "desktop-commander"]
# 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."
}

# Set resource limits
timeout_seconds = 300 # Maximum time for a single request
# 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
}
```

Expand Down
37 changes: 37 additions & 0 deletions docs/ai-coder/examples/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM codercom/enterprise-base:ubuntu

# Install dependencies needed for Claude Code and VS Code
# Using NodeSource to get a more recent version of Node.js
RUN apt-get update && \
apt-get install -y \
curl \
git \
jq \
screen \
sudo \
wget \
&& curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
&& apt-get install -y nodejs \
&& echo "Node.js version: $(node -v)" \
&& echo "npm version: $(npm -v)" \
&& rm -rf /var/lib/apt/lists/*

# Create global npm directories with proper permissions
RUN mkdir -p /usr/local/lib/node_modules && \
chmod 777 /usr/local/lib/node_modules

# Claude Code CLI is installed via npm
# Install the npm package directly for immediate availability
RUN npm install -g @anthropic-ai/claude-code

# Set up user for Coder
ARG USER=coder
RUN useradd --groups sudo --create-home --shell /bin/bash ${USER} \
&& echo "${USER} ALL=(ALL) NOPASSWD:ALL" >/etc/sudoers.d/${USER} \
&& chmod 0440 /etc/sudoers.d/${USER}

USER ${USER}
WORKDIR /home/${USER}

# Configure Claude for dashboard reporting
ENV CODER_MCP_APP_STATUS_SLUG=claude
175 changes: 175 additions & 0 deletions docs/ai-coder/examples/claude-coder-main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
terraform {
required_providers {
coder = {
source = "coder/coder"
}
docker = {
source = "kreuzwerker/docker"
}
}
}

provider "docker" {}
provider "coder" {}

data "coder_workspace" "me" {}
data "coder_workspace_owner" "me" {}

locals {
username = data.coder_workspace_owner.me.name
}

# Parameter for users to enter prompts directly from the workspace creation page
data "coder_parameter" "ai_prompt" {
type = "string"
name = "AI Prompt"
default = ""
description = "Write a prompt for Claude Code"
mutable = true
ephemeral = true
}

resource "coder_agent" "main" {
arch = "amd64"
os = "linux"
dir = "/home/${local.username}"

startup_script = <<-EOT
# Ensure screen is installed (required for Claude Code)
if ! command -v screen &> /dev/null; then
echo "Installing screen for Claude Code..."
sudo apt-get update
sudo apt-get install -y screen
fi

# Ensure Node.js and npm are installed
if ! command -v node &> /dev/null; then
echo "Installing Node.js and npm..."
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs
fi
EOT

env = {
# Git configuration
GIT_AUTHOR_NAME = data.coder_workspace_owner.me.name
GIT_AUTHOR_EMAIL = data.coder_workspace_owner.me.email
GIT_COMMITTER_NAME = data.coder_workspace_owner.me.name
GIT_COMMITTER_EMAIL = data.coder_workspace_owner.me.email
}

# Basic workspace metrics
metadata {
display_name = "CPU Usage"
key = "cpu_usage"
script = "coder stat cpu"
interval = 10
timeout = 1
}

metadata {
display_name = "RAM Usage"
key = "ram_usage"
script = "coder stat mem"
interval = 10
timeout = 1
}
}

# Integrate Claude Code using the official module
module "claude-code" {
source = "registry.coder.com/modules/claude-code/coder"
version = "1.2.1"
agent_id = coder_agent.main.id

# Enable dashboard visualization features
experiment_use_screen = true
experiment_report_tasks = true
}

# Configure Claude with Anthropic API key and Sonnet model
resource "coder_env" "claude_api_key" {
agent_id = coder_agent.main.id
name = "CLAUDE_API_KEY"
value = var.anthropic_api_key
}

resource "coder_env" "claude_model" {
agent_id = coder_agent.main.id
name = "CLAUDE_MODEL"
value = "claude-3-sonnet-20240229"
}

# Pass parameter prompt to Claude Code
resource "coder_env" "claude_task_prompt" {
agent_id = coder_agent.main.id
name = "CODER_MCP_CLAUDE_TASK_PROMPT"
value = data.coder_parameter.ai_prompt.value
}

# Add VS Code integration
module "code-server" {
source = "registry.coder.com/modules/code-server/coder"
version = "1.0.2"
agent_id = coder_agent.main.id
folder = "/home/${local.username}"
}

# Docker resources
resource "docker_volume" "home_volume" {
name = "coder-${data.coder_workspace.me.id}-home"
lifecycle {
ignore_changes = all
}
labels {
label = "coder.workspace_id"
value = data.coder_workspace.me.id
}
}

resource "docker_image" "main" {
name = "codercom/enterprise-base:ubuntu"
}

resource "docker_container" "workspace" {
count = data.coder_workspace.me.start_count
image = docker_image.main.name
name = "coder-${data.coder_workspace_owner.me.name}-${lower(data.coder_workspace.me.name)}"
hostname = data.coder_workspace.me.name

env = ["CODER_AGENT_TOKEN=${coder_agent.main.token}"]
entrypoint = ["sh", "-c", coder_agent.main.init_script]

host {
host = "host.docker.internal"
ip = "host-gateway"
}

volumes {
container_path = "/home/${local.username}"
volume_name = docker_volume.home_volume.name
read_only = false
}

labels {
label = "coder.owner"
value = data.coder_workspace_owner.me.name
}

labels {
label = "coder.workspace_id"
value = data.coder_workspace.me.id
}
}

# Parameter for API authentication
variable "anthropic_api_key" {
type = string
sensitive = true
description = "Anthropic API key for Claude Sonnet integration"
}

# Output with usage instructions
output "claude_usage_instructions" {
value = "Claude 3 Sonnet is available in this workspace. Use it through the terminal with 'claude-code \"Your prompt\"' or through the VS Code extension."
}
Loading