Skip to content

Commit a85436f

Browse files
chore(claude-code): use $HOME variable instead of hardcoded path and remove symlink (#592)
## Description - Remove hardcoded `/home/coder` path. - Remove symlink in favour of coder_env "PATH". ## Type of Change - [ ] New module - [ ] New template - [x] Bug fix - [ ] Feature/enhancement - [ ] Documentation - [ ] Other ## Module Information **Path:** `registry/[coder/modules/claude-code` **New version:** `v4.2.7` **Breaking change:** [ ] Yes [x] No ## Testing & Validation - [x] Tests pass (`bun test`) - [x] Code formatted (`bun fmt`) - [ ] Changes tested locally ## Related Issues <!-- Link related issues or write "None" if not applicable --> --------- Signed-off-by: 35C4n0r <work.jaykumar@gmail.com> Co-authored-by: DevelopmentCats <christofer@coder.com>
1 parent aa4890f commit a85436f

File tree

5 files changed

+25
-35
lines changed

5 files changed

+25
-35
lines changed

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

Lines changed: 8 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.2.6"
16+
version = "4.2.7"
1717
agent_id = coder_agent.main.id
1818
workdir = "/home/coder/project"
1919
claude_api_key = "xxxx-xxxxx-xxxx"
@@ -45,7 +45,7 @@ This example shows how to configure the Claude Code module to run the agent behi
4545
```tf
4646
module "claude-code" {
4747
source = "dev.registry.coder.com/coder/claude-code/coder"
48-
version = "4.2.6"
48+
version = "4.2.7"
4949
agent_id = coder_agent.main.id
5050
workdir = "/home/coder/project"
5151
enable_boundary = true
@@ -72,7 +72,7 @@ data "coder_parameter" "ai_prompt" {
7272
7373
module "claude-code" {
7474
source = "registry.coder.com/coder/claude-code/coder"
75-
version = "4.2.6"
75+
version = "4.2.7"
7676
agent_id = coder_agent.main.id
7777
workdir = "/home/coder/project"
7878
@@ -92,10 +92,9 @@ module "claude-code" {
9292
{
9393
"mcpServers": {
9494
"my-custom-tool": {
95-
"command": "my-tool-server"
95+
"command": "my-tool-server",
9696
"args": ["--port", "8080"]
9797
}
98-
9998
}
10099
}
101100
EOF
@@ -109,7 +108,7 @@ Run and configure Claude Code as a standalone CLI in your workspace.
109108
```tf
110109
module "claude-code" {
111110
source = "registry.coder.com/coder/claude-code/coder"
112-
version = "4.2.6"
111+
version = "4.2.7"
113112
agent_id = coder_agent.main.id
114113
workdir = "/home/coder/project"
115114
install_claude_code = true
@@ -131,7 +130,7 @@ variable "claude_code_oauth_token" {
131130
132131
module "claude-code" {
133132
source = "registry.coder.com/coder/claude-code/coder"
134-
version = "4.2.6"
133+
version = "4.2.7"
135134
agent_id = coder_agent.main.id
136135
workdir = "/home/coder/project"
137136
claude_code_oauth_token = var.claude_code_oauth_token
@@ -204,7 +203,7 @@ resource "coder_env" "bedrock_api_key" {
204203
205204
module "claude-code" {
206205
source = "registry.coder.com/coder/claude-code/coder"
207-
version = "4.2.6"
206+
version = "4.2.7"
208207
agent_id = coder_agent.main.id
209208
workdir = "/home/coder/project"
210209
model = "global.anthropic.claude-sonnet-4-5-20250929-v1:0"
@@ -261,7 +260,7 @@ resource "coder_env" "google_application_credentials" {
261260
262261
module "claude-code" {
263262
source = "registry.coder.com/coder/claude-code/coder"
264-
version = "4.2.6"
263+
version = "4.2.7"
265264
agent_id = coder_agent.main.id
266265
workdir = "/home/coder/project"
267266
model = "claude-sonnet-4@20250514"

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ interface SetupProps {
3939
agentapiMockScript?: string;
4040
}
4141

42-
const setup = async (props?: SetupProps): Promise<{ id: string }> => {
42+
const setup = async (
43+
props?: SetupProps,
44+
): Promise<{ id: string; coderEnvVars: Record<string, string> }> => {
4345
const projectDir = "/home/coder/project";
44-
const { id } = await setupUtil({
46+
const { id, coderEnvVars } = await setupUtil({
4547
moduleDir: import.meta.dir,
4648
moduleVariables: {
4749
install_claude_code: props?.skipClaudeMock ? "true" : "false",
@@ -61,7 +63,7 @@ const setup = async (props?: SetupProps): Promise<{ id: string }> => {
6163
content: await loadTestFile(import.meta.dir, "claude-mock.sh"),
6264
});
6365
}
64-
return { id };
66+
return { id, coderEnvVars };
6567
};
6668

6769
setDefaultTimeout(60 * 1000);
@@ -79,14 +81,14 @@ describe("claude-code", async () => {
7981

8082
test("install-claude-code-version", async () => {
8183
const version_to_install = "1.0.40";
82-
const { id } = await setup({
84+
const { id, coderEnvVars } = await setup({
8385
skipClaudeMock: true,
8486
moduleVariables: {
8587
install_claude_code: "true",
8688
claude_code_version: version_to_install,
8789
},
8890
});
89-
await execModuleScript(id);
91+
await execModuleScript(id, coderEnvVars);
9092
const resp = await execContainer(id, [
9193
"bash",
9294
"-c",
@@ -96,14 +98,14 @@ describe("claude-code", async () => {
9698
});
9799

98100
test("check-latest-claude-code-version-works", async () => {
99-
const { id } = await setup({
101+
const { id, coderEnvVars } = await setup({
100102
skipClaudeMock: true,
101103
skipAgentAPIMock: true,
102104
moduleVariables: {
103105
install_claude_code: "true",
104106
},
105107
});
106-
await execModuleScript(id);
108+
await execModuleScript(id, coderEnvVars);
107109
await expectAgentAPIStarted(id);
108110
});
109111

@@ -133,13 +135,13 @@ describe("claude-code", async () => {
133135
},
134136
},
135137
});
136-
const { id } = await setup({
138+
const { id, coderEnvVars } = await setup({
137139
skipClaudeMock: true,
138140
moduleVariables: {
139141
mcp: mcpConfig,
140142
},
141143
});
142-
await execModuleScript(id);
144+
await execModuleScript(id, coderEnvVars);
143145

144146
const resp = await readFileContainer(id, "/home/coder/.claude.json");
145147
expect(resp).toContain("test-cmd");

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,12 @@ resource "coder_env" "disable_autoupdater" {
288288
value = "1"
289289
}
290290

291+
resource "coder_env" "claude_binary_path" {
292+
agent_id = var.agent_id
293+
name = "PATH"
294+
value = "$HOME/.local/bin:$PATH"
295+
}
296+
291297
locals {
292298
# we have to trim the slash because otherwise coder exp mcp will
293299
# set up an invalid claude config

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
#!/bin/bash
22

3-
if [ -f "$HOME/.bashrc" ]; then
4-
source "$HOME"/.bashrc
5-
fi
6-
7-
# Set strict error handling AFTER sourcing bashrc to avoid unbound variable errors from user dotfiles
83
set -euo pipefail
94

105
BOLD='\033[0;1m'
@@ -45,11 +40,6 @@ function install_claude_code_cli() {
4540
if [ $CURL_EXIT -ne 0 ]; then
4641
echo "Claude Code installer failed with exit code $$CURL_EXIT"
4742
fi
48-
49-
# Ensure binaries are discoverable.
50-
echo "Creating a symlink for claude"
51-
sudo ln -s /home/coder/.local/bin/claude /usr/local/bin/claude
52-
5343
echo "Installed Claude Code successfully. Version: $(claude --version || echo 'unknown')"
5444
else
5545
echo "Skipping Claude Code installation as per configuration."

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
#!/bin/bash
22

3-
if [ -f "$HOME/.bashrc" ]; then
4-
source "$HOME"/.bashrc
5-
fi
6-
7-
# Set strict error handling AFTER sourcing bashrc to avoid unbound variable errors from user dotfiles
83
set -euo pipefail
94

10-
export PATH="$HOME/.local/bin:$PATH"
11-
125
command_exists() {
136
command -v "$1" > /dev/null 2>&1
147
}

0 commit comments

Comments
 (0)