Skip to content

Commit 36cebbd

Browse files
committed
feat: refactor claude code to use agentapi module
1 parent 97b036e commit 36cebbd

File tree

12 files changed

+797
-644
lines changed

12 files changed

+797
-644
lines changed
Lines changed: 81 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,133 @@
11
---
22
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.
44
icon: ../../../../.icons/claude.svg
55
verified: true
6-
tags: [agent, claude-code, ai, tasks]
6+
tags: [agent, claude-code, ai, tasks, anthropic]
77
---
88

99
# Claude Code
1010

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.
1212

1313
```tf
1414
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"
2119
}
2220
```
2321

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.
2824
2925
## Prerequisites
3026

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).
3429

3530
## Examples
3631

37-
### Run in the background and report tasks (Experimental)
32+
### Usage with Tasks and Advanced Configuration
3833

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.
4735

4836
```tf
4937
variable "anthropic_api_key" {
5038
type = string
51-
description = "The Anthropic API key"
39+
description = "The Anthropic API key."
5240
sensitive = true
5341
}
5442
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" {
6344
type = "string"
64-
name = "AI Prompt"
45+
name = "AI Task Prompt"
6546
default = ""
66-
description = "Write a prompt for Claude Code"
47+
description = "Initial task prompt for Claude Code."
6748
mutable = true
6849
}
6950
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
8156
}
8257
8358
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
9490
}
9591
```
9692

97-
## Run standalone
93+
### Standalone Mode
9894

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.
10096

10197
```tf
10298
module "claude-code" {
10399
source = "registry.coder.com/coder/claude-code/coder"
104-
version = "2.1.0"
100+
version = "3.0.0"
105101
agent_id = coder_agent.example.id
106-
folder = "/home/coder"
102+
workdir = "/home/coder"
107103
install_claude_code = true
108104
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
112107
}
113108
```
114109

115110
## Troubleshooting
116111

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

Comments
 (0)