Skip to content

Commit 8c45c65

Browse files
committed
fix(registry/coder/modules): write bootstrap scripts to module dir instead of /tmp
Bootstrap scripts used fixed /tmp paths with generic names like /tmp/main.sh, making them easy to collide with or accidentally overwrite. Write them into $HOME/<module_dir_name>/scripts/ instead, following the pattern used by the agent-helper module. Also fix install.sh hardcoding port 3284 instead of using ARG_AGENTAPI_PORT. Refs #736
1 parent 6ec506e commit 8c45c65

6 files changed

Lines changed: 44 additions & 25 deletions

File tree

registry/coder/modules/agentapi/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The AgentAPI module is a building block for modules that need to run an AgentAPI
1616
```tf
1717
module "agentapi" {
1818
source = "registry.coder.com/coder/agentapi/coder"
19-
version = "2.1.1"
19+
version = "2.1.2"
2020
2121
agent_id = var.agent_id
2222
web_app_slug = local.app_slug

registry/coder/modules/agentapi/main.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,16 +309,22 @@ describe("agentapi", async () => {
309309
"../scripts/agentapi-shutdown.sh",
310310
);
311311

312+
const shutdownScriptPath = `/home/coder/${moduleDirName}/scripts/agentapi-shutdown.sh`;
313+
await execContainer(containerId, [
314+
"bash",
315+
"-c",
316+
`mkdir -p /home/coder/${moduleDirName}/scripts`,
317+
]);
312318
await writeExecutable({
313319
containerId,
314-
filePath: "/tmp/shutdown.sh",
320+
filePath: shutdownScriptPath,
315321
content: shutdownScript,
316322
});
317323

318324
return await execContainer(containerId, [
319325
"bash",
320326
"-c",
321-
`ARG_TASK_ID=${taskId} ARG_AGENTAPI_PORT=3284 CODER_AGENT_URL=http://localhost:18080 CODER_AGENT_TOKEN=test-token /tmp/shutdown.sh`,
327+
`ARG_TASK_ID=${taskId} ARG_AGENTAPI_PORT=3284 CODER_AGENT_URL=http://localhost:18080 CODER_AGENT_TOKEN=test-token ${shutdownScriptPath}`,
322328
]);
323329
};
324330

