From ea718084ff29d312df3df2414bb3c0dc862a314c Mon Sep 17 00:00:00 2001 From: david-fraley <67079030+david-fraley@users.noreply.github.com> Date: Tue, 16 Sep 2025 15:27:57 -0500 Subject: [PATCH] docs: update Tasks Template Code (#19770) --- docs/ai-coder/tasks.md | 49 +++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/docs/ai-coder/tasks.md b/docs/ai-coder/tasks.md index ef47a6b3fb..38349b2ae8 100644 --- a/docs/ai-coder/tasks.md +++ b/docs/ai-coder/tasks.md @@ -46,7 +46,7 @@ To import the template and begin configuring it, follow the [documentation in th ### Option 2) Create or Duplicate Your Own Template -A template becomes a Task template if it defines a `coder_ai_task` resource and a `coder_parameter` named `"AI Prompt"`. Coder analyzes template files during template version import to determine if these requirements are met. +A template becomes a Task template if it defines a `coder_ai_task` resource and a `coder_parameter` named `"AI Prompt"`. Coder analyzes template files during template version import to determine if these requirements are met. Try adding this terraform block to an existing template where you'll add our Claude Code module. Note: the `coder_ai_task` resource is defined within the [Claude Code Module](https://registry.coder.com/modules/coder/claude-code?tab=readme), so it's not defined within this block. ```hcl data "coder_parameter" "ai_prompt" { @@ -54,16 +54,45 @@ data "coder_parameter" "ai_prompt" { type = "string" } -# Multiple coder_ai_tasks can be defined in a template -resource "coder_ai_task" "claude-code" { - # At most one coder ai task can be instantiated during a workspace build. - # Coder fails the build if it would instantiate more than 1. - count = data.coder_parameter.ai_prompt.value != "" ? 1 : 0 +data "coder_parameter" "setup_script" { + name = "setup_script" + display_name = "Setup Script" + type = "string" + form_type = "textarea" + description = "Script to run before running the agent" + mutable = false + default = "" +} - sidebar_app { - # which app to display in the sidebar on the task page - id = coder_app.claude-code.id - } +# The Claude Code module does the automatic task reporting +# Other agent modules: https://registry.coder.com/modules?search=agent +# Or use a custom agent: +module "claude-code" { + count = data.coder_workspace.me.start_count + source = "registry.coder.com/coder/claude-code/coder" + version = "2.2.0" + agent_id = coder_agent.main.id + folder = "/home/coder/projects" + install_claude_code = true + claude_code_version = "latest" + order = 999 + + # experiment_post_install_script = data.coder_parameter.setup_script.value + + # This enables Coder Tasks + experiment_report_tasks = true +} + +variable "anthropic_api_key" { + type = string + description = "Generate one at: https://console.anthropic.com/settings/keys" + sensitive = true +} + +resource "coder_env" "anthropic_api_key" { + agent_id = coder_agent.main.id + name = "CODER_MCP_CLAUDE_API_KEY" + value = var.anthropic_api_key } ```