8000 agentapi 0.2.2, screen support · coder/registry@677318c · GitHub
[go: up one dir, main page]

Skip to content

Commit 677318c

Browse files
committed
agentapi 0.2.2, screen support
1 parent 1916bad commit 677318c

File tree

1 file changed

+50
-9
lines changed
  • registry/coder/modules/claude-code

1 file changed

+50
-9
lines changed

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

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ terraform {
44
required_providers {
55
coder = {
66
source = "coder/coder"
7+
version = ">= 2.7.0"
78
}
89
}
910
}
@@ -53,6 +54,18 @@ variable "claude_code_version" {
5354
default = "latest"
5455
}
5556

57+
variable "install_agentapi" {
58+
type = bool
59+
description = "Whether to install AgentAPI."
60+
default = true
61+
}
62+
63+
variable "agentapi_version" {
64+
type = string
65+
description = "The version of AgentAPI to install."
66+
default = "v0.2.2"
67+
}
68+
5669
variable "experiment_use_screen" {
5770
type = bool
5871
description = "Whether to use screen for running Claude Code in the background."
@@ -86,6 +99,15 @@ variable "experiment_post_install_script" {
8699
locals {
87100
encoded_pre_install_script = var.experiment_pre_install_script != null ? base64encode(var.experiment_pre_install_script) : ""
88101
encoded_post_install_script = var.experiment_post_install_script != null ? base64encode(var.experiment_post_install_script) : ""
102+
agentapi_start_command = <<-EOT
103+
#!/bin/bash
104+
set -e
105+
106+
# use low width to fit in the tasks UI sidebar. height is adjusted to ~match the default 80k (80x1000) characters
107+
# visible in the terminal screen.
108+
agentapi server --term-width 67 --term-height 1190 -- bash -c "claude --dangerously-skip-permissions \"$(cat ~/.claude-code-prompt)\""
109+
EOT
110+
agentapi_start_command_base64 = base64encode(local.agentapi_start_command)
89111
}
90112

91113
# Install and Initialize Claude Code
@@ -130,10 +152,31 @@ resource "coder_script" "claude_code" {
130152
npm install -g @anthropic-ai/claude-code@${var.claude_code_version}
131153
fi
132154
133-
# Hardcoded for now: install AgentAPI
134-
wget https://github.com/coder/agentapi/releases/download/preview/agentapi-linux-amd64
135-
chmod +x agentapi-linux-amd64
136-
sudo mv agentapi-linux-amd64 /usr/local/bin/agentapi
155+
# Install AgentAPI if enabled
156+
if [ "${var.install_agentapi}" = "true" ]; then
157+
echo "Installing AgentAPI..."
158+
arch=$(uname -m)
159+
if [ "$arch" = "x86_64" ]; then
160+
binary_name="agentapi-linux-amd64"
161+
elif [ "$arch" = "aarch64" ]; then
162+
binary_name="agentapi-linux-arm64"
163+
else
164+
echo "Error: Unsupported architecture: $arch"
165+
exit 1
166+
fi
167+
wget "https://github.com/coder/agentapi/releases/download/${var.agentapi_version}/$binary_name"
168+
chmod +x "$binary_name"
169+
sudo mv "$binary_name" /usr/local/bin/agentapi
170+
fi
171+
172+
if ! command_exists agentapi; then
173+
echo "Error: AgentAPI is not installed. Please enable install_agentapi or install it manually."
174+
exit 1
175+
fi
176+
177+
echo -n "$CODER_MCP_CLAUDE_TASK_PROMPT" > ~/.claude-code-prompt
178+
echo -n "${local.agentapi_start_command_base64}" | base64 -d > ~/.agentapi-start-command
179+
chmod +x ~/.agentapi-start-command
137180
138181
if [ "${var.experiment_report_tasks}" = "true" ]; then
139182
echo "Configuring Claude Code to report tasks via Coder MCP..."
@@ -172,7 +215,7 @@ resource "coder_script" "claude_code" {
172215
173216
# use low width to fit in the tasks UI sidebar. height is adjusted to ~match the default 80k (80x1000) characters
174217
# visible in the terminal screen.
175-
tmux new-session -d -s claude-code-agentapi -c ${var.folder} 'agentapi server --term-width 67 --term-height 1190 -- bash -c "claude --dangerously-skip-permissions \"$CODER_MCP_CLAUDE_TASK_PROMPT\""; exec bash'
218+
tmux new-session -d -s claude-code-agentapi -c ${var.folder} '~/.agentapi-start-command; exec bash'
176219
echo "Waiting for agentapi server to start on port 3284..."
177220
for i in $(seq 1 15); do
178221
if lsof -i :3284 | grep -q 'LISTEN'; then
@@ -223,7 +266,7 @@ resource "coder_script" "claude_code" {
223266
224267
screen -U -dmS claude-code bash -c '
225268
cd ${var.folder}
226-
claude --dangerously-skip-permissions "$CODER_MCP_CLAUDE_TASK_PROMPT" | tee -a "$HOME/.claude-code.log"
269+
~/.agentapi-start-command
227270
exec bash
228271
'
229272
else
@@ -266,9 +309,7 @@ resource "coder_app" "claude_code" {
266309
267310
if ! tmux has-session -t claude-code-agentapi 2>/dev/null; then
268311
echo "Starting a new Claude Code agentapi tmux session." | tee -a "$HOME/.claude-code.log"
269-
# use low width to fit in the tasks UI sidebar. height is adjusted to ~match the default 80k (80x1000) characters
270-
# visible in the terminal screen.
271-
tmux new-session -d -s claude-code-agentapi -c ${var.folder} 'agentapi server --term-width 67 --term-height 1190 -- bash -c "claude --dangerously-skip-permissions"; exec bash'
312+
tmux new-session -d -s claude-code-agentapi -c ${var.folder} '~/.agentapi-start-command; exec bash'
272313
fi
273314
274315
if tmux has-session -t claude-code 2>/dev/null; then

0 commit comments

Comments
 (0)
0