|
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 to generate code and perform tasks. |
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.1.0" |
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" |
21 | 19 | } |
22 | 20 | ``` |
23 | 21 |
|
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. |
| 22 | +> [!WARNING] |
| 23 | +> **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 | 24 |
|
29 | 25 | ## Prerequisites |
30 | 26 |
|
31 | | -- You must add the [Coder Login](https://registry.coder.com/modules/coder-login) module to your template |
32 | | - |
33 | | -The `codercom/oss-dogfood:latest` container image can be used for testing on container-based workspaces. |
| 27 | +- You must add the [Coder Login](https://registry.coder.com/modules/coder-login) module to your template for task reporting features. |
| 28 | +- An **Anthropic API key** is required for tasks. You can get one from the [Anthropic Console](https://console.anthropic.com/dashboard). |
34 | 29 |
|
35 | 30 | ## Examples |
36 | 31 |
|
37 | | -### Run in the background and report tasks (Experimental) |
| 32 | +### Usage with Tasks and Advanced Configuration |
38 | 33 |
|
39 | | -> This functionality is in early access as of Coder v2.21 and is still evolving. |
40 | | -> For now, we recommend testing it in a demo or staging environment, |
41 | | -> rather than deploying to production |
42 | | -> |
43 | | -> Learn more in [the Coder documentation](https://coder.com/docs/tutorials/ai-agents) |
44 | | -> |
45 | | -> Join our [Discord channel](https://discord.gg/coder) or |
46 | | -> [contact us](https://coder.com/contact) to get help or share feedback. |
| 34 | +This example shows how to configure the Claude Code module with a task prompt, API key, and other custom settings. |
47 | 35 |
|
48 | 36 | ```tf |
49 | 37 | variable "anthropic_api_key" { |
50 | 38 | type = string |
51 | | - description = "The Anthropic API key" |
| 39 | + description = "The Anthropic API key." |
52 | 40 | sensitive = true |
53 | 41 | } |
54 | 42 |
|
55 | | -module "coder-login" { |
56 | | - count = data.coder_workspace.me.start_count |
57 | | - source = "registry.coder.com/coder/coder-login/coder" |
58 | | - version = "1.0.15" |
59 | | - agent_id = coder_agent.example.id |
60 | | -} |
61 | | -
|
62 | | -data "coder_parameter" "ai_prompt" { |
| 43 | +data "coder_parameter" "task_prompt" { |
63 | 44 | type = "string" |
64 | | - name = "AI Prompt" |
| 45 | + name = "AI Task Prompt" |
65 | 46 | default = "" |
66 | | - description = "Write a prompt for Claude Code" |
| 47 | + description = "Initial task prompt for Claude Code." |
67 | 48 | mutable = true |
68 | 49 | } |
69 | 50 |
|
70 | | -# Set the prompt and system prompt for Claude Code via environment variables |
71 | | -resource "coder_agent" "main" { |
72 | | - # ... |
73 | | - env = { |
74 | | - CODER_MCP_CLAUDE_API_KEY = var.anthropic_api_key # or use a coder_parameter |
75 | | - CODER_MCP_CLAUDE_TASK_PROMPT = data.coder_parameter.ai_prompt.value |
76 | | - CODER_MCP_APP_STATUS_SLUG = "claude-code" |
77 | | - CODER_MCP_CLAUDE_SYSTEM_PROMPT = <<-EOT |
78 | | - You are a helpful assistant that can help with code. |
79 | | - EOT |
80 | | - } |
| 51 | +module "coder-login" { |
| 52 | + count = data.coder_workspace.me.start_count |
| 53 | + source = "registry.coder.com/coder/coder-login/coder" |
| 54 | + version = "1.0.31" # Use a recent version |
| 55 | + agent_id = coder_agent.example.id |
81 | 56 | } |
82 | 57 |
|
83 | 58 | module "claude-code" { |
84 | | - count = data.coder_workspace.me.start_count |
85 | | - source = "registry.coder.com/coder/claude-code/coder" |
86 | | - version = "2.1.0" |
87 | | - agent_id = coder_agent.example.id |
88 | | - folder = "/home/coder" |
89 | | - install_claude_code = true |
90 | | - claude_code_version = "1.0.40" |
91 | | -
|
92 | | - # Enable experimental features |
93 | | - experiment_report_tasks = true |
| 59 | + source = "registry.coder.com/coder/claude-code/coder" |
| 60 | + version = "3.0.0" |
| 61 | + agent_id = coder_agent.example.id |
| 62 | + workdir = "/home/coder/project" |
| 63 | +
|
| 64 | + # --- Authentication --- |
| 65 | + claude_api_key = var.anthropic_api_key # required for tasks |
| 66 | +
|
| 67 | + # --- Versioning --- |
| 68 | + claude_code_version = "1.0.82" # Pin to a specific version |
| 69 | + agentapi_version = "v0.6.1" |
| 70 | +
|
| 71 | + # --- Task Configuration --- |
| 72 | + task_prompt = data.coder_parameter.task_prompt.value |
| 73 | + continue = true # will fail in a new workspace with no conversation/session to continue |
| 74 | + model = "sonnet" |
| 75 | +
|
| 76 | + # --- Permissions & Tools --- |
| 77 | + permission_mode = "plan" |
| 78 | +
|
| 79 | + # --- MCP Configuration --- |
| 80 | + mcp =<<-EOF |
| 81 | + { |
| 82 | + "mcpServers": { |
| 83 | + "my-custom-tool": { |
| 84 | + "command": "my-tool-server" |
| 85 | + "args": ["--port", "8080"] |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | + EOF |
94 | 90 | } |
95 | 91 | ``` |
96 | 92 |
|
97 | | -## Run standalone |
| 93 | +### Standalone Mode |
98 | 94 |
|
99 | | -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. |
| 95 | +Run Claude Code as a standalone CLI in your workspace without task reporting to the Coder UI. |
100 | 96 |
|
101 | 97 | ```tf |
102 | 98 | module "claude-code" { |
103 | 99 | source = "registry.coder.com/coder/claude-code/coder" |
104 | | - version = "2.1.0" |
| 100 | + version = "3.0.0" |
105 | 101 | agent_id = coder_agent.example.id |
106 | | - folder = "/home/coder" |
| 102 | + workdir = "/home/coder" |
107 | 103 | install_claude_code = true |
108 | 104 | claude_code_version = "latest" |
109 | | -
|
110 | | - # Icon is not available in Coder v2.20 and below, so we'll use a custom icon URL |
111 | | - icon = "https://registry.npmmirror.com/@lobehub/icons-static-png/1.24.0/files/dark/claude-color.png" |
| 105 | + report_tasks = false |
| 106 | + cli_app = true |
112 | 107 | } |
113 | 108 | ``` |
114 | 109 |
|
115 | 110 | ## Troubleshooting |
116 | 111 |
|
117 | | -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. |
| 112 | +If you encounter any issues, check the log files in the `~/.claude-module` directory within your workspace for detailed information. |
| 113 | + |
| 114 | +```bash |
| 115 | +# Installation logs |
| 116 | +cat ~/.claude-module/install.log |
| 117 | + |
| 118 | +# Startup logs |
| 119 | +cat ~/.claude-module/agentapi-start.log |
| 120 | + |
| 121 | +# Pre/post install script logs |
| 122 | +cat ~/.claude-module/pre_install.log |
| 123 | +cat ~/.claude-module/post_install.log |
| 124 | +``` |
| 125 | + |
| 126 | +> [!NOTE] |
| 127 | +> To use tasks with Claude Code, you must provide an `anthropic_api_key`. It's recommended to use a `coder_parameter` for the `task_prompt` to allow users to input tasks from the Coder UI. The `workdir` variable is required and specifies the directory where Claude Code will run. |
| 128 | +
|
| 129 | +## References |
| 130 | + |
| 131 | +- [Claude Code Documentation](https://docs.anthropic.com/en/docs/agents-and-tools/claude-code/overview) |
| 132 | +- [AgentAPI Documentation](https://github.com/coder/agentapi) |
| 133 | +- [Coder AI Agents Guide](https://coder.com/docs/tutorials/ai-agents) |
0 commit comments