diff --git a/docs/ai-coder/tasks.md b/docs/ai-coder/tasks.md index ef47a6b3fb8..38349b2ae8a 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 } ```