@@ -38,6 +38,7 @@ locals {
38
38
repo_base_dir = data. coder_parameter . repo_base_dir . value == " ~" ? " /home/coder" : replace (data. coder_parameter . repo_base_dir . value , " /^~\\ //" , " /home/coder/" )
39
39
repo_dir = replace (try (module. git-clone [0 ]. repo_dir , " " ), " /^~\\ //" , " /home/coder/" )
40
40
container_name = " coder-${ data . coder_workspace_owner . me . name } -${ lower (data. coder_workspace . me . name )} "
41
+ has_ai_prompt = data. coder_parameter . ai_prompt . value != " "
41
42
}
42
43
43
44
data "coder_workspace_preset" "cpt" {
@@ -150,6 +151,13 @@ data "coder_parameter" "image_type" {
150
151
}
151
152
}
152
153
154
+ variable "anthropic_api_key" {
155
+ type = string
156
+ description = " The API key used to authenticate with the Anthropic API."
157
+ default = " "
158
+ sensitive = true
159
+ }
160
+
153
161
locals {
154
162
default_regions = {
155
163
// keys should match group names
@@ -242,6 +250,14 @@ data "coder_parameter" "devcontainer_autostart" {
242
250
mutable = true
243
251
}
244
252
253
+ data "coder_parameter" "ai_prompt" {
254
+ type = " string"
255
+ name = " AI Prompt"
256
+ default = " "
257
+ description = " Prompt for Claude Code"
258
+ mutable = false
259
+ }
260
+
245
261
provider "docker" {
246
262
host = lookup (local. docker_host , data. coder_parameter . region . value )
247
263
}
@@ -380,6 +396,25 @@ module "devcontainers-cli" {
380
396
agent_id = coder_agent. dev . id
381
397
}
382
398
399
+ module "claude-code" {
400
+ count = local. has_ai_prompt ? data. coder_workspace . me . start_count : 0
401
+ source = " dev.registry.coder.com/coder/claude-code/coder"
402
+ version = " ~>2.0"
403
+ agent_id = coder_agent. dev . id
404
+ folder = local. repo_dir
405
+ install_claude_code = true
406
+ claude_code_version = " latest"
407
+ order = 999
408
+
409
+ experiment_report_tasks = true
410
+ # TODO(Cian): Add post-install script to set up required MCP servers:
411
+ # - desktop-commander
412
+ # - playwright
413
+ # experiment_post_install_script = <<-EOT
414
+ # EOT
415
+ }
416
+
417
+
383
418
resource "coder_agent" "dev" {
384
419
arch = " amd64"
385
420
os = " linux"
@@ -710,4 +745,67 @@ resource "coder_metadata" "container_info" {
710
745
key = " region"
711
746
value = data. coder_parameter . region . option [index (data. coder_parameter . region . option . * . value , data. coder_parameter . region . value )]. name
712
747
}
748
+ item {
749
+ key = " ai_task"
750
+ value = local. has_ai_prompt ? " yes" : " no"
751
+ }
752
+ }
753
+
754
+ resource "coder_env" "claude_system_prompt" {
755
+ count = local. has_ai_prompt ? data. coder_workspace . me . start_count : 0
756
+ agent_id = coder_agent. dev . id
757
+ name = " CODER_MCP_CLAUDE_SYSTEM_PROMPT"
758
+ value = <<- EOT
759
+ <system>
760
+ -- Framing --
761
+ You are a helpful Coding assistant. Aim to autonomously investigate
762
+ and solve issues the user gives you and test your work, whenever possible.
763
+
764
+ Avoid shortcuts like mocking tests. When you get stuck, you can ask the user
765
+ but opt for autonomy.
766
+
767
+ -- Tool Selection --
768
+ - coder_report_task: providing status updates or requesting user input.
769
+ - Built-in tools - use for everything else:
770
+ (file operations, git commands, builds & installs, one-off shell commands)
771
+
772
+ -- Task Reporting --
773
+ Report all tasks to Coder, following these EXACT guidelines:
774
+ 1. Be granular. If you are investigating with multiple steps, report each step
775
+ to coder.
776
+ 2. IMMEDIATELY report status after receiving ANY user message
777
+ 3. Use "state": "working" when actively processing WITHOUT needing
778
+ additional user input
779
+ 4. Use "state": "complete" only when finished with a task
780
+ 5. Use "state": "failure" when you need ANY user input, lack sufficient
781
+ details, or encounter blockers
782
+
783
+ In your summary:
784
+ - Be specific about what you're doing
785
+ - Clearly indicate what information you need from the user when in
786
+ "failure" state
787
+ - Keep it under 160 characters
788
+ - Make it actionable
789
+
790
+ -- Context --
791
+ There is an existing application in the current directory.
792
+ Be sure to read CLAUDE.md before making any changes.
793
+
794
+ This is a real-world production application. As such, make sure to think carefully, use TODO lists, and plan carefully before making changes.
795
+ </system>
796
+ EOT
797
+ }
798
+
799
+ resource "coder_env" "claude_task_prompt" {
800
+ count = local. has_ai_prompt ? data. coder_workspace . me . start_count : 0
801
+ agent_id = coder_agent. dev . id
802
+ name = " CODER_MCP_CLAUDE_TASK_PROMPT"
803
+ value = data. coder_parameter . ai_prompt . value
804
+ }
805
+
806
+ resource "coder_env" "anthropic_api_key" {
807
+ count = local. has_ai_prompt ? data. coder_workspace . me . start_count : 0
808
+ agent_id = coder_agent. dev . id
809
+ name = " ANTHROPIC_API_KEY"
810
+ value = var. anthropic_api_key
713
811
}
0 commit comments