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:
- A Coder deployment with v2.21.0 or later (use the quickstart guide to get started quickly)
- An API key from Anthropic or access through AWS Bedrock/GCP Vertex AI
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.
-
Create a new Coder template or modify an existing one
-
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 }
-
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 = "" }
-
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 }
-
Push your template:
coder templates push my-claude-template
-
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:
-
Navigate to your repository:
cd /path/to/repo
-
Get a high-level overview:
claude "Help me understand this codebase"
-
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:
-
Make sure you have the GitHub CLI:
which gh || sudo apt-get update && sudo apt-get install -y gh
-
Authenticate (if using external auth with Coder):
eval "$(coder external-auth url-application github)"
-
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:
-
Install Claude Desktop on your local machine
-
Use Coder to configure MCP integration:
# Run this on your local machine (not in the workspace) coder exp mcp configure claude-desktop
-
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:
- Double-check your API key is correct
- Verify the API key has been passed to your workspace
- 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:
- Increase your workspace's memory allocation
- For large requests, try breaking them into smaller, more focused prompts
- If using VS Code extension, try the CLI version instead for better performance
Enable debug logging
-
Check your Claude version:
claude --version
-
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:
- Always store API keys as sensitive template variables.
- Use RBAC to control which users can access AI features.
- Regularly review Claude's activity in your Coder dashboard.
- Consider workspace boundaries to limit what Claude can access.
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.
Variable | Description | Default | Required | Example |
---|---|---|---|---|
CLAUDE_API_KEY | Anthropic API key for authentication | None | Yes | sk-ant-... |
CLAUDE_MODEL | Claude model to use | claude-3-5-sonnet-20240620 | No | claude-3-7-sonnet-20240229 |
CLAUDE_CODE_DEBUG | Enable verbose debug logging | 0 | No | 1 |
CLAUDE_TIMEOUT_SECONDS | Maximum time for a request (seconds) | 300 | No | 600 |
CODER_AGENT_TOKEN | Token for Coder Agent authentication | None | No | coder... |
CODER_AGENT_TOKEN_FILE | Path to file containing the agent token | None | No | /path/to/token |
CODER_MCP_APP_STATUS_SLUG | Identifier for status reporting | None | No | claude |
CODER_MCP_CLAUDE_SYSTEM_PROMPT | Override system prompt | Default prompt | No | "You are a Python expert..." |
CODER_MCP_CLAUDE_CODER_PROMPT | Override coder prompt | Default prompt | No | "You are a Go specialist..." |
CODER_MCP_INSTRUCTIONS | Custom instructions for MCP server | None | No | "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
- Connect Claude to your issue tracker to help with tickets
- Try other AI coding agents in Coder
- Add AI tools via MCP to enhance Claude's capabilities
- Learn about running AI agents without an IDE