Skip to content

Feat/claude code subagents #274

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
24 changes: 19 additions & 5 deletions registry/coder-labs/modules/gemini/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ tags: [agent, gemini, ai, google, tasks]

# Gemini CLI

Run [Gemini CLI](https://ai.google.dev/gemini-api/docs/cli) in your workspace to access Google's Gemini AI models, and custom pre/post install scripts. This module integrates with [AgentAPI](https://github.com/coder/agentapi) for Coder Tasks compatibility.
Run [Gemini CLI](https://ai.google.com/docs/gemini/tools/cli) in your workspace to access Google's Gemini AI models, and custom pre/post install scripts. This module integrates with [AgentAPI](https://github.com/coder/agentapi) for Coder Tasks compatibility.

## Getting Started

1. **Get a Gemini API Key**:
- Visit [Google AI Studio](https://makersuite.google.com/app/apikey)
- Create a new API key or use an existing one
- The API key starts with "AIza..."

```tf
module "gemini" {
Expand Down Expand Up @@ -44,10 +51,13 @@ module "gemini" {
source = "registry.coder.com/coder-labs/gemini/coder"
version = "1.0.0"
agent_id = coder_agent.example.id
gemini_api_key = var.gemini_api_key # we recommend providing this parameter inorder to have a smoother experience (i.e. no google sign-in)
gemini_api_key = var.gemini_api_key # Required for automated setup
gemini_model = "gemini-2.5-flash"
install_gemini = true
gemini_version = "latest"
install_gemini = true
gemini_version = "latest"
auto_approve = true # Automatically approve API key usage
yolo_mode = true # Enable faster responses without confirmations
folder = "/home/coder/project" # Custom working directory
gemini_instruction_prompt = "Start every response with `Gemini says:`"
}
```
Expand All @@ -64,7 +74,11 @@ module "gemini" {
- If Gemini CLI is not found, ensure `install_gemini = true` and your API key is valid
- Node.js and npm are installed automatically if missing (using NVM)
- Check logs in `/home/coder/.gemini-module/` for install/start output
- We highly recommend using the `gemini_api_key` variable, this also ensures smooth tasks running without needing to sign in to Google.
- We highly recommend using the `gemini_api_key` variable, this also ensures smooth tasks running without needing to sign in to Google
- If experiencing prompts for approval or confirmation:
- Set `auto_approve = true` to automatically approve API key usage
- Set `yolo_mode = true` to enable faster responses without confirmation prompts
- These settings are configured in `~/.gemini/settings.json` automatically

> [!IMPORTANT]
> To use tasks with Gemini CLI, ensure you have the `gemini_api_key` variable set, and **you pass the `AI Prompt` Parameter**.
Expand Down
14 changes: 13 additions & 1 deletion registry/coder-labs/modules/gemini/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ variable "group" {
variable "icon" {
type = string
description = "The icon to use for the app."
default = "/icon/gemini.svg"
default = "../../../../.icons/gemini.svg"
}

variable "folder" {
Expand All @@ -42,6 +42,18 @@ variable "folder" {
default = "/home/coder"
}

variable "auto_approve" {
type = bool
description = "Whether to automatically approve Gemini API key usage."
default = true
}

variable "yolo_mode" {
type = bool
description = "Whether to enable YOLO mode for faster responses without confirmation prompts."
default = true
}

variable "install_gemini" {
type = bool
description = "Whether to install Gemini."
Expand Down
8 changes: 6 additions & 2 deletions registry/coder-labs/modules/gemini/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,12 @@ function append_extensions_to_settings_json() {
'.mcpServers = (.mcpServers // {} + $base + $add)' \
"$SETTINGS_PATH" > "$TMP_SETTINGS" && mv "$TMP_SETTINGS" "$SETTINGS_PATH"

# Add theme and selectedAuthType fields
jq '.theme = "Default" | .selectedAuthType = "gemini-api-key"' "$SETTINGS_PATH" > "$TMP_SETTINGS" && mv "$TMP_SETTINGS" "$SETTINGS_PATH"
# Add theme, selectedAuthType, and Gemini settings
jq '.theme = "Default" |
.selectedAuthType = "gemini-api-key" |
.autoApproveApiKey = true |
.geminicodeassist.agentYoloMode = true |
.geminicodeassist.autoConfirm = true' "$SETTINGS_PATH" > "$TMP_SETTINGS" && mv "$TMP_SETTINGS" "$SETTINGS_PATH"

printf "[append_extensions_to_settings_json] Merge complete.\n"
}
Expand Down
15 changes: 15 additions & 0 deletions registry/coder/modules/claude-code/install.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
resource "coder_script" "install_claude_code" {
agent_id = var.agent_id
display_name = "Install Claude Code"
icon = var.icon
script = file("${path.module}/scripts/install.sh")
run_on_start = true

env = {
ARG_ENABLE_SUBAGENTS = tostring(var.enable_subagents)
ARG_SUBAGENTS_VERSION = var.subagents_version
ARG_CUSTOM_SUBAGENTS_PATH = var.custom_subagents_path
ARG_ENABLED_SUBAGENTS = jsonencode(var.enabled_subagents)
ARG_DEFAULT_SUBAGENT_MODEL = var.default_subagent_model
}
}
30 changes: 30 additions & 0 deletions registry/coder/modules/claude-code/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,36 @@ variable "install_claude_code" {
default = true
}

variable "enable_subagents" {
type = bool
description = "Whether to enable Claude Code subagents for specialized tasks."
default = false
}

variable "subagents_version" {
type = string
description = "The version of subagents to install. Set to 'latest' for the most recent version."
default = "latest"
}

variable "custom_subagents_path" {
type = string
description = "Path to custom subagents directory. If not set, will use the default agents from wshobson/agents."
default = ""
}

variable "enabled_subagents" {
type = list(string)
description = "List of subagents to enable. If empty, all subagents will be enabled when enable_subagents is true."
default = []
}

variable "default_subagent_model" {
type = string
description = "Default Claude model to use for subagents that don't specify a model. Options: claude-3-5-haiku-20241022, claude-sonnet-4-20250514, claude-opus-4-20250514"
default = "claude-sonnet-4-20250514"
}

variable "claude_code_version" {
type = string
description = "The version of Claude Code to install."
Expand Down
61 changes: 61 additions & 0 deletions registry/coder/modules/claude-code/scripts/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash

set -euo pipefail

BOLD='\033[0;1m'

# Parse arguments
ARG_ENABLE_SUBAGENTS="${ARG_ENABLE_SUBAGENTS:-false}"
ARG_SUBAGENTS_VERSION="${ARG_SUBAGENTS_VERSION:-latest}"
ARG_CUSTOM_SUBAGENTS_PATH="${ARG_CUSTOM_SUBAGENTS_PATH:-}"
ARG_ENABLED_SUBAGENTS="${ARG_ENABLED_SUBAGENTS:-}"
ARG_DEFAULT_SUBAGENT_MODEL="${ARG_DEFAULT_SUBAGENT_MODEL:-claude-sonnet-4-20250514}"

# Create Claude config directory
CLAUDE_DIR="$HOME/.claude"
mkdir -p "$CLAUDE_DIR"

# Install subagents if enabled
if [ "$ARG_ENABLE_SUBAGENTS" = "true" ]; then
printf "%s Installing Claude Code subagents...\n" "${BOLD}"

if [ -n "$ARG_CUSTOM_SUBAGENTS_PATH" ]; then
# Use custom subagents path
printf "Using custom subagents from: %s\n" "$ARG_CUSTOM_SUBAGENTS_PATH"
mkdir -p "$CLAUDE_DIR/agents"
cp -r "$ARG_CUSTOM_SUBAGENTS_PATH"/* "$CLAUDE_DIR/agents/"
else
# Clone the default agents repository
AGENTS_DIR="$CLAUDE_DIR/agents"
if [ ! -d "$AGENTS_DIR" ]; then
git clone https://github.com/wshobson/agents.git "$AGENTS_DIR"
fi
cd "$AGENTS_DIR"

if [ "$ARG_SUBAGENTS_VERSION" = "latest" ]; then
git pull origin main
else
git checkout "$ARG_SUBAGENTS_VERSION"
fi
fi

# Configure enabled subagents
if [ -n "$ARG_ENABLED_SUBAGENTS" ]; then
printf "Configuring enabled subagents: %s\n" "$ARG_ENABLED_SUBAGENTS"
mkdir -p "$CLAUDE_DIR/config"
echo "{\"enabledAgents\": $ARG_ENABLED_SUBAGENTS, \"defaultModel\": \"$ARG_DEFAULT_SUBAGENT_MODEL\"}" > "$CLAUDE_DIR/config/agents.json"
fi

printf "%s Claude Code subagents installed successfully\n" "${BOLD}"
fi

# Install Claude Code
printf "%s Installing Claude Code...\n" "${BOLD}"
if command -v npm &> /dev/null; then
npm install -g @anthropic/claude-code
else
echo "npm not found. Please install Node.js and npm first."
exit 1
fi

printf "%s Claude Code installation complete\n" "${BOLD}"