Skip to content

feat: implement AWS Bedrock integration and update authentication han…#548

Open
tintnc wants to merge 6 commits intositeboon:mainfrom
tintnc:feat/aws_bedrock_support
Open

feat: implement AWS Bedrock integration and update authentication han…#548
tintnc wants to merge 6 commits intositeboon:mainfrom
tintnc:feat/aws_bedrock_support

Conversation

@tintnc
Copy link

@tintnc tintnc commented Mar 15, 2026

Inspired by: #306

image
  • Added AWS Bedrock configuration entries to .env.example to simplify initial setup.
  • Updated the SDK to support asynchronous mapping of CLI options, with model aliases resolved via Bedrock configuration.
  • Extended authentication validation to cover Bedrock mode and adjusted the CLI auth route response format.
  • Updated state management to surface Bedrock authentication status consistently across components.

Summary by CodeRabbit

  • New Features

    • Optional AWS Bedrock support for Claude: auth/status now indicates Bedrock usage, model selection can resolve Bedrock-specific model IDs, and login/re-auth prompts are hidden when Bedrock is active.
    • Authentication status responses and client state include an isBedrock flag.
  • Documentation

    • Updated environment example with commented Bedrock configuration and model override guidance.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 15, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds commented AWS Bedrock guidance to .env.example; introduces Bedrock-aware model resolution and env loading (~/.claude/settings.json); surfaces isBedrock through server auth responses and frontend types/UI; makes CLI→SDK mapping async to await settings-driven resolution.

Changes

Cohort / File(s) Summary
Env example
\.env.example
Adds commented AWS Bedrock configuration block and Claude model override vars (CLAUDE_CODE_USE_BEDROCK, AWS_*, AWS_BEARER_TOKEN_BEDROCK, ANTHROPIC_MODEL).
Backend: SDK & Model Resolution
server/claude-sdk.js
mapCliOptionsToSDK changed to async; awaits loadClaudeSettingsEnv; adds resolveClaudeEnvValue/resolveClaudeModel to choose Bedrock vs SDK models; queryClaudeSDK awaits mapping.
Backend: Auth & Status
server/routes/cli-auth.js
Adds Bedrock bypass in credential checks; returns isBedrock: true for Bedrock path and ensures isBedrock present (false) for other paths; imports loadClaudeSettingsEnv.
Backend: Env Helpers
server/utils/env-helpers.js
Adds isTruthyValue(value) and loadClaudeSettingsEnv() to read ~/.claude/settings.json safely (non-throwing, returns {} on error).
Shared Constants
shared/modelConstants.js
Adds CLAUDE_MODELS.BEDROCK mapping for aliases (sonnet, opus, haiku, etc.) to Bedrock model IDs.
Frontend: Types & Defaults
src/components/settings/types/types.ts, src/components/settings/constants/constants.ts
Adds optional isBedrock?: boolean to AuthStatus and sets DEFAULT_AUTH_STATUS.isBedrock = false.
Frontend: Hooks & UI
src/components/settings/hooks/useSettingsController.ts, src/components/settings/view/tabs/agents-settings/.../AccountContent.tsx
Extends StatusApiResponse to include isBedrock; propagates it into auth state and hides login/re-auth UI when isBedrock is true.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Server
  participant SettingsFile as "~/.claude/settings.json"
  participant Bedrock
  rect rgba(200,200,255,0.5)
    Client->>Server: request Claude status / operation
    Server->>SettingsFile: loadClaudeSettingsEnv()
    SettingsFile-->>Server: returns env object (or {})
    alt Bedrock enabled (env or process.env)
      Server->>Server: resolveClaudeModel(alias, settingsEnv)
      Server->>Bedrock: call Bedrock endpoint (bedrock auth path)
      Bedrock-->>Server: respond (method: "bedrock")
      Server-->>Client: { authenticated: true, method: "bedrock", isBedrock: true }
    else Non-Bedrock
      Server->>Server: check API key / OAuth / settings.json creds
      Server-->>Client: { authenticated:*, method:*, isBedrock: false }
    end
  end
