You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
11
+
Install and configure the [Claude Code](https://docs.anthropic.com/en/docs/agents-and-tools/claude-code/overview)CLI in your workspace. Starting Claude is left to the caller (template command, IDE launcher, or a custom `coder_script`).
> **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.
25
-
26
-
> [!NOTE]
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.
28
-
29
23
## Prerequisites
30
24
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)
34
-
35
-
### Session Resumption Behavior
25
+
Provide exactly one authentication method:
36
26
37
-
By default, Claude Code automatically resumes existing conversations when your workspace restarts. Sessions are tracked per workspace directory, so conversations continue where you left off. If no session exists (first start), your `ai_prompt` will run normally. To disable this behavior and always start fresh, set `continue = false`
27
+
-**Anthropic API key**: get one from the [Anthropic Console](https://console.anthropic.com/dashboard) and pass it as `anthropic_api_key`.
28
+
-**Claude.ai OAuth token** (Pro, Max, or Enterprise accounts): generate one by running `claude setup-token` locally and pass it as `claude_code_oauth_token`.
29
+
-**Coder AI Gateway** (Coder Premium, Coder >= 2.30.0): set `enable_ai_gateway = true`. The module authenticates against the gateway using the workspace owner's session token. Do not combine with `anthropic_api_key` or `claude_code_oauth_token`.
38
30
39
-
## State Persistence
31
+
## Examples
40
32
41
-
AgentAPI can save and restore its conversation state to disk across workspace restarts. This complements `continue` (which resumes the Claude CLI session) by also preserving the AgentAPI-level context. Enabled by default, requires agentapi >= v0.12.0 (older versions skip it with a warning).
33
+
### Standalone mode with a launcher app
42
34
43
-
To disable:
35
+
Authenticate Claude directly against Anthropic's API and add a `coder_app` that users can click from the workspace dashboard to open an interactive Claude session.
44
36
45
37
```tf
46
-
module "claude-code" {
47
-
# ... other config
48
-
enable_state_persistence = false
38
+
locals {
39
+
claude_workdir = "/home/coder/project"
49
40
}
50
-
```
51
-
52
-
## Examples
53
-
54
-
### Usage with Agent Boundaries
55
-
56
-
This example shows how to configure the Claude Code module to run the agent behind a process-level boundary that restricts its network access.
57
41
58
-
By default, when `enable_boundary = true`, the module uses `coder boundary` subcommand (provided by Coder) without requiring any installation.
> For developers: The module also supports installing boundary from a release version (`use_boundary_directly = true`) or compiling from source (`compile_boundary_from_source = true`). These are escape hatches for development and testing purposes.
66
+
> `coder_app.command` runs when the user clicks the app tile. Combine with `anthropic_api_key`, `claude_code_oauth_token`, or `enable_ai_gateway = true` on the module to pre-authenticate the CLI.
72
67
73
-
### Usage with AI Bridge
68
+
### Usage with AI Gateway
74
69
75
-
[AI Bridge](https://coder.com/docs/ai-coder/ai-bridge) is a Premium Coder feature that provides centralized LLM proxy management. To use AI Bridge, set `enable_aibridge = true`. Requires Coder version >= 2.29.0.
76
-
77
-
For tasks integration with AI Bridge, add `enable_aibridge = true` to the [Usage with Tasks](#usage-with-tasks) example below.
78
-
79
-
#### Standalone usage with AI Bridge
70
+
[AI Gateway](https://coder.com/docs/ai-coder/ai-gateway) is a Premium Coder feature that provides centralized LLM proxy management. Requires Coder >= 2.30.0.
# Optional: route through AI Bridge (Premium feature)
119
-
# enable_aibridge = true
120
-
}
121
-
```
89
+
> [!CAUTION]
90
+
> `enable_ai_gateway = true` is mutually exclusive with `anthropic_api_key` and `claude_code_oauth_token`. Setting any of them together fails at plan time.
122
91
123
92
### Advanced Configuration
124
93
125
-
This example shows additional configuration options for version pinning, custom models, and MCP servers.
126
-
127
-
> [!NOTE]
128
-
> The `claude_binary_path` variable can be used to specify where a pre-installed Claude binary is located.
94
+
This example shows version pinning, a pre-installed binary path, a custom model, and MCP servers.
129
95
130
96
> [!WARNING]
131
-
> **Deprecation Notice**: The npm installation method (`install_via_npm = true`) will be deprecated and removed in the next major release. Please use the default binary installation method instead.
97
+
> **Deprecation notice**: `install_via_npm = true` will be removed in the next major release. Prefer the default binary installer.
claude_code_version = "2.0.62" # Pin to a specific Claude CLI version.
143
109
144
-
claude_code_version = "2.0.62" # Pin to a specific version
145
-
claude_binary_path = "/opt/claude/bin" # Path to pre-installed Claude binary
146
-
agentapi_version = "0.11.4"
110
+
# Skip the module's installer and point at a pre-installed Claude binary.
111
+
# claude_binary_path can only be customized when install_claude_code is false.
112
+
install_claude_code = false
113
+
claude_binary_path = "/opt/claude/bin"
147
114
148
-
model = "sonnet"
149
-
permission_mode = "plan"
115
+
model = "sonnet"
150
116
151
117
mcp = <<-EOF
152
118
{
@@ -166,6 +132,9 @@ module "claude-code" {
166
132
}
167
133
```
168
134
135
+
> [!NOTE]
136
+
> Swap `anthropic_api_key` for `claude_code_oauth_token = "xxxxx-xxxx-xxxx"` to authenticate via a Claude.ai OAuth token instead. Pass exactly one.
137
+
169
138
> [!NOTE]
170
139
> Remote URLs should return a JSON body in the following format:
171
140
>
@@ -180,41 +149,37 @@ module "claude-code" {
180
149
> }
181
150
> ```
182
151
>
183
-
> The `Content-Type` header doesn't matter—both `text/plain` and `application/json` work fine.
152
+
> The `Content-Type` header doesn't matter, both `text/plain` and `application/json` work fine.
153
+
154
+
### Serialize a downstream `coder_script` after the install pipeline
184
155
185
-
### Standalone Mode
156
+
The module exposes the `coder exp sync` name of each script it creates via the `scripts` output: an ordered list (`pre_install`, `install`, `post_install`) of names for scripts this module actually creates. Scripts that were not configured are absent from the list.
186
157
187
-
Run and configure Claude Code as a standalone CLI in your workspace.
158
+
Downstream `coder_script` resources can wait for this module's install pipeline to finish using `coder exp sync want <self> <each name>`:
0 commit comments