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 -->
This commit is contained in:
DevCats 2025-08-26 20:36:27 -05:00 committed by GitHub
parent 62951f1fca
commit c8441fc593
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 6 deletions

View File

@ -13,7 +13,7 @@ Run the [Claude Code](https://docs.anthropic.com/en/docs/agents-and-tools/claude
```tf ```tf
module "claude-code" { module "claude-code" {
source = "registry.coder.com/coder/claude-code/coder" source = "registry.coder.com/coder/claude-code/coder"
version = "2.1.0" version = "2.2.0"
agent_id = coder_agent.example.id agent_id = coder_agent.example.id
folder = "/home/coder" folder = "/home/coder"
install_claude_code = true install_claude_code = true
@ -83,7 +83,7 @@ resource "coder_agent" "main" {
module "claude-code" { module "claude-code" {
count = data.coder_workspace.me.start_count count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/claude-code/coder" source = "registry.coder.com/coder/claude-code/coder"
version = "2.1.0" version = "2.2.0"
agent_id = coder_agent.example.id agent_id = coder_agent.example.id
folder = "/home/coder" folder = "/home/coder"
install_claude_code = true install_claude_code = true
@ -101,7 +101,7 @@ Run Claude Code as a standalone app in your workspace. This will install Claude
```tf ```tf
module "claude-code" { module "claude-code" {
source = "registry.coder.com/coder/claude-code/coder" source = "registry.coder.com/coder/claude-code/coder"
version = "2.1.0" version = "2.2.0"
agent_id = coder_agent.example.id agent_id = coder_agent.example.id
folder = "/home/coder" folder = "/home/coder"
install_claude_code = true install_claude_code = true

View File

@ -100,7 +100,13 @@ variable "install_agentapi" {
variable "agentapi_version" { variable "agentapi_version" {
type = string type = string
description = "The version of AgentAPI to install." description = "The version of AgentAPI to install."
default = "v0.3.0" default = "v0.3.3"
}
variable "subdomain" {
type = bool
description = "Whether to use a subdomain for the Claude Code app."
default = true
} }
locals { locals {
@ -113,6 +119,15 @@ locals {
agentapi_wait_for_start_script_b64 = base64encode(file("${path.module}/scripts/agentapi-wait-for-start.sh")) agentapi_wait_for_start_script_b64 = base64encode(file("${path.module}/scripts/agentapi-wait-for-start.sh"))
remove_last_session_id_script_b64 = base64encode(file("${path.module}/scripts/remove-last-session-id.sh")) remove_last_session_id_script_b64 = base64encode(file("${path.module}/scripts/remove-last-session-id.sh"))
claude_code_app_slug = "ccw" claude_code_app_slug = "ccw"
// Chat base path is only set if not using a subdomain.
// NOTE:
// - Initial support for --chat-base-path was added in v0.3.1 but configuration
// via environment variable AGENTAPI_CHAT_BASE_PATH was added in v0.3.3.
// - As CODER_WORKSPACE_AGENT_NAME is a recent addition we use agent ID
// for backward compatibility.
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"
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}"
healthcheck_url = "http://localhost:3284${local.server_base_path}/status"
} }
# Install and Initialize Claude Code # Install and Initialize Claude Code
@ -229,6 +244,9 @@ resource "coder_script" "claude_code" {
# Disable host header check since AgentAPI is proxied by Coder (which does its own validation) # Disable host header check since AgentAPI is proxied by Coder (which does its own validation)
export AGENTAPI_ALLOWED_HOSTS="*" export AGENTAPI_ALLOWED_HOSTS="*"
# Set chat base path for non-subdomain routing (only set if not using subdomain)
export AGENTAPI_CHAT_BASE_PATH="${local.agentapi_chat_base_path}"
nohup "$module_path/scripts/agentapi-start.sh" use_prompt &> "$module_path/agentapi-start.log" & nohup "$module_path/scripts/agentapi-start.sh" use_prompt &> "$module_path/agentapi-start.log" &
"$module_path/scripts/agentapi-wait-for-start.sh" "$module_path/scripts/agentapi-wait-for-start.sh"
@ -245,9 +263,9 @@ resource "coder_app" "claude_code_web" {
icon = var.icon icon = var.icon
order = var.order order = var.order
group = var.group group = var.group
subdomain = true subdomain = var.subdomain
healthcheck { healthcheck {
url = "http://localhost:3284/status" url = local.healthcheck_url
interval = 3 interval = 3
threshold = 20 threshold = 20
} }