Skip to content

feat(agent): support custom baseURL for Claude Code workspaces#543

Draft
MarsKubeX wants to merge 2 commits into
openkaiden:mainfrom
MarsKubeX:anthropic-base-url-support
Draft

feat(agent): support custom baseURL for Claude Code workspaces#543
MarsKubeX wants to merge 2 commits into
openkaiden:mainfrom
MarsKubeX:anthropic-base-url-support

Conversation

@MarsKubeX

Copy link
Copy Markdown
Contributor

When a model ID includes a base URL (provider::model::baseURL), write ANTHROPIC_BASE_URL into .claude/settings.json so Claude Code routes requests to the custom endpoint. This enables local inference engines (e.g. llama-server) and API proxies.

Part of openkaiden/kaiden#1855

When a model ID includes a base URL (provider::model::baseURL), write
ANTHROPIC_BASE_URL into .claude/settings.json so Claude Code routes
requests to the custom endpoint. This enables local inference engines
(e.g. llama-server) and API proxies.

Part of openkaiden/kaiden#1855

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Marcel Bertagnini <mbertagn@redhat.com>
@codecov

codecov Bot commented May 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@coderabbitai

coderabbitai Bot commented May 18, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Rate limit exceeded

@MarsKubeX has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 37 minutes and 1 second before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 335ae405-c8b4-4f97-b5e1-44a8dc657b7f

📥 Commits

Reviewing files that changed from the base of the PR and between 5140445 and 6fdea5b.

📒 Files selected for processing (2)
  • pkg/agent/claude.go
  • pkg/agent/claude_test.go
📝 Walkthrough

Walkthrough

SetModel method in claudeAgent now accepts a containerHost parameter to rewrite localhost-based Anthropic API base URLs to container DNS names. The implementation parses modelID, extracts the base URL component, and conditionally rewrites HTTP addresses via the containerurl package while preserving remote URLs. Test coverage validates all rewriting paths, conditional env block creation, and existing environment variable preservation.

Changes

Claude Agent Container Host URL Configuration

Layer / File(s) Summary
Container host URL rewriting implementation
pkg/agent/claude.go
Method signature updated to accept containerHost parameter; containerurl import added; SetModel extended to parse modelID format (model name and optional base URL), rewrite localhost addresses with containerHost, and store rewritten URL in config["env"]["ANTHROPIC_BASE_URL"].
URL rewriting test coverage
pkg/agent/claude_test.go
Existing TestClaude_SetModel_ProviderModelURLFormat enhanced to assert env["ANTHROPIC_BASE_URL"] contains host-rewritten URL. Added tests for localhost-to-container rewriting, remote HTTPS URL preservation, conditional env block omission when no base URL present, and existing environment variable preservation during ANTHROPIC_BASE_URL injection.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • openkaiden/kdn#392: Both PRs modify claudeAgent.SetModel to interpret modelID format in .claude/settings.json (PR #392 normalizes provider ::model[::url] format; this PR injects ANTHROPIC_BASE_URL via containerHost rewriting).
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title accurately describes the main change: adding support for custom baseURL configuration for Claude Code workspaces via the SetModel method.
Description check ✅ Passed The description is directly related to the changeset, explaining how model IDs with base URLs are now handled and the intended use cases for local inference engines and API proxies.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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


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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/agent/claude.go`:
- Around line 238-247: When baseURL is empty we must clear a stale
ANTHROPIC_BASE_URL in the model config so a previous custom endpoint doesn't
persist; in the function containing this block (e.g., SetModel / the code using
config and env variables in pkg/agent/claude.go) detect the case where baseURL
== "" and remove the ANTHROPIC_BASE_URL key from the env map (obtained from
config["env"]) if it exists, then write the env map back into config["env"];
keep the existing behavior when baseURL != "" that sets
env["ANTHROPIC_BASE_URL"] to the resolvedURL.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6982bde0-2f86-4324-aea5-6baa8a12186c

📥 Commits

Reviewing files that changed from the base of the PR and between d251318 and 5140445.

📒 Files selected for processing (2)
  • pkg/agent/claude.go
  • pkg/agent/claude_test.go

Comment thread pkg/agent/claude.go
If a pre-existing .claude/settings.json contains ANTHROPIC_BASE_URL
from a previous configuration, remove it when the new model ID does
not include a custom base URL to prevent unintended routing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Marcel Bertagnini <mbertagn@redhat.com>
@MarsKubeX MarsKubeX requested review from benoitf and feloy May 18, 2026 11:48
@MarsKubeX

Copy link
Copy Markdown
Contributor Author

@coderabbitai resolve

@coderabbitai

coderabbitai Bot commented May 18, 2026

Copy link
Copy Markdown
✅ Actions performed

Comments resolved. Approval is disabled; enable reviews.request_changes_workflow to allow explicit top-level @coderabbitai resolve or @coderabbitai approve commands.

@MarsKubeX MarsKubeX marked this pull request as draft May 19, 2026 09:23
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