Skip to content

Conversation

@rkuprin
Copy link

@rkuprin rkuprin commented Jan 8, 2026

  • 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.

Summary by CodeRabbit

  • New Features

    • Users can set and persist a custom Anthropic API Base URL during setup alongside their API key.
  • Improvements

    • Setup UI renamed to "configuration" wording, adds a dedicated Base URL input and updated success/error messages.
    • Saving now persists base URL to settings and returns masked configuration including base URL.
    • Client APIs accept an optional Base URL when storing configuration.
  • Bug Fixes

    • CLI auth flow now consistently clears/restores Anthropic base URL to avoid mismatched environments.

✏️ Tip: You can customize this high-level summary in your review settings.

- 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
@coderabbitai
Copy link

coderabbitai bot commented Jan 8, 2026

📝 Walkthrough

Walkthrough

This 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

Cohort / File(s) Summary
Route wiring
apps/server/src/index.ts, apps/server/src/routes/setup/index.ts
Inject SettingsService into createSetupRoutes and pass it to setup route handlers.
Store API key + base URL handler
apps/server/src/routes/setup/routes/store-api-key.ts, apps/server/src/routes/setup/routes/verify-claude-auth.ts
Accept optional baseUrl in store handler; persist/clear ANTHROPIC_BASE_URL in environment and via SettingsService; verify flow saves/restores/clears ANTHROPIC_BASE_URL as needed.
Settings persistence & types
apps/server/src/services/settings-service.ts, libs/types/src/settings.ts
Add baseUrls to Credentials; updateCredentials deep-merges baseUrls and apiKeys; getMaskedCredentials exposes optional anthropic baseUrl.
Provider env allowlist
apps/server/src/providers/claude-provider.ts
Add ANTHROPIC_BASE_URL to allowed environment variables forwarded to Claude provider.
Frontend: UI & hooks
apps/ui/src/components/views/setup-view/steps/claude-setup-step.tsx, apps/ui/src/components/views/setup-view/hooks/use-token-save.ts
Add baseUrl input/state in Claude setup; pass baseUrl when saving; adjust messaging to “configuration” for Anthropic.
Client & Electron API
apps/ui/src/lib/http-api-client.ts, apps/ui/src/lib/electron.ts
Extend storeApiKey signatures to accept optional baseUrl and include it in requests; update mock implementations.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

  • Improve code docker2 #201 — touches SettingsService and credentials shape; related to updateCredentials and getMaskedCredentials changes.

Suggested labels

Enhancement, Ready-To-Merge

Poem

🐰 I hopped from UI to server with glee,

I tucked a baseUrl where keys used to be.
Anthropic now finds its custom way,
Saved and restored by settings today.
Tiny rabbit cheers — config, hip-hip-hooray! 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding Anthropic API base URL configuration support, which is the core feature across all modified files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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

  • Anthropic API Base URL Configuration: Introduced support for configuring custom Anthropic API base URLs, enabling use with enterprise deployments and custom endpoints.
  • Credentials Interface Enhancement: The Credentials interface now includes an optional baseUrls field to store custom API endpoints for various providers.
  • Claude Provider Update: The Claude provider has been updated to recognize and utilize the ANTHROPIC_BASE_URL environment variable for the Anthropic SDK.
  • Settings Service Integration: The SettingsService now properly handles and persists base URLs alongside API keys, including deep merging for updates and exposing the base URL in masked credentials.
  • Setup API and UI Updates: The setup API routes and UI have been modified to accept, store, and display base URL configurations, combining API key and base URL inputs into a single cohesive section.
  • Type Safety and API Client Updates: All relevant type definitions, the HTTP client, and the Electron API have been updated to ensure type safety and proper passing of base URL parameters throughout the save flow.

🧠 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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.

Comment on lines +40 to +45
} 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');
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

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');
Copy link
Contributor

Choose a reason for hiding this comment

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

high

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.

Copy link

@coderabbitai coderabbitai bot left a 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_URL to 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 SettingsService is properly injected into the route factory and forwarded to the handler, enabling base URL persistence. However, the baseUrl parameter in store-api-key.ts is 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

📥 Commits

Reviewing files that changed from the base of the PR and between 271749a and c0837b9.

