Skip to content

Commit c8441fc

Browse files
feat(claude-code): add subdomain variable and logic (#387)
Closes # ## Description - Introduces `subdomain` variable - Logic for subdomain and base path Tested with and without subdomain to ensure no breaking changes <!-- 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/coder/modules/claude-code` **New version:** `v2.2.0` **Breaking change:** [X] 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 -->
1 parent 62951f1 commit c8441fc

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

registry/coder/modules/claude-code/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Run the [Claude Code](https://docs.anthropic.com/en/docs/agents-and-tools/claude
1313
```tf
1414
module "claude-code" {
1515
source = "registry.coder.com/coder/claude-code/coder"
16-
version = "2.1.0"
16+
version = "2.2.0"
1717
agent_id = coder_agent.example.id
1818
folder = "/home/coder"
1919
install_claude_code = true
@@ -83,7 +83,7 @@ resource "coder_agent" "main" {
8383
module "claude-code" {
8484
count = data.coder_workspace.me.start_count
8585
source = "registry.coder.com/coder/claude-code/coder"
86-
version = "2.1.0"
86+
version = "2.2.0"
8787
agent_id = coder_agent.example.id
8888
folder = "/home/coder"
8989
install_claude_code = true
@@ -101,7 +101,7 @@ Run Claude Code as a standalone app in your workspace. This will install Claude
101101
```tf
102102
module "claude-code" {
103103
source = "registry.coder.com/coder/claude-code/coder"
104-
version = "2.1.0"
104+
version = "2.2.0"
105105
agent_id = coder_agent.example.id
106106
folder = "/home/coder"
107107
install_claude_code = true

registry/coder/modules/claude-code/main.tf

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,13 @@ variable "install_agentapi" {
100100
variable "agentapi_version" {
101101
type = string
102102
description = "The version of AgentAPI to install."
103-
default = "v0.3.0"
103+
default = "v0.3.3"
104+
}
105+
106+
variable "subdomain" {
107+
type = bool
108+
description = "Whether to use a subdomain for the Claude Code app."
109+
default = true
104110
}
105111

106112
locals {
@@ -113,6 +119,15 @@ locals {
113119
agentapi_wait_for_start_script_b64 = base64encode(file("${path.module}/scripts/agentapi-wait-for-start.sh"))
114120
remove_last_session_id_script_b64 = base64encode(file("${path.module}/scripts/remove-last-session-id.sh"))
115121
claude_code_app_slug = "ccw"
122+
// Chat base path is only set if not using a subdomain.
123+
// NOTE:
124+
// - Initial support for --chat-base-path was added in v0.3.1 but configuration
125+
// via environment variable AGENTAPI_CHAT_BASE_PATH was added in v0.3.3.
126+
// - As CODER_WORKSPACE_AGENT_NAME is a recent addition we use agent ID
127+
// for backward compatibility.
128+
agentapi_chat_base_path = var.subdomain ? "" : "/@${data.coder_workspace_owner.me.name}/${data.coder_workspace.me.name}.${var.agent_id}/apps/${local.claude_code_app_slug}/chat"
129+
server_base_path = var.subdomain ? "" : "/@${data.coder_workspace_owner.me.name}/${data.coder_workspace.me.name}.${var.agent_id}/apps/${local.claude_code_app_slug}"
130+
healthcheck_url = "http://localhost:3284${local.server_base_path}/status"
116131
}
117132

118133
# Install and Initialize Claude Code
@@ -229,6 +244,9 @@ resource "coder_script" "claude_code" {
229244
230245
# Disable host header check since AgentAPI is proxied by Coder (which does its own validation)
231246
export AGENTAPI_ALLOWED_HOSTS="*"
247+
248+
# Set chat base path for non-subdomain routing (only set if not using subdomain)
249+
export AGENTAPI_CHAT_BASE_PATH="${local.agentapi_chat_base_path}"
232250
233251
nohup "$module_path/scripts/agentapi-start.sh" use_prompt &> "$module_path/agentapi-start.log" &
234252
"$module_path/scripts/agentapi-wait-for-start.sh"
@@ -245,9 +263,9 @@ resource "coder_app" "claude_code_web" {
245263
icon = var.icon
246264
order = var.order
247265
group = var.group
248-
subdomain = true
266+
subdomain = var.subdomain
249267
healthcheck {
250-
url = "http://localhost:3284/status"
268+
url = local.healthcheck_url
251269
interval = 3
252270
threshold = 20
253271
}

0 commit comments

Comments
 (0)