-
Notifications
You must be signed in to change notification settings - Fork 91
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?
Changes from all commits
db4cbed
11203a4
2efe178
4963d31
3328805
4aad195
0ed44f4
3dbed9a
3dfd968
2e76f43
a59a423
28fc496
8a4b5e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -228,6 +228,22 @@ variable "compile_boundary_from_source" { | |||||
| default = false | ||||||
| } | ||||||
|
|
||||||
| 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 uses Coder's authentication." | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
What do you think about something like this? Same suggestion below. |
||||||
| } | ||||||
|
|
||||||
| 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 uses Coder's authentication." | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| resource "coder_env" "claude_code_md_path" { | ||||||
| count = var.claude_md_path == "" ? 0 : 1 | ||||||
| agent_id = var.agent_id | ||||||
|
|
@@ -281,6 +297,21 @@ resource "coder_env" "anthropic_model" { | |||||
| value = var.model | ||||||
| } | ||||||
|
|
||||||
| resource "coder_env" "anthropic_base_url" { | ||||||
| count = var.enable_aibridge ? 1 : 0 | ||||||
| agent_id = var.agent_id | ||||||
| name = "ANTHROPIC_BASE_URL" | ||||||
| value = "${data.coder_workspace.me.access_url}/api/v2/aibridge/anthropic" | ||||||
| } | ||||||
|
|
||||||
| # https://code.claude.com/docs/en/settings#environment-variables | ||||||
| resource "coder_env" "anthropic_auth_token" { | ||||||
| count = var.enable_aibridge ? 1 : 0 | ||||||
| agent_id = var.agent_id | ||||||
| name = "ANTHROPIC_AUTH_TOKEN" | ||||||
| value = data.coder_workspace_owner.me.session_token | ||||||
| } | ||||||
|
|
||||||
| locals { | ||||||
| # we have to trim the slash because otherwise coder exp mcp will | ||||||
| # set up an invalid claude config | ||||||
|
|
@@ -382,6 +413,7 @@ module "agentapi" { | |||||
| ARG_ALLOWED_TOOLS='${var.allowed_tools}' \ | ||||||
| ARG_DISALLOWED_TOOLS='${var.disallowed_tools}' \ | ||||||
| ARG_MCP='${var.mcp != null ? base64encode(replace(var.mcp, "'", "'\\''")) : ""}' \ | ||||||
| ARG_ENABLE_AIBRIDGE='${var.enable_aibridge}' \ | ||||||
| /tmp/install.sh | ||||||
| EOT | ||||||
| } | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ ARG_MCP_APP_STATUS_SLUG=${ARG_MCP_APP_STATUS_SLUG:-} | |
| ARG_MCP=$(echo -n "${ARG_MCP:-}" | base64 -d) | ||
| ARG_ALLOWED_TOOLS=${ARG_ALLOWED_TOOLS:-} | ||
| ARG_DISALLOWED_TOOLS=${ARG_DISALLOWED_TOOLS:-} | ||
| ARG_ENABLE_AIBRIDGE=${ARG_ENABLE_AIBRIDGE:-false} | ||
|
|
||
| echo "--------------------------------" | ||
|
|
||
|
|
@@ -31,6 +32,7 @@ printf "ARG_MCP_APP_STATUS_SLUG: %s\n" "$ARG_MCP_APP_STATUS_SLUG" | |
| 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" | ||
|
|
||
| echo "--------------------------------" | ||
|
|
||
|
|
@@ -133,27 +135,25 @@ function setup_claude_configurations() { | |
| function configure_standalone_mode() { | ||
| echo "Configuring Claude Code for standalone mode..." | ||
|
|
||
| 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" | ||
| return | ||
| fi | ||
|
|
||
| local claude_config="$HOME/.claude.json" | ||
| local workdir_normalized | ||
| workdir_normalized=$(echo "$ARG_WORKDIR" | tr '/' '-') | ||
|
|
||
| # Create or update .claude.json with minimal configuration for API key auth | ||
| # Create or update .claude.json with minimal configuration | ||
| # This skips the interactive login prompt and onboarding screens | ||
| if [ -f "$claude_config" ]; then | ||
| echo "Updating existing Claude configuration at $claude_config" | ||
|
|
||
| jq --arg apikey "${CLAUDE_API_KEY:-}" \ | ||
| --arg workdir "$ARG_WORKDIR" \ | ||
| jq --arg workdir "$ARG_WORKDIR" \ | ||
| '.autoUpdaterStatus = "disabled" | | ||
| .bypassPermissionsModeAccepted = true | | ||
| .hasAcknowledgedCostThreshold = true | | ||
| .hasCompletedOnboarding = true | | ||
| .primaryApiKey = $apikey | | ||
| .projects[$workdir].hasCompletedProjectOnboarding = true | | ||
| .projects[$workdir].hasTrustDialogAccepted = true' \ | ||
| "$claude_config" > "${claude_config}.tmp" && mv "${claude_config}.tmp" "$claude_config" | ||
|
|
@@ -165,7 +165,6 @@ function configure_standalone_mode() { | |
| "bypassPermissionsModeAccepted": true, | ||
| "hasAcknowledgedCostThreshold": true, | ||
| "hasCompletedOnboarding": true, | ||
| "primaryApiKey": "${CLAUDE_API_KEY:-}", | ||
| "projects": { | ||
| "$ARG_WORKDIR": { | ||
| "hasCompletedProjectOnboarding": true, | ||
|
|
@@ -176,6 +175,11 @@ function configure_standalone_mode() { | |
| EOF | ||
| fi | ||
|
|
||
| # Add API key only if set | ||
| if [ -n "${CLAUDE_API_KEY:-}" ]; then | ||
| jq --arg apikey "${CLAUDE_API_KEY}" '.primaryApiKey = $apikey' "$claude_config" > "${claude_config}.tmp" && mv "${claude_config}.tmp" "$claude_config" | ||
| fi | ||
|
Comment on lines
+178
to
+181
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we get any benefit from adding the key to the file? Why not only rely on |
||
|
|
||
| echo "Standalone mode configured successfully" | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.