📒 Files selected for processing (10)
  • apps/server/src/index.ts
  • apps/server/src/providers/claude-provider.ts
  • apps/server/src/routes/setup/index.ts
  • apps/server/src/routes/setup/routes/store-api-key.ts
  • apps/server/src/services/settings-service.ts
  • apps/ui/src/components/views/setup-view/hooks/use-token-save.ts
  • apps/ui/src/components/views/setup-view/steps/claude-setup-step.tsx
  • apps/ui/src/lib/electron.ts
  • apps/ui/src/lib/http-api-client.ts
  • libs/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.ts
  • apps/server/src/index.ts
  • apps/ui/src/components/views/setup-view/steps/claude-setup-step.tsx
  • libs/types/src/settings.ts
  • apps/server/src/routes/setup/index.ts
  • apps/ui/src/lib/http-api-client.ts
  • apps/server/src/routes/setup/routes/store-api-key.ts
  • apps/server/src/services/settings-service.ts
  • apps/ui/src/components/views/setup-view/hooks/use-token-save.ts
  • apps/ui/src/lib/electron.ts
apps/server/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Use createEventEmitter() from lib/events.ts for all server operations to emit events that stream to frontend via WebSocket

Files:

  • apps/server/src/providers/claude-provider.ts
  • apps/server/src/index.ts
  • apps/server/src/routes/setup/index.ts
  • apps/server/src/routes/setup/routes/store-api-key.ts
  • apps/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.ts
  • apps/server/src/index.ts
  • apps/ui/src/components/views/setup-view/steps/claude-setup-step.tsx
  • libs/types/src/settings.ts
  • apps/server/src/routes/setup/index.ts
  • apps/ui/src/lib/http-api-client.ts
  • apps/server/src/routes/setup/routes/store-api-key.ts
  • apps/server/src/services/settings-service.ts
  • apps/ui/src/components/views/setup-view/hooks/use-token-save.ts
  • apps/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 baseUrl parameter maintains backward compatibility while enabling the new base URL configuration feature.


29-29: LGTM! Base URL properly passed to API.

The baseUrl parameter is correctly forwarded to the storeApiKey method, aligning with the updated API signature.

libs/types/src/settings.ts (2)

509-513: LGTM! Base URLs field added with proper structure.

The optional baseUrls field 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_CREDENTIALS constant correctly includes the new baseUrls field with anthropic set to undefined, 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 type keyword 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 baseUrl parameter 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 apiKey and baseUrl state 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 baseUrls correctly mirrors the existing apiKeys pattern, maintaining consistency in the service. The atomic write ensures data integrity.

Also applies to: 363-370


386-403: LGTM!

The getMaskedCredentials method 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 baseUrl parameter with appropriate type annotation.

apps/ui/src/lib/electron.ts (3)

650-654: LGTM!

The ElectronAPI type definition correctly reflects the updated storeApiKey signature with the optional baseUrl parameter.


1223-1227: LGTM!

The SetupAPI interface update maintains consistency with the ElectronAPI interface.


1303-1308: LGTM!

The mock implementation correctly accepts the baseUrl parameter and logs it for debugging purposes. No actual persistence is needed for the mock, which is appropriate.

Comment on lines +35 to +55
// 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');
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 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 -100

Repository: AutoMaker-Org/automaker

Length of output: 3113


🏁 Script executed:

# Find persistApiKeyToEnv implementation
rg -n "persistApiKeyToEnv" -A 10 -B 2

Repository: 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 5

Repository: 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 5

Repository: 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 2

Repository: 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 5

Repository: 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 -3

Repository: 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 -150

Repository: 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 3

Repository: 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 5

Repository: 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 -100

Repository: 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 5

Repository: 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 5

Repository: 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 5

Repository: 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 3

Repository: 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 cat

Repository: 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.
Copy link

@coderabbitai coderabbitai bot left a 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> allows undefined values, but the implementation only adds defined values (the condition if (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() from lib/events.ts to 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() from lib/events.ts for 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:

  • HOME and PATH are documented SDK requirements (for config directory ~/.claude and CLI discovery)
  • SHELL, TERM, USER, LANG, LC_ALL are needed for CLI subprocess execution

Add 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

📥 Commits

Reviewing files that changed from the base of the PR and between f651c3b and 77cf672.

📒 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() from lib/events.ts for 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_URL for 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 finally block to ensure cleanup

This maintains environment integrity after verification.

maxTurns: 1,
allowedTools: [],
abortController,
env: buildEnv(),
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 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 -50

Repository: 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 10

Repository: 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.ts

Repository: 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.ts

Repository: 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 -20

Repository: 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 -5

Repository: 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.ts

Repository: 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.

@PhunkyBob
Copy link

Hello,
I wanted to test your branch and I notice the ANTHROPIC_BASE_URL field is missing in the "Settings" section.

image

@webdevcody
Copy link
Collaborator

please fix conflicts and code rabbit comments. we will close in a few days if no more activity on this.

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.

3 participants