Loading

Possibly related PRs

Suggested Reviewers

  • viper151
  • blackmammoth

Poem

🐰
I nibble configs in the night,
Bedrock paths now gleam with light,
Models hop from file to sky,
isBedrock gives a cheerful try,
Claude and I debug by moonlight.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 70.00% 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 pull request title clearly summarizes the main changes: implementing AWS Bedrock integration and updating authentication handling, which are the primary objectives of this changeset.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Copy link
Contributor

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/components/settings/hooks/useSettingsController.ts (1)

276-284: ⚠️ Potential issue | 🟡 Minor

Missing isBedrock: false in failed response path.

When !response.ok, the status object is missing the isBedrock field. Since setAuthStatusByProvider replaces the entire object (not merges), this could leave isBedrock undefined. Other paths at lines 287-294 and 297-303 correctly include it.

🔧 Proposed fix
       if (!response.ok) {
         setAuthStatusByProvider(provider, {
           authenticated: false,
           email: null,
           loading: false,
           error: 'Failed to check authentication status',
+          isBedrock: false,
         });
         return;
       }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/settings/hooks/useSettingsController.ts` around lines 276 -
284, The failure branch that runs when response.ok is false calls
setAuthStatusByProvider(provider, {...}) but omits the isBedrock property;
update that object to include isBedrock: false (matching the other
failure/success branches) so setAuthStatusByProvider receives a complete status
shape for provider and won’t leave isBedrock undefined.
server/routes/cli-auth.js (1)

166-172: ⚠️ Potential issue | 🟡 Minor

Missing isBedrock: false in ANTHROPIC_API_KEY path.

This return path is missing the isBedrock field, while other api_key paths (lines 177-184, 186-193) include it. For consistency and to avoid potential undefined values, add the field.

🔧 Proposed fix
   if (process.env.ANTHROPIC_API_KEY && process.env.ANTHROPIC_API_KEY.trim()) {
     return {
       authenticated: true,
       email: 'API Key Auth',
-      method: 'api_key'
+      method: 'api_key',
+      isBedrock: false
     };
   }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/routes/cli-auth.js` around lines 166 - 172, The ANTHROPIC_API_KEY
return path is missing the isBedrock property; update the object returned inside
the conditional that checks process.env.ANTHROPIC_API_KEY (the block returning
authenticated: true, email: 'API Key Auth', method: 'api_key') to include
isBedrock: false so it matches the other api_key return paths and avoids
undefined values.
🧹 Nitpick comments (2)
server/claude-sdk.js (2)

472-485: loadClaudeSettingsEnv is also duplicated in cli-auth.js.

