-
Notifications
You must be signed in to change notification settings - Fork 92
feat(coder/modules/claude-code): add support for aibridge #657
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
base: main
Are you sure you want to change the base?
Conversation
|
wip. |
There was a problem hiding this 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?
# Conflicts: # registry/coder/modules/claude-code/README.md # registry/coder/modules/claude-code/main.test.ts
|
@35C4n0r other than what atif mentioned this looks good to me! |
There was a problem hiding this 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:
- In "Usage with Tasks and Advanced Configuration"
- 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
matifali
left a comment
There was a problem hiding this 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.
|
@35C4n0r You will also need to run |
|
The CI failure in In this PR, the resource was renamed from 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 |
23573ee to
a9d3304
Compare
| ``` | ||
|
|
||
| ### Usage with Tasks and Advanced Configuration | ||
| ### Usage with AI Bridge Configuration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ### 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." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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" { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this 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_aibridgevariable with validation to prevent conflicts with existing authentication methods - Configured environment variables (
ANTHROPIC_BASE_URLandANTHROPIC_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 |
| 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." | ||
| } | ||
| } |
Copilot
AI
Jan 18, 2026
There was a problem hiding this comment.
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:
- That ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN environment variables are set correctly when enable_aibridge is true
- That the validation rules preventing claude_api_key and claude_code_oauth_token from being used with enable_aibridge work as expected
- That the shell script properly handles the ARG_ENABLE_AIBRIDGE parameter and skips API key setup when aibridge is enabled
| 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" |
Copilot
AI
Jan 18, 2026
There was a problem hiding this comment.
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.
| printf "ARG_ENABLE_AIBRIDGE %s\n" "$ARG_ENABLE_AIBRIDGE" | |
| printf "ARG_ENABLE_AIBRIDGE: %s\n" "$ARG_ENABLE_AIBRIDGE" |
| 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" |
Copilot
AI
Jan 18, 2026
There was a problem hiding this comment.
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"
| 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" |
Description
Type of Change
Module Information
Path:
registry/coder/modules/claude-codeNew version:
v4.5.0Breaking change: [ ] Yes [ ] No
Testing & Validation
bun test)bun fmt)Related Issues
Closes: #649