Skip to content

Query agentapi for claude-code status #136

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: claude-code-web
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions registry/coder/modules/claude-code/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ variable "experiment_report_tasks" {
default = false
}

variable "experiment_report_tasks_interval" {
type = number
description = "How often to poll task status in seconds, or zero to disable."
default = 0
}

variable "experiment_pre_install_script" {
type = string
description = "Custom script to run before installing Claude Code."
Expand Down Expand Up @@ -247,6 +253,40 @@ resource "coder_app" "claude_code_web" {
subdomain = true
}

resource "coder_script" "task_reporter" {
agent_id = var.agent_id
display_name = "Task reporter"
icon = var.icon
command = <<-EOT
#!/bin/bash
set -e
if [ -z "${var.experiment_report_tasks_interval}" ] ;
echo "Task polling is not enabled"
exit 0
fi
if [ "${var.experiment_report_tasks_interval}" = "0" ] ;
echo "Task polling is not enabled"
exit 0
fi
echo "Waiting for agentapi server to start on port 3284..."
for i in $(seq 1 15); do
if lsof -i :3284 | grep -q 'LISTEN'; then
echo "agentapi server started on port 3284."
break
fi
echo "Waiting... ($i/15)"
sleep 1
done
if ! lsof -i :3284 | grep -q 'LISTEN'; then
echo "Error: agentapi server did not start on port 3284 after 15 seconds."
exit 1
fi
echo "Running status poller in the background..."
coder exp task report-status --agentapi-url "http://localhost:3284" &
EOT
run_on_start = true
}

resource "coder_app" "claude_code" {
slug = "claude-code"
display_name = "Claude Code"
Expand Down