Skip to content

Commit 1c99c57

Browse files
authored
add agentapi
1 parent a0c1a05 commit 1c99c57

File tree

1 file changed

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

1 file changed

+36
-2
lines changed

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

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ resource "coder_script" "claude_code" {
131131
npm install -g @anthropic-ai/claude-code@${var.claude_code_version}
132132
fi
133133
134+
# Hardcoded for now: install AgentAPI
135+
wget https://github.com/coder/agentapi/releases/download/preview/agentapi-linux-amd64More actions
136+
chmod +x agentapi-linux-amd64
137+
sudo mv agentapi-linux-amd64 /usr/local/bin/agentapi
138+
134139
if [ "${var.experiment_report_tasks}" = "true" ]; then
135140
echo "Configuring Claude Code to report tasks via Coder MCP..."
136141
coder exp mcp configure claude-code ${var.folder}
@@ -166,8 +171,22 @@ resource "coder_script" "claude_code" {
166171
export LANG=en_US.UTF-8
167172
export LC_ALL=en_US.UTF-8
168173
169-
# Create a new tmux session in detached mode
170-
tmux new-session -d -s claude-code -c ${var.folder} "claude --dangerously-skip-permissions \"$CODER_MCP_CLAUDE_TASK_PROMPT\""
174+
tmux new-session -d -s claude-code-agentapi -c ${var.folder} 'agentapi server -- bash -c "claude --dangerously-skip-permissions \"$CODER_MCP_CLAUDE_TASK_PROMPT\" | tee -a \"$HOME/.claude-code.log\""; exec bash'More actions
175+
echo "Waiting for agentapi server to start on port 3284..."
176+
for i in $(seq 1 15); do
177+
if lsof -i :3284 | grep -q 'LISTEN'; then
178+
echo "agentapi server started on port 3284."
179+
break
180+
fi
181+
echo "Waiting... ($i/15)"
182+
sleep 1
183+
done
184+
if ! lsof -i :3284 | grep -q 'LISTEN'; then
185+
echo "Error: agentapi server did not start on port 3284 after 15 seconds."
186+
exit 1
187+
fi
188+
tmux new-session -d -s claude-code -c ${var.folder} "agentapi attach"
189+
171190
172191
fi
173192
@@ -217,6 +236,15 @@ resource "coder_script" "claude_code" {
217236
run_on_start = true
218237
}
219238

239+
resource "coder_app" "claude_code_web" {
240+
slug = "claude-code-web"
241+
display_name = "Claude Code Web"
242+
agent_id = var.agent_id
243+
url = "http://localhost:3284/chat/embed"
244+
icon = var.icon
245+
subdomain = true
246+
}
247+
220248
resource "coder_app" "claude_code" {
221249
slug = "claude-code"
222250
display_name = "Claude Code"
@@ -229,6 +257,12 @@ resource "coder_app" "claude_code" {
229257
export LC_ALL=en_US.UTF-8
230258
231259
if [ "${var.experiment_use_tmux}" = "true" ]; then
260+
261+
if ! tmux has-session -t claude-code-agentapi 2>/dev/null; then
262+
echo "Starting a new Claude Code agentapi tmux session." | tee -a "$HOME/.claude-code.log"
263+
tmux new-session -d -s claude-code-agentapi -c ${var.folder} 'agentapi server -- bash -c "claude --dangerously-skip-permissions | tee -a \"$HOME/.claude-code.log\""; exec bash'
264+
fi
265+
232266
if tmux has-session -t claude-code 2>/dev/null; then
233267
echo "Attaching to existing Claude Code tmux session." | tee -a "$HOME/.claude-code.log"
234268
tmux attach-session -t claude-code

0 commit comments

Comments
 (0)