Skip to content

Commit 54b9737

Browse files
feat: enhance Claude Code installation process with npm check including new node install via nvm if not present
1 parent 65320be commit 54b9737

File tree

1 file changed

+25
-2
lines changed
  • registry/coder/modules/claude-code

1 file changed

+25
-2
lines changed

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

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,32 @@ resource "coder_script" "claude_code" {
135135
136136
# Install Claude Code if enabled
137137
if [ "${var.install_claude_code}" = "true" ]; then
138+
# Check if npm is available, if not try to install Node.js using NVM
138139
if ! command_exists npm; then
139-
echo "Error: npm is not installed. Please install Node.js and npm first."
140-
exit 1
140+
echo "npm not found, checking for Node.js installation..."
141+
if ! command_exists node; then
142+
echo "Node.js not found, installing Node.js via NVM..."
143+
# Install NVM
144+
export NVM_DIR="$HOME/.nvm"
145+
if [ ! -d "$NVM_DIR" ]; then
146+
mkdir -p "$NVM_DIR"
147+
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
148+
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
149+
else
150+
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
151+
fi
152+
153+
# Install Node.js LTS version
154+
nvm install --lts
155+
nvm use --lts
156+
nvm alias default node
157+
158+
echo "Node.js installed: $(node --version)"
159+
echo "npm installed: $(npm --version)"
160+
else
161+
echo "Node.js is installed but npm is not available. Please install npm manually."
162+
exit 1
163+
fi
141164
fi
142165
echo "Installing Claude Code..."
143166
npm install -g @anthropic-ai/claude-code@${var.claude_code_version}

0 commit comments

Comments
 (0)