Similar to isTruthyValue, this function is duplicated in server/routes/cli-auth.js (lines 111-125). Both implementations read from the same path and have identical logic. Consider extracting to a shared module.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/claude-sdk.js` around lines 472 - 485, Duplicate implementation of
loadClaudeSettingsEnv exists; extract it into a single shared module (e.g.,
create a new module that exports loadClaudeSettingsEnv) and replace both local
copies with imports. Preserve the original behavior (async function, reading
path.join(os.homedir(), '.claude', 'settings.json'), JSON.parse, returning
parsed.env when an object, catching errors and returning {}), export it as a
named function (loadClaudeSettingsEnv) from the new module, update the callers
(the implementations currently in claude-sdk.js and cli-auth.js) to import that
function and remove the duplicate code blocks.

463-470: Consider extracting isTruthyValue to a shared utility.

This helper is duplicated in server/routes/cli-auth.js (lines 9-16). Extracting it to a shared utility module would reduce duplication and ensure consistent behavior.

♻️ Suggested refactor

Create a shared utility file:

// server/utils/env-helpers.js
export function isTruthyValue(value) {
  if (typeof value !== 'string') {
    return false;
  }
  const normalized = value.trim().toLowerCase();
  return normalized === '1' || normalized === 'true' || normalized === 'yes' || normalized === 'on';
}

Then import in both files:

import { isTruthyValue } from './utils/env-helpers.js';
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/claude-sdk.js` around lines 463 - 470, The helper isTruthyValue is
duplicated; extract it into a shared utility module (e.g., env-helpers) as a
named export isTruthyValue, remove the local definitions in the modules that
currently define it, and update those modules to import { isTruthyValue } from
the new utility; ensure the exported function preserves the same string-check
behavior and replace the local calls with the imported function everywhere the
duplicate existed (including the other module that currently contains lines
9-16).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@server/routes/cli-auth.js`:
- Around line 166-172: The ANTHROPIC_API_KEY return path is missing the
isBedrock property; update the object returned inside the conditional that
checks process.env.ANTHROPIC_API_KEY (the block returning authenticated: true,
email: 'API Key Auth', method: 'api_key') to include isBedrock: false so it
matches the other api_key return paths and avoids undefined values.

In `@src/components/settings/hooks/useSettingsController.ts`:
- Around line 276-284: The failure branch that runs when response.ok is false
calls setAuthStatusByProvider(provider, {...}) but omits the isBedrock property;
update that object to include isBedrock: false (matching the other
failure/success branches) so setAuthStatusByProvider receives a complete status
shape for provider and won’t leave isBedrock undefined.

---

Nitpick comments:
In `@server/claude-sdk.js`:
- Around line 472-485: Duplicate implementation of loadClaudeSettingsEnv exists;
extract it into a single shared module (e.g., create a new module that exports
loadClaudeSettingsEnv) and replace both local copies with imports. Preserve the
original behavior (async function, reading path.join(os.homedir(), '.claude',
'settings.json'), JSON.parse, returning parsed.env when an object, catching
errors and returning {}), export it as a named function (loadClaudeSettingsEnv)
from the new module, update the callers (the implementations currently in
claude-sdk.js and cli-auth.js) to import that function and remove the duplicate
code blocks.
- Around line 463-470: The helper isTruthyValue is duplicated; extract it into a
shared utility module (e.g., env-helpers) as a named export isTruthyValue,
remove the local definitions in the modules that currently define it, and update
those modules to import { isTruthyValue } from the new utility; ensure the
exported function preserves the same string-check behavior and replace the local
calls with the imported function everywhere the duplicate existed (including the
other module that currently contains lines 9-16).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 73fe83d1-5fe0-4878-b1bb-d84fbc8a59be

📥 Commits

Reviewing files that changed from the base of the PR and between 95bcee0 and 181cf5c.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (7)
  • .env.example
  • server/claude-sdk.js
  • server/routes/cli-auth.js
  • src/components/settings/constants/constants.ts
  • src/components/settings/hooks/useSettingsController.ts
  • src/components/settings/types/types.ts
  • src/components/settings/view/tabs/agents-settings/sections/content/AccountContent.tsx

@tintnc
Copy link
Author

tintnc commented Mar 15, 2026

Addressing CodeRabbit review feedback:

  • Moved isTruthyValue and loadClaudeSettingsEnv from claude-sdk.js and cli-auth.js into a dedicated utils/env-helpers.js module to improve structure and reuse.
  • Updated claude-sdk.js and cli-auth.js to import from the new helper module.

Copy link
Contributor

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

🧹 Nitpick comments (1)
server/utils/env-helpers.js (1)

25-38: Consider caching to avoid redundant file reads during a single request.

Per context snippets, loadClaudeSettingsEnv() is called from both checkClaudeCredentials() (cli-auth.js:125) and mapCliOptionsToSDK() (claude-sdk.js:196). A single request flow that checks auth and then processes through the SDK will read ~/.claude/settings.json twice.

While the current implementation is correct and OS-level file caching mitigates most overhead, a simple module-level cache with TTL would reduce I/O and ensure consistent snapshots within a request.

💡 Optional: Add simple caching
+let cachedSettingsEnv = null;
+let cacheTimestamp = 0;
+const CACHE_TTL_MS = 5000; // 5 seconds
+
 export async function loadClaudeSettingsEnv() {
+  const now = Date.now();
+  if (cachedSettingsEnv && (now - cacheTimestamp) < CACHE_TTL_MS) {
+    return cachedSettingsEnv;
+  }
+
   try {
     const settingsPath = path.join(os.homedir(), '.claude', 'settings.json');
     const content = await fs.readFile(settingsPath, 'utf8');
     const settings = JSON.parse(content);
 
     if (settings?.env && typeof settings.env === 'object') {
+      cachedSettingsEnv = settings.env;
+      cacheTimestamp = now;
       return settings.env;
     }
   } catch {
     // Ignore missing or malformed settings and fall back to empty.
   }
 
+  cachedSettingsEnv = {};
+  cacheTimestamp = now;
   return {};
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/utils/env-helpers.js` around lines 25 - 38, loadClaudeSettingsEnv
currently rereads ~/.claude/settings.json on every call causing duplicate I/O
when invoked by checkClaudeCredentials and mapCliOptionsToSDK; add a simple
module-level cache (e.g., cachedEnv and cachedAt) and a TTL (e.g., 1–5 seconds)
so loadClaudeSettingsEnv returns the cached env if cachedAt is recent, otherwise
reads the file, updates cachedEnv and cachedAt, and returns the result; preserve
current error swallowing and fallback-to-empty behavior and ensure cache stores
the parsed settings.env object (or {}).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@server/utils/env-helpers.js`:
- Around line 25-38: loadClaudeSettingsEnv currently rereads
~/.claude/settings.json on every call causing duplicate I/O when invoked by
checkClaudeCredentials and mapCliOptionsToSDK; add a simple module-level cache
(e.g., cachedEnv and cachedAt) and a TTL (e.g., 1–5 seconds) so
loadClaudeSettingsEnv returns the cached env if cachedAt is recent, otherwise
reads the file, updates cachedEnv and cachedAt, and returns the result; preserve
current error swallowing and fallback-to-empty behavior and ensure cache stores
the parsed settings.env object (or {}).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 9b153b0b-0d85-4f7b-8e2e-f789649eb8c5

📥 Commits

Reviewing files that changed from the base of the PR and between 181cf5c and 93079f7.

📒 Files selected for processing (4)
  • server/claude-sdk.js
  • server/routes/cli-auth.js
  • server/utils/env-helpers.js
  • src/components/settings/hooks/useSettingsController.ts

@blackmammoth blackmammoth requested a review from viper151 March 16, 2026 11:43
@viper151
Copy link
Contributor

@tintnc can you look at the PR again and the claude agent sdk requirements for env variables?
There are some env variables you have added in the .env.example that are not needed at all
like for example the below. I'd suggest that you look first at the claude agent sdk docs and try to correct your implementation

AWS_ACCESS_KEY_ID=your-access-key-id

AWS_SECRET_ACCESS_KEY=your-secret-access-key

Once you are done, please put your PR back to open so we can have a look at it.

@viper151 viper151 marked this pull request as draft March 16, 2026 16:14
@tintnc tintnc force-pushed the feat/aws_bedrock_support branch from cd67122 to d5cd3d4 Compare March 17, 2026 15:56
@tintnc tintnc marked this pull request as ready for review March 17, 2026 15:56
@tintnc
Copy link
Author

tintnc commented Mar 17, 2026

Thanks @viper151, I have updated accordingly for what need to be used on the .env.example

Copy link
Contributor

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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.env.example:
- Around line 58-63: Remove the unused AWS_BEARER_TOKEN_BEDROCK entry and its
explanatory comment from .env.example: delete the line defining
AWS_BEARER_TOKEN_BEDROCK and any lines that suggest using a bearer token for
Bedrock authentication, and ensure the remaining comments reference only
standard AWS SDK auth (e.g., AWS_REGION, AWS_PROFILE,
AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY or IAM roles) and the
CLAUDE_CODE_USE_BEDROCK flag so users are not misled about supported
authentication methods.

In `@server/claude-sdk.js`:
- Around line 478-504: In resolveClaudeModel, a user-supplied options.model
passed as modelAlias can be overridden by environment-derived explicitModel when
bedrock is enabled; to fix, add an early check in resolveClaudeModel that if
modelAlias is truthy and not one of the special alias tokens
('haiku','opus','opusplan','sonnet','sonnet[1m]') then return modelAlias
(requestedModel) immediately so a direct CLI/API model selection always has
highest precedence before falling back to explicitModel, explicitFastModel,
sonnetDefault, opusDefault, or haikuDefault.

In `@server/routes/cli-auth.js`:
- Around line 127-130: The bedrock enablement check is duplicated (the local
bedrockEnabled variable using isTruthyValue and settingsEnv) and should be
centralized: add a new helper function isBedrockEnabled(settingsEnv = {}) in
server/utils/env-helpers.js that returns the existing expression
(isTruthyValue(process.env.CLAUDE_CODE_USE_BEDROCK) ||
isTruthyValue(settingsEnv.CLAUDE_CODE_USE_BEDROCK)), then update the usage in
server/routes/cli-auth.js (replace the bedrockEnabled declaration) and in
server/claude-sdk.js (replace the resolver’s bedrock check) to import and call
isBedrockEnabled so both files rely on the same implementation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 7a45a4d5-833a-41ba-8b82-c6ce7a5b3d66

📥 Commits

Reviewing files that changed from the base of the PR and between cd67122 and 74d43fb.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (8)
  • .env.example
  • server/claude-sdk.js
  • server/routes/cli-auth.js
  • server/utils/env-helpers.js
  • src/components/settings/constants/constants.ts
  • src/components/settings/hooks/useSettingsController.ts
  • src/components/settings/types/types.ts
  • src/components/settings/view/tabs/agents-settings/sections/content/AccountContent.tsx
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/components/settings/types/types.ts
  • server/utils/env-helpers.js
  • src/components/settings/hooks/useSettingsController.ts

Comment on lines +127 to +130
// Priority 0: Bedrock mode bypasses Claude OAuth checks.
const bedrockEnabled = isTruthyValue(process.env.CLAUDE_CODE_USE_BEDROCK)
|| isTruthyValue(settingsEnv.CLAUDE_CODE_USE_BEDROCK);
if (bedrockEnabled) {
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Bedrock enablement logic is duplicated and can diverge from SDK behavior.

This inline check can drift from the resolver used in server/claude-sdk.js, causing status/UI to report Bedrock while SDK model resolution behaves differently. Centralize Bedrock detection in one shared helper and reuse it in both files.

Proposed fix
-import { isTruthyValue, loadClaudeSettingsEnv } from '../utils/env-helpers.js';
+import { isBedrockEnabled, loadClaudeSettingsEnv } from '../utils/env-helpers.js';
@@
-  const bedrockEnabled = isTruthyValue(process.env.CLAUDE_CODE_USE_BEDROCK)
-    || isTruthyValue(settingsEnv.CLAUDE_CODE_USE_BEDROCK);
+  const bedrockEnabled = isBedrockEnabled(settingsEnv);
// server/utils/env-helpers.js
export function isBedrockEnabled(settingsEnv = {}) {
  return isTruthyValue(process.env.CLAUDE_CODE_USE_BEDROCK)
    || isTruthyValue(settingsEnv.CLAUDE_CODE_USE_BEDROCK);
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/routes/cli-auth.js` around lines 127 - 130, The bedrock enablement
check is duplicated (the local bedrockEnabled variable using isTruthyValue and
settingsEnv) and should be centralized: add a new helper function
isBedrockEnabled(settingsEnv = {}) in server/utils/env-helpers.js that returns
the existing expression (isTruthyValue(process.env.CLAUDE_CODE_USE_BEDROCK) ||
isTruthyValue(settingsEnv.CLAUDE_CODE_USE_BEDROCK)), then update the usage in
server/routes/cli-auth.js (replace the bedrockEnabled declaration) and in
server/claude-sdk.js (replace the resolver’s bedrock check) to import and call
isBedrockEnabled so both files rely on the same implementation.

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.

2 participants