Skip to content

Commit c9bd6d0

Browse files
committed
refactor(registry/coder/modules/claude-code): render install script via templatefile
Render scripts/install.sh.tftpl once at plan time and pass the result directly to coder-utils, replacing the runtime base64 encode/decode wrapper and the redundant scripts/install.sh. Sources coder-utils from a pinned commit on its refactor branch until the `module_directory`-derived caller name lands in a tagged release.
1 parent 5112588 commit c9bd6d0

5 files changed

Lines changed: 217 additions & 227 deletions

File tree

registry/coder/modules/claude-code/main.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ describe("claude-code", async () => {
300300
},
301301
});
302302
await runScripts(id, scripts);
303-
// install.sh echoes ARG_WORKDIR and creates the directory if missing.
303+
// install.sh.tftpl echoes ARG_WORKDIR and creates the directory if missing.
304304
const installLog = await readFileContainer(
305305
id,
306306
"/home/coder/.coder-modules/coder/claude-code/logs/install.log",

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

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ variable "model" {
7373

7474
variable "mcp" {
7575
type = string
76-
description = "MCP JSON to be added to the claude code local scope"
76+
description = "JSON-encoded string to configure MCP servers for Claude Code. When set, writes MCP configuration into the Claude Code local scope."
7777
default = ""
7878
}
7979

@@ -163,38 +163,30 @@ resource "coder_env" "anthropic_base_url" {
163163
}
164164

165165
locals {
166-
workdir = trimsuffix(var.workdir, "/")
167-
install_script = file("${path.module}/scripts/install.sh")
166+
workdir = trimsuffix(var.workdir, "/")
167+
install_script = templatefile("${path.module}/scripts/install.sh.tftpl", {
168+
ARG_CLAUDE_CODE_VERSION = var.claude_code_version
169+
ARG_INSTALL_CLAUDE_CODE = tostring(var.install_claude_code)
170+
ARG_CLAUDE_BINARY_PATH = var.claude_binary_path
171+
ARG_WORKDIR = local.workdir
172+
ARG_MCP = var.mcp != "" ? base64encode(var.mcp) : ""
173+
ARG_MCP_CONFIG_REMOTE_PATH = base64encode(jsonencode(var.mcp_config_remote_path))
174+
ARG_ENABLE_AI_GATEWAY = tostring(var.enable_ai_gateway)
175+
})
168176
module_dir_name = ".coder-modules/coder/claude-code"
169177
}
170178

171179
module "coder_utils" {
172180
source = "registry.coder.com/coder/coder-utils/coder"
173-
version = "1.3.0"
181+
version = "0.0.1"
174182

175183
agent_id = var.agent_id
176-
agent_name = "claude-code"
177184
module_directory = "$HOME/${local.module_dir_name}"
178185
display_name_prefix = "Claude Code"
179186
icon = var.icon
180187
pre_install_script = var.pre_install_script
181188
post_install_script = var.post_install_script
182-
install_script = <<-EOT
183-
#!/bin/bash
184-
set -o errexit
185-
set -o pipefail
186-
187-
echo -n '${base64encode(local.install_script)}' | base64 -d > /tmp/install.sh
188-
chmod +x /tmp/install.sh
189-
ARG_CLAUDE_CODE_VERSION='${var.claude_code_version}' \
190-
ARG_INSTALL_CLAUDE_CODE='${var.install_claude_code}' \
191-
ARG_CLAUDE_BINARY_PATH='${var.claude_binary_path}' \
192-
ARG_WORKDIR='${local.workdir}' \
193-
ARG_MCP='${var.mcp != null ? base64encode(replace(var.mcp, "'", "'\\''")) : ""}' \
194-
ARG_MCP_CONFIG_REMOTE_PATH='${base64encode(jsonencode(var.mcp_config_remote_path))}' \
195-
ARG_ENABLE_AI_GATEWAY='${var.enable_ai_gateway}' \
196-
/tmp/install.sh
197-
EOT
189+
install_script = local.install_script
198190
}
199191

200192
# Pass-through of coder-utils script outputs so upstream modules can serialize

registry/coder/modules/claude-code/main.tftest.hcl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ run "test_script_outputs_install_only" {
250250
}
251251

252252
assert {
253-
condition = length(output.scripts) == 1 && output.scripts[0] == "claude-code-install_script"
253+
condition = length(output.scripts) == 1 && output.scripts[0] == "coder-claude-code-install_script"
254254
error_message = "scripts output should list only the install script when pre/post are not configured"
255255
}
256256
}
@@ -266,7 +266,7 @@ run "test_script_outputs_with_pre_and_post" {
266266
}
267267

268268
assert {
269-
condition = output.scripts == ["claude-code-pre_install_script", "claude-code-install_script", "claude-code-post_install_script"]
269+
condition = output.scripts == ["coder-claude-code-pre_install_script", "coder-claude-code-install_script", "coder-claude-code-post_install_script"]
270270
error_message = "scripts output should list pre_install, install, post_install in run order"
271271
}
272272
}

registry/coder/modules/claude-code/scripts/install.sh

Lines changed: 0 additions & 203 deletions
This file was deleted.

0 commit comments

Comments
 (0)