Skip to content

Commit d212de4

Browse files
35C4n0rDevelopmentCatsmatifali
authored
feat: refactor claude code to use agentapi module (#402)
Closes #302 ## Description <!-- Briefly describe what this PR does and why --> ## Type of Change - [ ] New module - [ ] Bug fix - [x] Feature/enhancement - [ ] Documentation - [ ] Other ## Module Information <!-- Delete this section if not applicable --> **Path:** `registry/[namespace]/modules/[module-name]` **New version:** `v3.0.0` **Breaking change:** [ ] Yes [ ] No ## Testing & Validation - [x] Tests pass (`bun test`) - [x] Code formatted (`bun run fmt`) - [x] Changes tested locally ## Related Issues <!-- Link related issues or write "None" if not applicable --> --------- Co-authored-by: DevCats <[email protected]> Co-authored-by: Atif Ali <[email protected]>
1 parent 54b9bf3 commit d212de4

File tree

12 files changed

+879
-694
lines changed

12 files changed

+879
-694
lines changed
Lines changed: 90 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,142 @@
11
---
22
display_name: Claude Code
3-
description: Run Claude Code in your workspace
3+
description: Run the Claude Code agent in your workspace.
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.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"
2120
}
2221
```
2322

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.
2825
2926
> [!NOTE]
3027
> 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.
3128
3229
## Prerequisites
3330

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)
3734

3835
## Examples
3936

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

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

5141
```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-
6542
data "coder_parameter" "ai_prompt" {
6643
type = "string"
6744
name = "AI Prompt"
6845
default = ""
69-
description = "Write a prompt for Claude Code"
46+
description = "Initial task prompt for Claude Code."
7047
mutable = true
7148
}
7249
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-
8650
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"
9462
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
9778
}
9879
```
9980

100-
## Run standalone
81+
### Standalone Mode
10182

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

10485
```tf
10586
module "claude-code" {
10687
source = "registry.coder.com/coder/claude-code/coder"
107-
version = "2.2.1"
88+
version = "3.0.0"
10889
agent_id = coder_agent.example.id
109-
folder = "/home/coder"
90+
workdir = "/home/coder"
11091
install_claude_code = true
11192
claude_code_version = "latest"
93+
report_tasks = false
94+
cli_app = true
95+
}
96+
```
97+
98+
### Usage with Claude Code Subscription
11299

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
115115
}
116116
```
117117

118118
## Troubleshooting
119119

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

Comments
 (0)