Skip to content

Conversation

@35C4n0r
Copy link
Collaborator

@35C4n0r 35C4n0r commented Jan 13, 2026

Description

  • Add support for AI Bridge

Type of Change

  • New module
  • New template
  • Bug fix
  • Feature/enhancement
  • Documentation
  • Other

Module Information

Path: registry/coder/modules/claude-code
New version: v4.5.0
Breaking change: [ ] Yes [ ] No

Testing & Validation

  • Tests pass (bun test)
  • Code formatted (bun fmt)
  • Changes tested locally

Related Issues

Closes: #649

@35C4n0r 35C4n0r marked this pull request as draft January 13, 2026 10:40
@35C4n0r 35C4n0r self-assigned this Jan 13, 2026
@35C4n0r
Copy link
Collaborator Author

35C4n0r commented Jan 13, 2026

wip.

Copy link
Member

@matifali matifali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments, but looks good. Also, what do you think about moving the AI Bridge example a bit higher before Bedrock and Vertex AI examples?

@35C4n0r 35C4n0r marked this pull request as ready for review January 15, 2026 06:08
@DevelopmentCats
Copy link
Contributor

@35C4n0r other than what atif mentioned this looks good to me!

Copy link
Member

@matifali matifali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The coder_ai_task + data.coder_task.me boilerplate appears twice:

  1. In "Usage with Tasks and Advanced Configuration"
  2. In "Usage with tasks and AI Bridge"

Suggestion: Consolidate by showing the tasks pattern once, then have AI Bridge examples just show the enable_aibridge = true addition:

### Usage with Tasks

resource "coder_ai_task" "task" {
  count  = data.coder_workspace.me.start_count
  app_id = module.claude-code.task_app_id
}

data "coder_task" "me" {}

module "claude-code" {
  source    = "registry.coder.com/coder/claude-code/coder"
  version   = "4.5.0"
  agent_id  = coder_agent.main.id
  workdir   = "/home/coder/project"
  ai_prompt = data.coder_task.me.prompt
  
  # Optional: route through AI Bridge
  # enable_aibridge = true
}

Then the AI Bridge section can be simplified to just show standalone usage and reference that tasks work by adding enable_aibridge = true to the above example.

# Conflicts:
#	registry/coder/modules/claude-code/README.md
Copy link
Member

@matifali matifali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some Last few changes and it looks good to me.

@DevelopmentCats
Copy link
Contributor

@35C4n0r You will also need to run bun fmt on this as well

@blinkagent
Copy link
Contributor

blinkagent bot commented Jan 16, 2026

The CI failure in terraform_test_all.sh is caused by main.tftest.hcl referencing the old resource name.

In this PR, the resource was renamed from coder_env.claude_api_key to coder_env.anthropic_api_key in main.tf (line 266), but main.tftest.hcl still references the old name on line 45:

assert {
  condition     = coder_env.claude_api_key[0].value == "test-api-key-123"
  error_message = "Claude API key value should match the input"
}

This needs to be updated to:

assert {
  condition     = coder_env.anthropic_api_key[0].value == "test-api-key-123"
  error_message = "Anthropic API key value should match the input"
}

Since main.tftest.hcl wasn't included in the PR diff, this file needs to be added to the changeset.