registry/coder/modules/agentapi/main.tf

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,10 @@ resource "coder_script" "agentapi" {
193193
set -o errexit
194194
set -o pipefail
195195
196-
echo -n '${base64encode(local.main_script)}' | base64 -d > /tmp/main.sh
197-
chmod +x /tmp/main.sh
196+
SCRIPT_DIR="$HOME/${var.module_dir_name}/scripts"
197+
mkdir -p "$SCRIPT_DIR"
198+
echo -n '${base64encode(local.main_script)}' | base64 -d > "$SCRIPT_DIR/agentapi-main.sh"
199+
chmod +x "$SCRIPT_DIR/agentapi-main.sh"
198200
199201
ARG_MODULE_DIR_NAME='${var.module_dir_name}' \
200202
ARG_WORKDIR="$(echo -n '${base64encode(local.workdir)}' | base64 -d)" \
@@ -209,7 +211,7 @@ resource "coder_script" "agentapi" {
209211
ARG_AGENTAPI_CHAT_BASE_PATH='${local.agentapi_chat_base_path}' \
210212
ARG_TASK_ID='${try(data.coder_task.me.id, "")}' \
211213
ARG_TASK_LOG_SNAPSHOT='${var.task_log_snapshot}' \
212-
/tmp/main.sh
214+
"$SCRIPT_DIR/agentapi-main.sh"
213215
EOT
214216
run_on_start = true
215217
}
@@ -223,13 +225,15 @@ resource "coder_script" "agentapi_shutdown" {
223225
#!/bin/bash
224226
set -o pipefail
225227
226-
echo -n '${base64encode(local.shutdown_script)}' | base64 -d > /tmp/agentapi-shutdown.sh
227-
chmod +x /tmp/agentapi-shutdown.sh
228+
SCRIPT_DIR="$HOME/${var.module_dir_name}/scripts"
229+
mkdir -p "$SCRIPT_DIR"
230+
echo -n '${base64encode(local.shutdown_script)}' | base64 -d > "$SCRIPT_DIR/agentapi-shutdown.sh"
231+
chmod +x "$SCRIPT_DIR/agentapi-shutdown.sh"
228232
229233
ARG_TASK_ID='${try(data.coder_task.me.id, "")}' \
230234
ARG_TASK_LOG_SNAPSHOT='${var.task_log_snapshot}' \
231235
ARG_AGENTAPI_PORT='${var.agentapi_port}' \
232-
/tmp/agentapi-shutdown.sh
236+
"$SCRIPT_DIR/agentapi-shutdown.sh"
233237
EOT
234238
}
235239

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

Lines changed: 9 additions & 9 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 = "4.7.5"
16+
version = "4.7.6"
1717
agent_id = coder_agent.main.id
1818
workdir = "/home/coder/project"
1919
claude_api_key = "xxxx-xxxxx-xxxx"
@@ -47,7 +47,7 @@ By default, when `enable_boundary = true`, the module uses `coder boundary` subc
4747
```tf
4848
module "claude-code" {
4949
source = "registry.coder.com/coder/claude-code/coder"
50-
version = "4.7.5"
50+
version = "4.7.6"
5151
agent_id = coder_agent.main.id
5252
workdir = "/home/coder/project"
5353
enable_boundary = true
@@ -68,7 +68,7 @@ For tasks integration with AI Bridge, add `enable_aibridge = true` to the [Usage
6868
```tf
6969
module "claude-code" {
7070
source = "registry.coder.com/coder/claude-code/coder"
71-
version = "4.7.5"
71+
version = "4.7.6"
7272
agent_id = coder_agent.main.id
7373
workdir = "/home/coder/project"
7474
enable_aibridge = true
@@ -97,7 +97,7 @@ data "coder_task" "me" {}
9797
9898
module "claude-code" {
9999
source = "registry.coder.com/coder/claude-code/coder"
100-
version = "4.7.5"
100+
version = "4.7.6"
101101
agent_id = coder_agent.main.id
102102
workdir = "/home/coder/project"
103103
ai_prompt = data.coder_task.me.prompt
@@ -120,7 +120,7 @@ This example shows additional configuration options for version pinning, custom
120120
```tf
121121
module "claude-code" {
122122
source = "registry.coder.com/coder/claude-code/coder"
123-
version = "4.7.5"
123+
version = "4.7.6"
124124
agent_id = coder_agent.main.id
125125
workdir = "/home/coder/project"
126126
@@ -176,7 +176,7 @@ Run and configure Claude Code as a standalone CLI in your workspace.
176176
```tf
177177
module "claude-code" {
178178
source = "registry.coder.com/coder/claude-code/coder"
179-
version = "4.7.5"
179+
version = "4.7.6"
180180
agent_id = coder_agent.main.id
181181
workdir = "/home/coder/project"
182182
install_claude_code = true
@@ -198,7 +198,7 @@ variable "claude_code_oauth_token" {
198198
199199
module "claude-code" {
200200
source = "registry.coder.com/coder/claude-code/coder"
201-
version = "4.7.5"
201+
version = "4.7.6"
202202
agent_id = coder_agent.main.id
203203
workdir = "/home/coder/project"
204204
claude_code_oauth_token = var.claude_code_oauth_token
@@ -271,7 +271,7 @@ resource "coder_env" "bedrock_api_key" {
271271
272272
module "claude-code" {
273273
source = "registry.coder.com/coder/claude-code/coder"
274-
version = "4.7.5"
274+
version = "4.7.6"
275275
agent_id = coder_agent.main.id
276276
workdir = "/home/coder/project"
277277
model = "global.anthropic.claude-sonnet-4-5-20250929-v1:0"
@@ -328,7 +328,7 @@ resource "coder_env" "google_application_credentials" {
328328
329329
module "claude-code" {
330330
source = "registry.coder.com/coder/claude-code/coder"
331-
version = "4.7.5"
331+
version = "4.7.6"
332332
agent_id = coder_agent.main.id
333333
workdir = "/home/coder/project"
334334
model = "claude-sonnet-4@20250514"

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ locals {
318318
install_script = file("${path.module}/scripts/install.sh")
319319
start_script = file("${path.module}/scripts/start.sh")
320320
module_dir_name = ".claude-module"
321+
agentapi_port = 3284
321322
# Extract hostname from access_url for boundary --allow flag
322323
coder_host = replace(replace(data.coder_workspace.me.access_url, "https://", ""), "http://", "")
323324
claude_api_key = var.enable_aibridge ? data.coder_workspace_owner.me.session_token : var.claude_api_key
@@ -378,8 +379,11 @@ module "agentapi" {
378379
#!/bin/bash
379380
set -o errexit
380381
set -o pipefail
381-
echo -n '${base64encode(local.start_script)}' | base64 -d > /tmp/start.sh
382-
chmod +x /tmp/start.sh
382+
383+
SCRIPT_DIR="$HOME/${local.module_dir_name}/scripts"
384+
mkdir -p "$SCRIPT_DIR"
385+
echo -n '${base64encode(local.start_script)}' | base64 -d > "$SCRIPT_DIR/claude-code-start.sh"
386+
chmod +x "$SCRIPT_DIR/claude-code-start.sh"
383387
384388
ARG_RESUME_SESSION_ID='${var.resume_session_id}' \
385389
ARG_CONTINUE='${var.continue}' \
@@ -394,16 +398,18 @@ module "agentapi" {
394398
ARG_USE_BOUNDARY_DIRECTLY='${var.use_boundary_directly}' \
395399
ARG_CODER_HOST='${local.coder_host}' \
396400
ARG_CLAUDE_BINARY_PATH='${var.claude_binary_path}' \
397-
/tmp/start.sh
401+
"$SCRIPT_DIR/claude-code-start.sh"
398402
EOT
399403

400404
install_script = <<-EOT
401405
#!/bin/bash
402406
set -o errexit
403407
set -o pipefail
404408
405-
echo -n '${base64encode(local.install_script)}' | base64 -d > /tmp/install.sh
406-
chmod +x /tmp/install.sh
409+
SCRIPT_DIR="$HOME/${local.module_dir_name}/scripts"
410+
mkdir -p "$SCRIPT_DIR"
411+
echo -n '${base64encode(local.install_script)}' | base64 -d > "$SCRIPT_DIR/claude-code-install.sh"
412+
chmod +x "$SCRIPT_DIR/claude-code-install.sh"
407413
ARG_CLAUDE_CODE_VERSION='${var.claude_code_version}' \
408414
ARG_MCP_APP_STATUS_SLUG='${local.app_slug}' \
409415
ARG_INSTALL_CLAUDE_CODE='${var.install_claude_code}' \
@@ -416,7 +422,8 @@ module "agentapi" {
416422
ARG_MCP='${var.mcp != null ? base64encode(replace(var.mcp, "'", "'\\''")) : ""}' \
417423
ARG_MCP_CONFIG_REMOTE_PATH='${base64encode(jsonencode(var.mcp_config_remote_path))}' \
418424
ARG_ENABLE_AIBRIDGE='${var.enable_aibridge}' \
419-
/tmp/install.sh
425+
ARG_AGENTAPI_PORT='${local.agentapi_port}' \
426+
"$SCRIPT_DIR/claude-code-install.sh"
420427
EOT
421428
}
422429

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ ARG_CLAUDE_BINARY_PATH="${ARG_CLAUDE_BINARY_PATH//\$HOME/$HOME}"
1717
ARG_INSTALL_VIA_NPM=${ARG_INSTALL_VIA_NPM:-false}
1818
ARG_REPORT_TASKS=${ARG_REPORT_TASKS:-true}
1919
ARG_MCP_APP_STATUS_SLUG=${ARG_MCP_APP_STATUS_SLUG:-}
20+
ARG_AGENTAPI_PORT=${ARG_AGENTAPI_PORT:-3284}
2021
ARG_MCP=$(echo -n "${ARG_MCP:-}" | base64 -d)
2122
ARG_MCP_CONFIG_REMOTE_PATH=$(echo -n "${ARG_MCP_CONFIG_REMOTE_PATH:-}" | base64 -d)
2223
ARG_ALLOWED_TOOLS=${ARG_ALLOWED_TOOLS:-}
@@ -34,6 +35,7 @@ printf "ARG_CLAUDE_BINARY_PATH: %s\n" "$ARG_CLAUDE_BINARY_PATH"
3435
printf "ARG_INSTALL_VIA_NPM: %s\n" "$ARG_INSTALL_VIA_NPM"
3536
printf "ARG_REPORT_TASKS: %s\n" "$ARG_REPORT_TASKS"
3637
printf "ARG_MCP_APP_STATUS_SLUG: %s\n" "$ARG_MCP_APP_STATUS_SLUG"
38+
printf "ARG_AGENTAPI_PORT: %s\n" "$ARG_AGENTAPI_PORT"
3739
printf "ARG_MCP: %s\n" "$ARG_MCP"
3840
printf "ARG_MCP_CONFIG_REMOTE_PATH: %s\n" "$ARG_MCP_CONFIG_REMOTE_PATH"
3941
printf "ARG_ALLOWED_TOOLS: %s\n" "$ARG_ALLOWED_TOOLS"
@@ -228,7 +230,7 @@ function report_tasks() {
228230
if [ "$ARG_REPORT_TASKS" = "true" ]; then
229231
echo "Configuring Claude Code to report tasks via Coder MCP..."
230232
export CODER_MCP_APP_STATUS_SLUG="$ARG_MCP_APP_STATUS_SLUG"
231-
export CODER_MCP_AI_AGENTAPI_URL="http://localhost:3284"
233+
export CODER_MCP_AI_AGENTAPI_URL="http://localhost:${ARG_AGENTAPI_PORT:-3284}"
232234
coder exp mcp configure claude-code "$ARG_WORKDIR"
233235
else
234236
configure_standalone_mode

0 commit comments

Comments
 (0)