-
Notifications
You must be signed in to change notification settings - Fork 444
feat: add Anthropic API base URL configuration support #382
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
- Added support for configuring custom Anthropic API base URLs to enable enterprise deployments and custom endpoints. - Enhanced the Credentials interface to include optional baseUrls field for storing custom API endpoints. - Updated the Claude provider to support ANTHROPIC_BASE_URL environment variable for the Anthropic SDK. - Modified the SettingsService to handle base URLs alongside API keys with proper persistence. - Updated setup API routes to accept and store base URL configuration from the UI. - Combined API key and base URL inputs into a single cohesive configuration section in the setup UI. - Enhanced the HTTP client and Electron API to pass base URL parameters through the save flow. - Updated all type definitions to ensure type safety for the new base URL functionality. This allows users to configure custom Anthropic API endpoints while maintaining backward compatibility for existing users who don't need this feature. Closes AutoMaker-Org#378
📝 WalkthroughWalkthroughThis PR adds optional Anthropic API base URL support across server and client, wires SettingsService into setup routes to persist/restore base URLs alongside API keys, updates environment handling for Claude provider, and exposes baseUrl through UI, client APIs, and settings persistence. Changes
Sequence Diagram(s)sequenceDiagram
participant UI as Claude Setup UI
participant Hook as useTokenSave Hook
participant Client as HttpApiClient / ElectronAPI
participant Server as Store API Key Handler
participant Service as SettingsService
participant Env as Environment
UI->>Hook: saveApiKeyToken(provider, apiKey, baseUrl)
Hook->>Client: storeApiKey(provider, apiKey, baseUrl)
Client->>Server: POST /api/setup/store-api-key {provider, apiKey, baseUrl}
Server->>Env: set/clear ANTHROPIC_BASE_URL (as needed)
Server->>Service: updateCredentials({ apiKeys, baseUrls:{anthropic} })
Service-->>Server: persisted credentials
Server-->>Client: { success: true }
Client-->>Hook: { success: true }
Hook-->>UI: show success toast
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary of ChangesHello @rkuprin, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the application's flexibility by allowing users to specify custom base URLs for the Anthropic API. This feature is crucial for environments requiring custom endpoints, such as enterprise deployments or proxy setups, ensuring broader compatibility and adaptability without breaking existing functionality for users who do not require this customization. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request adds support for configuring a custom Anthropic API base URL, which is a valuable feature for enterprise users. The changes are well-structured across the backend, UI, and type definitions. I've identified two issues related to the persistence of the base URL configuration when it's cleared or deleted, which could lead to inconsistent behavior. My review comments provide details on these issues and suggest how to address them to ensure the configuration is managed correctly throughout its lifecycle. Overall, this is a solid contribution.
| } else if (process.env.ANTHROPIC_BASE_URL) { | ||
| // Clear existing base URL if not provided | ||
| delete process.env.ANTHROPIC_BASE_URL; | ||
| // Note: we don't remove from .env file as that's more complex | ||
| logger.info('[Setup] Cleared ANTHROPIC_BASE_URL from environment'); | ||
| } |
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.
Clearing the ANTHROPIC_BASE_URL from process.env is not sufficient as it won't persist across server restarts. The value will be reloaded from the .env file, causing the old base URL to be used again. This is likely not the intended behavior.
A function removeApiKeyFromEnv already exists in apps/server/src/routes/setup/routes/delete-api-key.ts which can remove a key from the .env file. It would be best to move this function to common.ts and use it here to properly remove the key from the .env file.
Here's how you could modify this block after making removeApiKeyFromEnv available:
} else if (process.env.ANTHROPIC_BASE_URL) {
// Clear existing base URL if not provided
delete process.env.ANTHROPIC_BASE_URL;
await removeApiKeyFromEnv('ANTHROPIC_BASE_URL');
logger.info('[Setup] Cleared ANTHROPIC_BASE_URL from environment and .env file');
}This ensures that clearing the base URL is a persistent change.
| hasCredentialsFile: claudeAuthStatus?.hasCredentialsFile || false, | ||
| }); | ||
| toast.success('API key deleted successfully'); | ||
| toast.success('Anthropic configuration deleted successfully'); |
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 toast message now correctly refers to 'Anthropic configuration'. However, the backend delete-api-key endpoint, which is called when the user deletes the configuration, only seems to delete the API key (ANTHROPIC_API_KEY). It should be updated to also delete the base URL (ANTHROPIC_BASE_URL) from both the .env file and the credentials.json settings to ensure the entire configuration is removed consistently.
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.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In @apps/server/src/routes/setup/routes/store-api-key.ts:
- Around line 35-55: When clearing process.env.ANTHROPIC_BASE_URL in the else
branch, also call and await persistApiKeyToEnv('ANTHROPIC_BASE_URL', '') so the
.env file is updated to an empty value (preventing dotenv from restoring the old
value on restart); update the block around process.env.ANTHROPIC_BASE_URL to
delete the env var, await persistApiKeyToEnv with an empty string, and keep the
logger.info message (referencing persistApiKeyToEnv and
process.env.ANTHROPIC_BASE_URL).
🧹 Nitpick comments (3)
apps/ui/src/components/views/setup-view/hooks/use-token-save.ts (1)
33-33: Success message now says "configuration" instead of "API key".The toast message has been generalized from "API key saved successfully" to "configuration saved successfully" for non-OAuth providers. This is more accurate since the function now saves both API keys and optional base URLs, but existing users might notice the wording change.
Alternative: More specific messaging
If you want to be more explicit about what was saved, consider:
- const tokenType = provider.includes('oauth') ? 'subscription token' : 'configuration'; + const tokenType = provider.includes('oauth') ? 'subscription token' : baseUrl ? 'API key and base URL' : 'API key';This provides more context to users about what was actually configured.
apps/server/src/providers/claude-provider.ts (1)
23-25: LGTM! Anthropic base URL environment variable added.Adding
ANTHROPIC_BASE_URLto the allowlist enables the Anthropic SDK to use custom API endpoints for enterprise deployments. This follows the existing security pattern of explicit environment variable allowlisting.Optional: Add documentation comment
Consider adding a comment explaining when this variable is used:
const ALLOWED_ENV_VARS = [ 'ANTHROPIC_API_KEY', + // Custom API endpoint for enterprise deployments or proxies 'ANTHROPIC_BASE_URL', 'PATH',apps/server/src/routes/setup/index.ts (1)
28-34: Dependency injection correctly implemented; add URL validation for baseUrl.The
SettingsServiceis properly injected into the route factory and forwarded to the handler, enabling base URL persistence. However, thebaseUrlparameter instore-api-key.tsis only trimmed (lines 36-39) without validating its format. The handler accepts any non-empty string, which could cause runtime errors when the Anthropic SDK attempts to use an invalid URL. Add URL validation before persisting to prevent downstream failures.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (10)
apps/server/src/index.tsapps/server/src/providers/claude-provider.tsapps/server/src/routes/setup/index.tsapps/server/src/routes/setup/routes/store-api-key.tsapps/server/src/services/settings-service.tsapps/ui/src/components/views/setup-view/hooks/use-token-save.tsapps/ui/src/components/views/setup-view/steps/claude-setup-step.tsxapps/ui/src/lib/electron.tsapps/ui/src/lib/http-api-client.tslibs/types/src/settings.ts
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (CLAUDE.md)
Always import from shared packages (@automaker/*), never from old relative paths
Files:
apps/server/src/providers/claude-provider.tsapps/server/src/index.tsapps/ui/src/components/views/setup-view/steps/claude-setup-step.tsxlibs/types/src/settings.tsapps/server/src/routes/setup/index.tsapps/ui/src/lib/http-api-client.tsapps/server/src/routes/setup/routes/store-api-key.tsapps/server/src/services/settings-service.tsapps/ui/src/components/views/setup-view/hooks/use-token-save.tsapps/ui/src/lib/electron.ts
apps/server/src/**/*.{ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
Use
createEventEmitter()fromlib/events.tsfor all server operations to emit events that stream to frontend via WebSocket
Files:
apps/server/src/providers/claude-provider.tsapps/server/src/index.tsapps/server/src/routes/setup/index.tsapps/server/src/routes/setup/routes/store-api-key.tsapps/server/src/services/settings-service.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
Use
resolveModelString()from @automaker/model-resolver to convert model aliases (haiku, sonnet, opus) to full model names
Files:
apps/server/src/providers/claude-provider.tsapps/server/src/index.tsapps/ui/src/components/views/setup-view/steps/claude-setup-step.tsxlibs/types/src/settings.tsapps/server/src/routes/setup/index.tsapps/ui/src/lib/http-api-client.tsapps/server/src/routes/setup/routes/store-api-key.tsapps/server/src/services/settings-service.tsapps/ui/src/components/views/setup-view/hooks/use-token-save.tsapps/ui/src/lib/electron.ts
🧠 Learnings (1)
📚 Learning: 2025-12-30T01:02:07.114Z
Learnt from: illia1f
Repo: AutoMaker-Org/automaker PR: 324
File: apps/ui/src/components/views/board-view/components/kanban-card/kanban-card.tsx:122-131
Timestamp: 2025-12-30T01:02:07.114Z
Learning: Tailwind CSS v4 uses postfix syntax for the important modifier: append ! at the end of the utility class (e.g., backdrop-blur-[0px]! or hover:bg-red-500!). The older v3 style used a prefix (!) at the start (e.g., !backdrop-blur-[0px]); prefer the postfix form for consistency across TSX files.
Applied to files:
apps/ui/src/components/views/setup-view/steps/claude-setup-step.tsx
🧬 Code graph analysis (3)
apps/server/src/index.ts (1)
apps/server/src/routes/setup/index.ts (1)
createSetupRoutes(28-55)
apps/server/src/routes/setup/index.ts (2)
apps/server/src/services/settings-service.ts (1)
SettingsService(107-709)apps/server/src/routes/setup/routes/store-api-key.ts (1)
createStoreApiKeyHandler(12-70)
apps/server/src/routes/setup/routes/store-api-key.ts (1)
apps/server/src/routes/setup/common.ts (1)
persistApiKeyToEnv(40-50)
🔇 Additional comments (19)
apps/ui/src/components/views/setup-view/hooks/use-token-save.ts (2)
17-17: LGTM! Optional baseUrl parameter added correctly.The addition of the optional
baseUrlparameter maintains backward compatibility while enabling the new base URL configuration feature.
29-29: LGTM! Base URL properly passed to API.The
baseUrlparameter is correctly forwarded to thestoreApiKeymethod, aligning with the updated API signature.libs/types/src/settings.ts (2)
509-513: LGTM! Base URLs field added with proper structure.The optional
baseUrlsfield is well-designed:
- Maintains backward compatibility through optional typing
- Allows future expansion for other providers
- Clear JSDoc comment explains the purpose
693-695: LGTM! Default credentials properly updated.The
DEFAULT_CREDENTIALSconstant correctly includes the newbaseUrlsfield withanthropicset toundefined, maintaining consistency with the interface definition.apps/server/src/index.ts (1)
209-209: LGTM! SettingsService correctly injected into setup routes.The dependency injection follows the existing pattern used by other routes (e.g., line 206 for enhance-prompt, line 210 for suggestions) and enables the store-api-key handler to persist base URL configuration.
apps/server/src/routes/setup/index.ts (1)
6-6: LGTM! Type-only import used correctly.The
typekeyword in the import ensures this is stripped during compilation, following TypeScript best practices for type-only imports.apps/ui/src/lib/http-api-client.ts (1)
1012-1019: LGTM!The addition of the optional
baseUrlparameter is clean and follows the existing pattern of server-side validation. The parameter is properly threaded through to the POST payload.apps/ui/src/components/views/setup-view/steps/claude-setup-step.tsx (5)
58-58: LGTM!State initialization follows the existing pattern for
apiKey.
566-584: LGTM!The base URL input follows established patterns and provides clear guidance. The
type="url"attribute enables HTML5 validation, and the helper text effectively communicates that this is an optional field for advanced use cases.
587-587: LGTM!The save flow correctly passes both parameters to the token save hook.
223-224: LGTM!Correctly clears both
apiKeyandbaseUrlstate when deleting the configuration, maintaining consistency with the backend.
115-115: LGTM!The terminology updates from "API key" to "configuration" are appropriate since the feature now manages both API keys and base URLs. The changes are consistent throughout the file and improve clarity.
Also applies to: 233-233, 235-235, 237-240, 537-537, 598-598
apps/server/src/services/settings-service.ts (2)
337-337: LGTM!The deep merge implementation for
baseUrlscorrectly mirrors the existingapiKeyspattern, maintaining consistency in the service. The atomic write ensures data integrity.Also applies to: 363-370
386-403: LGTM!The
getMaskedCredentialsmethod correctly includes the base URL in the response. The optional chaining ensures safe access, and it's appropriate that base URLs are not masked (unlike API keys).apps/server/src/routes/setup/routes/store-api-key.ts (2)
12-12: LGTM!The function signature update enables dependency injection of
SettingsService, which is the correct approach for persisting base URL configuration.
15-19: LGTM!The request body destructuring correctly includes the optional
baseUrlparameter with appropriate type annotation.apps/ui/src/lib/electron.ts (3)
650-654: LGTM!The
ElectronAPItype definition correctly reflects the updatedstoreApiKeysignature with the optionalbaseUrlparameter.
1223-1227: LGTM!The
SetupAPIinterface update maintains consistency with theElectronAPIinterface.
1303-1308: LGTM!The mock implementation correctly accepts the
baseUrlparameter and logs it for debugging purposes. No actual persistence is needed for the mock, which is appropriate.
| // Handle custom base URL if provided | ||
| if (baseUrl && baseUrl.trim()) { | ||
| process.env.ANTHROPIC_BASE_URL = baseUrl.trim(); | ||
| await persistApiKeyToEnv('ANTHROPIC_BASE_URL', baseUrl.trim()); | ||
| logger.info('[Setup] Stored custom base URL as ANTHROPIC_BASE_URL'); | ||
| } else if (process.env.ANTHROPIC_BASE_URL) { | ||
| // Clear existing base URL if not provided | ||
| delete process.env.ANTHROPIC_BASE_URL; | ||
| // Note: we don't remove from .env file as that's more complex | ||
| logger.info('[Setup] Cleared ANTHROPIC_BASE_URL from environment'); | ||
| } | ||
|
|
||
| // Persist base URL to settings service | ||
| if (baseUrl !== undefined) { | ||
| await settingsService.updateCredentials({ | ||
| baseUrls: { | ||
| anthropic: baseUrl.trim() || undefined, | ||
| }, | ||
| }); | ||
| logger.info('[Setup] Persisted base URL to settings service'); | ||
| } |
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.
🧩 Analysis chain
🏁 Script executed:
# First, find and examine the file mentioned in the review
find . -type f -name "store-api-key.ts" -path "*/routes/setup/*"Repository: AutoMaker-Org/automaker
Length of output: 121
🏁 Script executed:
# Check the actual implementation of the code in question
cat -n apps/server/src/routes/setup/routes/store-api-key.ts | head -100Repository: AutoMaker-Org/automaker
Length of output: 3113
🏁 Script executed:
# Find persistApiKeyToEnv implementation
rg -n "persistApiKeyToEnv" -A 10 -B 2Repository: AutoMaker-Org/automaker
Length of output: 4326
🏁 Script executed:
# Check how environment variables are loaded at startup
rg -n "ANTHROPIC_BASE_URL" -A 5 -B 5Repository: AutoMaker-Org/automaker
Length of output: 3373
🏁 Script executed:
# Check secureFs.writeEnvKey implementation to see if it can delete keys
rg -n "writeEnvKey" -A 15 -B 5Repository: AutoMaker-Org/automaker
Length of output: 4236
🏁 Script executed:
# Check how settings service initializes and uses baseUrl
rg -n "class SettingsService|updateCredentials|getCredentials" apps/server/src/services/settings-service.ts -A 10 -B 2Repository: AutoMaker-Org/automaker
Length of output: 3273
🏁 Script executed:
# Check how ANTHROPIC_BASE_URL is used when initializing the client
rg -n "ANTHROPIC_BASE_URL" apps/server/src/providers/claude-provider.ts -A 5 -B 5Repository: AutoMaker-Org/automaker
Length of output: 369
🏁 Script executed:
# Check the initialization order in the main app file
find . -type f -name "main.ts" -o -name "index.ts" -o -name "app.ts" | xargs grep -l "SettingsService\|setupRoutes" 2>/dev/null | head -3Repository: AutoMaker-Org/automaker
Length of output: 198
🏁 Script executed:
# Check claude-provider to see where ANTHROPIC_BASE_URL is used and how it's initialized
cat -n apps/server/src/providers/claude-provider.ts | head -150Repository: AutoMaker-Org/automaker
Length of output: 5968
🏁 Script executed:
# Check how settings service baseUrls are loaded and used
rg -n "baseUrl|baseUrls" apps/server/src/providers/claude-provider.ts -A 3 -B 3Repository: AutoMaker-Org/automaker
Length of output: 49
🏁 Script executed:
# Look at app initialization to understand the order of precedence
rg -n "SettingsService\|setupRoutes\|createClaudeProvider" apps/server/src/index.ts -A 5 -B 5Repository: AutoMaker-Org/automaker
Length of output: 49
🏁 Script executed:
# Look for where settings service baseUrls are applied to process.env
rg -n "baseUrl|baseUrls" apps/server/src -A 2 -B 2 | head -100Repository: AutoMaker-Org/automaker
Length of output: 4110
🏁 Script executed:
# Check if there's any initialization code that applies settings service values to process.env
rg -n "updateCredentials|getCredentials" apps/server/src/index.ts -A 10 -B 5Repository: AutoMaker-Org/automaker
Length of output: 49
🏁 Script executed:
# Check the updateEnvContent function to understand what it does
cat -n libs/platform/src/secure-fs.ts | grep -A 30 "function updateEnvContent"Repository: AutoMaker-Org/automaker
Length of output: 1194
🏁 Script executed:
# Check if there's any startup code that loads settings service baseUrl into process.env
rg -n "process.env.ANTHROPIC_BASE_URL\s*=" apps/server/src -B 5 -A 5Repository: AutoMaker-Org/automaker
Length of output: 1268
🏁 Script executed:
# Search for any initialization that reads baseUrls from settings service
rg -n "getCredentials|baseUrl" apps/server/src/index.ts -A 5 -B 5Repository: AutoMaker-Org/automaker
Length of output: 49
🏁 Script executed:
# Look for any middleware or initialization that syncs settings service to process.env
rg -n "settingsService|baseUrl" apps/server/src/middleware -A 3 -B 3Repository: AutoMaker-Org/automaker
Length of output: 49
🏁 Script executed:
# Check the main server file for initialization logic
find . -type f -path "*/apps/server/src/index.ts" -o -path "*/apps/server/src/main.ts" | xargs catRepository: AutoMaker-Org/automaker
Length of output: 22471
Call persistApiKeyToEnv with an empty value when clearing the base URL to ensure .env is updated
When clearing the base URL (lines 40-45), the code removes it from process.env but doesn't update the .env file. Since dotenv.config() runs at startup and reloads the old baseUrl from .env, the cleared baseUrl will reappear after a server restart.
The simplest fix is to persist an empty value to .env when clearing, which the existing updateEnvContent() function already supports:
} else if (process.env.ANTHROPIC_BASE_URL) {
// Clear existing base URL if not provided
delete process.env.ANTHROPIC_BASE_URL;
await persistApiKeyToEnv('ANTHROPIC_BASE_URL', '');
logger.info('[Setup] Cleared ANTHROPIC_BASE_URL from environment');
}
This way, the .env file will be updated to an empty value, preventing the old baseUrl from being restored on restart.
🤖 Prompt for AI Agents
In @apps/server/src/routes/setup/routes/store-api-key.ts around lines 35 - 55,
When clearing process.env.ANTHROPIC_BASE_URL in the else branch, also call and
await persistApiKeyToEnv('ANTHROPIC_BASE_URL', '') so the .env file is updated
to an empty value (preventing dotenv from restoring the old value on restart);
update the block around process.env.ANTHROPIC_BASE_URL to delete the env var,
await persistApiKeyToEnv with an empty string, and keep the logger.info message
(referencing persistApiKeyToEnv and process.env.ANTHROPIC_BASE_URL).
…nment variables - Updated the verification handler to clear both the API key and base URL when using CLI authentication. - Restored the original base URL after verification, ensuring proper environment management for different authentication methods. - Improved logging to reflect changes in environment variable handling during CLI verification.
- Added a function to build an environment object containing explicitly allowed environment variables for the SDK. - This ensures that only specified variables are passed to the SDK, enhancing security and control over the environment. - Updated the verification handler to utilize the new environment management function during authentication.
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.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In @apps/server/src/routes/setup/routes/verify-claude-auth.ts:
- Line 161: The buildEnv() function is typed too loosely; change its return type
from Record<string, string | undefined> to Record<string, string> and adjust the
implementation so the compiler knows no undefined values are present (e.g., keep
the existing conditional that only assigns when process.env[key] is truthy or
explicitly filter/guard values before assignment), so callers like the env
option passed to the Claude SDK match the stricter Record<string, string> type.
🧹 Nitpick comments (3)
apps/server/src/routes/setup/routes/verify-claude-auth.ts (3)
30-38: Consider refining the return type for clarity.The return type
Record<string, string | undefined>allowsundefinedvalues, but the implementation only adds defined values (the conditionif (process.env[key])filters out falsy values). Consider making the type more precise.♻️ Optional type refinement
-function buildEnv(): Record<string, string | undefined> { - const env: Record<string, string | undefined> = {}; +function buildEnv(): Record<string, string> { + const env: Record<string, string> = {}; for (const key of ALLOWED_ENV_VARS) { if (process.env[key]) { env[key] = process.env[key]; } } return env; }Note: This also means empty strings won't be passed to the SDK, which is likely the desired behavior.
98-348: Consider emitting real-time events during verification.According to the coding guidelines, server operations should use
createEventEmitter()fromlib/events.tsto stream events to the frontend via WebSocket.Since verification can take up to 30 seconds, emitting progress events (e.g., "Starting verification", "Testing authentication", "Processing response") would improve the user experience by providing real-time feedback.
As per coding guidelines: "Use
createEventEmitter()fromlib/events.tsfor all server operations to emit events that stream to frontend via WebSocket"
13-25: Document why each environment variable is required.Verification confirms that the system environment variables are necessary for Claude Agent SDK operation:
HOMEandPATHare documented SDK requirements (for config directory~/.claudeand CLI discovery)SHELL,TERM,USER,LANG,LC_ALLare needed for CLI subprocess executionAdd inline comments explaining why each variable category (Anthropic-specific vs. system) is included. For example:
// Anthropic SDK authentication and configuration 'ANTHROPIC_API_KEY', 'ANTHROPIC_BASE_URL', // System vars needed by Claude SDK for config directory (~/.claude) and CLI operations 'PATH', // For finding claude-code CLI executable 'HOME', // For reading/writing ~/.claude config 'SHELL', // For CLI subprocess execution 'TERM', 'USER', 'LANG', 'LC_ALL', // For terminal and locale handling in CLI
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
apps/server/src/routes/setup/routes/verify-claude-auth.ts
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (CLAUDE.md)
Always import from shared packages (@automaker/*), never from old relative paths
Files:
apps/server/src/routes/setup/routes/verify-claude-auth.ts
apps/server/src/**/*.{ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
Use
createEventEmitter()fromlib/events.tsfor all server operations to emit events that stream to frontend via WebSocket
Files:
apps/server/src/routes/setup/routes/verify-claude-auth.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
Use
resolveModelString()from @automaker/model-resolver to convert model aliases (haiku, sonnet, opus) to full model names
Files:
apps/server/src/routes/setup/routes/verify-claude-auth.ts
🔇 Additional comments (2)
apps/server/src/routes/setup/routes/verify-claude-auth.ts (2)
121-121: Good environment management for CLI authentication.The logic correctly:
- Captures the original
ANTHROPIC_BASE_URLfor later restoration- Clears both API key and base URL for CLI verification (CLI auth only works with standard Anthropic endpoints)
- Logs the combined clearance for debugging
This is consistent with the existing API key handling pattern and maintains the integrity of CLI authentication.
Also applies to: 128-130
319-325: Environment restoration logic is correct.The base URL restoration pattern correctly mirrors the API key restoration logic:
- Restores the original value if it existed
- Keeps it cleared for CLI auth if there was no original value
- Executes in the
finallyblock to ensure cleanupThis maintains environment integrity after verification.
| maxTurns: 1, | ||
| allowedTools: [], | ||
| abortController, | ||
| env: buildEnv(), |
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.
🧩 Analysis chain
🌐 Web query:
@anthropic-ai/claude-agent-sdk 0.1.76 env option query configuration documentation
💡 Result:
Short answer: In @anthropic-ai/claude-agent-sdk v0.1.76 the "env" option is a dictionary of environment-variable name → string value that the SDK passes to the child/CLI/MCP processes it launches (used to provide API keys, credentials, feature flags, etc.). Example usage: env: { "ANTHROPIC_API_KEY": "sk-...", "DEBUG": "true" }. You can also combine this with extra_args for CLI flags. [1][2][3]
Sources:
- Package/version listing (v0.1.76). [1]
- Options docs showing env (dict[str,str]) and example. [2]
- Anthropic/Claude Agent SDK docs describing MCP/CLI env usage and API-key patterns. [3]
🏁 Script executed:
# Find and examine the actual file context
cat -n apps/server/src/routes/setup/routes/verify-claude-auth.ts | sed -n '150,175p'Repository: AutoMaker-Org/automaker
Length of output: 1098
🏁 Script executed:
# Search for buildEnv() function definition
fd -t f "\.ts$" -x grep -l "buildEnv" {} \;Repository: AutoMaker-Org/automaker
Length of output: 173
🏁 Script executed:
# Check for SDK version specification
cat -n package.json | head -50Repository: AutoMaker-Org/automaker
Length of output: 3748
🏁 Script executed:
# Find and examine buildEnv() definition
rg "export\s+function\s+buildEnv|function\s+buildEnv|const\s+buildEnv" -A 10Repository: AutoMaker-Org/automaker
Length of output: 1788
🏁 Script executed:
# Search for query function definition and its parameters
rg "function\s+query|const\s+query|export.*query" -B 2 -A 15 apps/server/src/routes/setup/routes/verify-claude-auth.tsRepository: AutoMaker-Org/automaker
Length of output: 49
🏁 Script executed:
# Check imports in the file to understand where query and buildEnv come from
head -30 apps/server/src/routes/setup/routes/verify-claude-auth.tsRepository: AutoMaker-Org/automaker
Length of output: 881
🏁 Script executed:
# Search for query function type definition
rg "query.*options" -A 5 apps/server/src/routes/setup/routes/verify-claude-auth.ts | head -20Repository: AutoMaker-Org/automaker
Length of output: 49
🏁 Script executed:
# Check if there are TypeScript type definitions available
find . -name "*.d.ts" -type f | xargs grep -l "query" 2>/dev/null | head -5Repository: AutoMaker-Org/automaker
Length of output: 49
🏁 Script executed:
# Look at how buildEnv is used - check if undefined values could cause issues
rg "for.*const.*key.*of.*ALLOWED_ENV_VARS" -A 5 apps/server/src/routes/setup/routes/verify-claude-auth.tsRepository: AutoMaker-Org/automaker
Length of output: 193
🏁 Script executed:
# Check if the env object actually contains any undefined values at runtime
# by looking at how the allowed vars are accessed
cat -n apps/server/src/routes/setup/routes/verify-claude-auth.ts | sed -n '25,60p'Repository: AutoMaker-Org/automaker
Length of output: 1198
SDK support confirmed; tighten the return type annotation.
The env option is supported by @anthropic-ai/claude-agent-sdk v0.1.76 and the usage here is correct. However, buildEnv() should return Record<string, string> instead of Record<string, string | undefined> since the function only assigns keys when values are truthy (line 33: if (process.env[key])), meaning the object never actually contains undefined values.
🤖 Prompt for AI Agents
In @apps/server/src/routes/setup/routes/verify-claude-auth.ts at line 161, The
buildEnv() function is typed too loosely; change its return type from
Record<string, string | undefined> to Record<string, string> and adjust the
implementation so the compiler knows no undefined values are present (e.g., keep
the existing conditional that only assigns when process.env[key] is truthy or
explicitly filter/guard values before assignment), so callers like the env
option passed to the Claude SDK match the stricter Record<string, string> type.
|
please fix conflicts and code rabbit comments. we will close in a few days if no more activity on this. |

This allows users to configure custom Anthropic API endpoints while maintaining backward compatibility for existing users who don't need this feature.
Summary by CodeRabbit
New Features
Improvements
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.