@35C4n0r 35C4n0r force-pushed the 35C4n0r/feat-claude-aibridge branch from 23573ee to a9d3304 Compare January 17, 2026 11:58
@35C4n0r 35C4n0r requested a review from matifali January 17, 2026 12:25
```

### Usage with Tasks and Advanced Configuration
### Usage with AI Bridge Configuration
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Usage with AI Bridge Configuration
### Usage with AI Bridge


validation {
condition = !(var.enable_aibridge && length(var.claude_api_key) > 0)
error_message = "claude_api_key cannot be provided when enable_aibridge is true. AI Bridge automatically authenticates the client using their Coder credentials."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
error_message = "claude_api_key cannot be provided when enable_aibridge is true. AI Bridge automatically authenticates the client using their Coder credentials."
error_message = "claude_api_key cannot be provided when enable_aibridge is true. AI Bridge automatically authenticates the client using Coder credentials."


validation {
condition = !(var.enable_aibridge && length(var.claude_code_oauth_token) > 0)
error_message = "claude_code_oauth_token cannot be provided when enable_aibridge is true. AI Bridge automatically authenticates the client using their Coder credentials."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
error_message = "claude_code_oauth_token cannot be provided when enable_aibridge is true. AI Bridge automatically authenticates the client using their Coder credentials."
error_message = "claude_code_oauth_token cannot be provided when enable_aibridge is true. AI Bridge automatically authenticates the client using Coder credentials."

}

# https://code.claude.com/docs/en/settings#environment-variables
resource "coder_env" "anthropic_auth_token" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this as we are writing the API key to the config file?


if [ -z "${CLAUDE_API_KEY:-}" ]; then
echo "Note: CLAUDE_API_KEY not set, skipping authentication setup"
if [ -z "${CLAUDE_API_KEY:-}" ] && [ "$ARG_ENABLE_AIBRIDGE" = "false" ]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep the logic simple here and simply use the key from the AI Bridge. No need to make this conditional on the AI Bridge. This should simply write the key wherever it came from.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds support for AI Bridge to the Claude Code module, enabling centralized LLM proxy management through Coder's AI Bridge feature. This is a Premium Coder feature that allows Claude Code to route API requests through Coder's proxy instead of directly to Anthropic's API.

Changes:

  • Added enable_aibridge variable with validation to prevent conflicts with existing authentication methods
  • Configured environment variables (ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN) when AI Bridge is enabled
  • Updated documentation with usage examples and integration guidance

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
registry/coder/modules/claude-code/main.tf Added enable_aibridge variable with mutual exclusivity validations for claude_api_key and claude_code_oauth_token; added environment variable resources for AI Bridge configuration
registry/coder/modules/claude-code/scripts/install.sh Added ARG_ENABLE_AIBRIDGE parameter handling; modified authentication setup to skip API key requirement when AI Bridge is enabled
registry/coder/modules/claude-code/README.md Updated version to 4.5.0 across all examples; added comprehensive AI Bridge documentation with standalone and tasks usage examples

Comment on lines +231 to +245
variable "enable_aibridge" {
type = bool
description = "Use AI Bridge for Claude Code. https://coder.com/docs/ai-coder/ai-bridge"
default = false

validation {
condition = !(var.enable_aibridge && length(var.claude_api_key) > 0)
error_message = "claude_api_key cannot be provided when enable_aibridge is true. AI Bridge automatically authenticates the client using their Coder credentials."
}

validation {
condition = !(var.enable_aibridge && length(var.claude_code_oauth_token) > 0)
error_message = "claude_code_oauth_token cannot be provided when enable_aibridge is true. AI Bridge automatically authenticates the client using their Coder credentials."
}
}
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new enable_aibridge feature lacks test coverage. Consider adding tests to verify:

  1. That ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN environment variables are set correctly when enable_aibridge is true
  2. That the validation rules preventing claude_api_key and claude_code_oauth_token from being used with enable_aibridge work as expected
  3. That the shell script properly handles the ARG_ENABLE_AIBRIDGE parameter and skips API key setup when aibridge is enabled

Copilot uses AI. Check for mistakes.
printf "ARG_MCP: %s\n" "$ARG_MCP"
printf "ARG_ALLOWED_TOOLS: %s\n" "$ARG_ALLOWED_TOOLS"
printf "ARG_DISALLOWED_TOOLS: %s\n" "$ARG_DISALLOWED_TOOLS"
printf "ARG_ENABLE_AIBRIDGE %s\n" "$ARG_ENABLE_AIBRIDGE"
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing colon after printf format specifier. The line should be:
printf "ARG_ENABLE_AIBRIDGE: %s\n" "$ARG_ENABLE_AIBRIDGE"

This is inconsistent with all other printf statements in the same section (lines 25-34) which include a colon after the variable name.

Suggested change
printf "ARG_ENABLE_AIBRIDGE %s\n" "$ARG_ENABLE_AIBRIDGE"
printf "ARG_ENABLE_AIBRIDGE: %s\n" "$ARG_ENABLE_AIBRIDGE"

Copilot uses AI. Check for mistakes.
if [ -z "${CLAUDE_API_KEY:-}" ]; then
echo "Note: CLAUDE_API_KEY not set, skipping authentication setup"
if [ -z "${CLAUDE_API_KEY:-}" ] && [ "$ARG_ENABLE_AIBRIDGE" = "false" ]; then
echo "Note: CLAUDE_API_KEY or enable_aibridge not set, skipping authentication setup"
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message is misleading. It says "CLAUDE_API_KEY or enable_aibridge not set" but the logic checks if BOTH are not set (API key is empty AND aibridge is false). The message should more accurately reflect this condition, such as: "Note: Neither CLAUDE_API_KEY nor enable_aibridge is set, skipping authentication setup"

Suggested change
echo "Note: CLAUDE_API_KEY or enable_aibridge not set, skipping authentication setup"
echo "Note: Neither CLAUDE_API_KEY nor enable_aibridge is set, skipping authentication setup"

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add AI Bridge Integration to Claude Code Module

4 participants