|
1 | 1 | ---
|
2 | 2 | display_name: Claude Code
|
3 |
| -description: Run Claude Code in your workspace |
| 3 | +description: Run the Claude Code agent in your workspace. |
4 | 4 | icon: ../../../../.icons/claude.svg
|
5 | 5 | verified: true
|
6 |
| -tags: [agent, claude-code, ai, tasks] |
| 6 | +tags: [agent, claude-code, ai, tasks, anthropic] |
7 | 7 | ---
|
8 | 8 |
|
9 | 9 | # Claude Code
|
10 | 10 |
|
11 |
| -Run the [Claude Code](https://docs.anthropic.com/en/docs/agents-and-tools/claude-code/overview) agent in your workspace to generate code and perform tasks. |
| 11 | +Run the [Claude Code](https://docs.anthropic.com/en/docs/agents-and-tools/claude-code/overview) agent in your workspace to generate code and perform tasks. This module integrates with [AgentAPI](https://github.com/coder/agentapi) for task reporting in the Coder UI. |
12 | 12 |
|
13 | 13 | ```tf
|
14 | 14 | module "claude-code" {
|
15 |
| - source = "registry.coder.com/coder/claude-code/coder" |
16 |
| - version = "2.2.1" |
17 |
| - agent_id = coder_agent.example.id |
18 |
| - folder = "/home/coder" |
19 |
| - install_claude_code = true |
20 |
| - claude_code_version = "latest" |
| 15 | + source = "registry.coder.com/coder/claude-code/coder" |
| 16 | + version = "3.0.0" |
| 17 | + agent_id = coder_agent.example.id |
| 18 | + workdir = "/home/coder/project" |
| 19 | + claude_api_key = "xxxx-xxxxx-xxxx" |
21 | 20 | }
|
22 | 21 | ```
|
23 | 22 |
|
24 |
| -> **Security Notice**: This module uses the [`--dangerously-skip-permissions`](https://docs.anthropic.com/en/docs/claude-code/cli-usage#cli-flags) flag when running Claude Code. This flag |
25 |
| -> bypasses standard permission checks and allows Claude Code broader access to your system than normally permitted. While |
26 |
| -> this enables more functionality, it also means Claude Code can potentially execute commands with the same privileges as |
27 |
| -> the user running it. Use this module _only_ in trusted environments and be aware of the security implications. |
| 23 | +> [!WARNING] |
| 24 | +> **Security Notice**: This module uses the `--dangerously-skip-permissions` flag when running Claude Code tasks. This flag bypasses standard permission checks and allows Claude Code broader access to your system than normally permitted. While this enables more functionality, it also means Claude Code can potentially execute commands with the same privileges as the user running it. Use this module _only_ in trusted environments and be aware of the security implications. |
28 | 25 |
|
29 | 26 | > [!NOTE]
|
30 | 27 | > By default, this module is configured to run the embedded chat interface as a path-based application. In production, we recommend that you configure a [wildcard access URL](https://coder.com/docs/admin/setup#wildcard-access-url) and set `subdomain = true`. See [here](https://coder.com/docs/tutorials/best-practices/security-best-practices#disable-path-based-apps) for more details.
|
31 | 28 |
|
32 | 29 | ## Prerequisites
|
33 | 30 |
|
34 |
| -- You must add the [Coder Login](https://registry.coder.com/modules/coder-login) module to your template |
35 |
| - |
36 |
| -The `codercom/oss-dogfood:latest` container image can be used for testing on container-based workspaces. |
| 31 | +- An **Anthropic API key** or a _Claude Session Token_ is required for tasks. |
| 32 | + - You can get the API key from the [Anthropic Console](https://console.anthropic.com/dashboard). |
| 33 | + - You can get the Session Token using the `claude setup-token` command. This is a long-lived authentication token (requires Claude subscription) |
37 | 34 |
|
38 | 35 | ## Examples
|
39 | 36 |
|
40 |
| -### Run in the background and report tasks (Experimental) |
| 37 | +### Usage with Tasks and Advanced Configuration |
41 | 38 |
|
42 |
| -> This functionality is in early access as of Coder v2.21 and is still evolving. |
43 |
| -> For now, we recommend testing it in a demo or staging environment, |
44 |
| -> rather than deploying to production |
45 |
| -> |
46 |
| -> Learn more in [the Coder documentation](https://coder.com/docs/tutorials/ai-agents) |
47 |
| -> |
48 |
| -> Join our [Discord channel](https://discord.gg/coder) or |
49 |
| -> [contact us](https://coder.com/contact) to get help or share feedback. |
| 39 | +This example shows how to configure the Claude Code module with an AI prompt, API key shared by all users of the template, and other custom settings. |
50 | 40 |
|
51 | 41 | ```tf
|
52 |
| -variable "anthropic_api_key" { |
53 |
| - type = string |
54 |
| - description = "The Anthropic API key" |
55 |
| - sensitive = true |
56 |
| -} |
57 |
| -
|
58 |
| -module "coder-login" { |
59 |
| - count = data.coder_workspace.me.start_count |
60 |
| - source = "registry.coder.com/coder/coder-login/coder" |
61 |
| - version = "1.0.15" |
62 |
| - agent_id = coder_agent.example.id |
63 |
| -} |
64 |
| -
|
65 | 42 | data "coder_parameter" "ai_prompt" {
|
66 | 43 | type = "string"
|
67 | 44 | name = "AI Prompt"
|
68 | 45 | default = ""
|
69 |
| - description = "Write a prompt for Claude Code" |
| 46 | + description = "Initial task prompt for Claude Code." |
70 | 47 | mutable = true
|
71 | 48 | }
|
72 | 49 |
|
73 |
| -# Set the prompt and system prompt for Claude Code via environment variables |
74 |
| -resource "coder_agent" "main" { |
75 |
| - # ... |
76 |
| - env = { |
77 |
| - CODER_MCP_CLAUDE_API_KEY = var.anthropic_api_key # or use a coder_parameter |
78 |
| - CODER_MCP_CLAUDE_TASK_PROMPT = data.coder_parameter.ai_prompt.value |
79 |
| - CODER_MCP_APP_STATUS_SLUG = "claude-code" |
80 |
| - CODER_MCP_CLAUDE_SYSTEM_PROMPT = <<-EOT |
81 |
| - You are a helpful assistant that can help with code. |
82 |
| - EOT |
83 |
| - } |
84 |
| -} |
85 |
| -
|
86 | 50 | module "claude-code" {
|
87 |
| - count = data.coder_workspace.me.start_count |
88 |
| - source = "registry.coder.com/coder/claude-code/coder" |
89 |
| - version = "2.2.1" |
90 |
| - agent_id = coder_agent.example.id |
91 |
| - folder = "/home/coder" |
92 |
| - install_claude_code = true |
93 |
| - claude_code_version = "1.0.40" |
| 51 | + source = "registry.coder.com/coder/claude-code/coder" |
| 52 | + version = "3.0.0" |
| 53 | + agent_id = coder_agent.example.id |
| 54 | + workdir = "/home/coder/project" |
| 55 | +
|
| 56 | + claude_api_key = "xxxx-xxxxx-xxxx" |
| 57 | + # OR |
| 58 | + claude_code_oauth_token = "xxxxx-xxxx-xxxx" |
| 59 | +
|
| 60 | + claude_code_version = "1.0.82" # Pin to a specific version |
| 61 | + agentapi_version = "v0.6.1" |
94 | 62 |
|
95 |
| - # Enable experimental features |
96 |
| - experiment_report_tasks = true |
| 63 | + ai_prompt = data.coder_parameter.ai_prompt.value |
| 64 | + model = "sonnet" |
| 65 | +
|
| 66 | + permission_mode = "plan" |
| 67 | +
|
| 68 | + mcp = <<-EOF |
| 69 | + { |
| 70 | + "mcpServers": { |
| 71 | + "my-custom-tool": { |
| 72 | + "command": "my-tool-server" |
| 73 | + "args": ["--port", "8080"] |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + EOF |
97 | 78 | }
|
98 | 79 | ```
|
99 | 80 |
|
100 |
| -## Run standalone |
| 81 | +### Standalone Mode |
101 | 82 |
|
102 |
| -Run Claude Code as a standalone app in your workspace. This will install Claude Code and run it without any task reporting to the Coder UI. |
| 83 | +Run and configure Claude Code as a standalone CLI in your workspace. |
103 | 84 |
|
104 | 85 | ```tf
|
105 | 86 | module "claude-code" {
|
106 | 87 | source = "registry.coder.com/coder/claude-code/coder"
|
107 |
| - version = "2.2.1" |
| 88 | + version = "3.0.0" |
108 | 89 | agent_id = coder_agent.example.id
|
109 |
| - folder = "/home/coder" |
| 90 | + workdir = "/home/coder" |
110 | 91 | install_claude_code = true
|
111 | 92 | claude_code_version = "latest"
|
| 93 | + report_tasks = false |
| 94 | + cli_app = true |
| 95 | +} |
| 96 | +``` |
| 97 | + |
| 98 | +### Usage with Claude Code Subscription |
112 | 99 |
|
113 |
| - # Icon is not available in Coder v2.20 and below, so we'll use a custom icon URL |
114 |
| - icon = "https://registry.npmmirror.com/@lobehub/icons-static-png/1.24.0/files/dark/claude-color.png" |
| 100 | +```tf |
| 101 | +
|
| 102 | +variable "claude_code_oauth_token" { |
| 103 | + type = string |
| 104 | + description = "Generate one using `claude setup-token` command" |
| 105 | + sensitive = true |
| 106 | + value = "xxxx-xxx-xxxx" |
| 107 | +} |
| 108 | +
|
| 109 | +module "claude-code" { |
| 110 | + source = "registry.coder.com/coder/claude-code/coder" |
| 111 | + version = "3.0.0" |
| 112 | + agent_id = coder_agent.example.id |
| 113 | + workdir = "/home/coder/project" |
| 114 | + claude_code_oauth_token = var.claude_code_oauth_token |
115 | 115 | }
|
116 | 116 | ```
|
117 | 117 |
|
118 | 118 | ## Troubleshooting
|
119 | 119 |
|
120 |
| -The module will create log files in the workspace's `~/.claude-module` directory. If you run into any issues, look at them for more information. |
| 120 | +If you encounter any issues, check the log files in the `~/.claude-module` directory within your workspace for detailed information. |
| 121 | + |
| 122 | +```bash |
| 123 | +# Installation logs |
| 124 | +cat ~/.claude-module/install.log |
| 125 | + |
| 126 | +# Startup logs |
| 127 | +cat ~/.claude-module/agentapi-start.log |
| 128 | + |
| 129 | +# Pre/post install script logs |
| 130 | +cat ~/.claude-module/pre_install.log |
| 131 | +cat ~/.claude-module/post_install.log |
| 132 | +``` |
| 133 | + |
| 134 | +> [!NOTE] |
| 135 | +> To use tasks with Claude Code, you must provide an `anthropic_api_key` or `claude_code_oauth_token`. |
| 136 | +> The `workdir` variable is required and specifies the directory where Claude Code will run. |
| 137 | +
|
| 138 | +## References |
| 139 | + |
| 140 | +- [Claude Code Documentation](https://docs.anthropic.com/en/docs/agents-and-tools/claude-code/overview) |
| 141 | +- [AgentAPI Documentation](https://github.com/coder/agentapi) |
| 142 | +- [Coder AI Agents Guide](https://coder.com/docs/tutorials/ai-agents) |
0 commit comments