Skip to content

Support Anthropic-compatible base URL override - #336

Closed
octo-patch wants to merge 2 commits into
frankbria:mainfrom
octo-patch:octopatch/minimax-provider-recvoLiru6kgr0
Closed

Support Anthropic-compatible base URL override#336
octo-patch wants to merge 2 commits into
frankbria:mainfrom
octo-patch:octopatch/minimax-provider-recvoLiru6kgr0

Conversation

@octo-patch

@octo-patch octo-patch commented Jul 9, 2026

Copy link
Copy Markdown

Summary

  • Add CLAUDE_ANTHROPIC_BASE_URL configuration for custom Anthropic-compatible endpoints.
  • Preserve environment-variable precedence over .ralphrc values.
  • Document the setting in the README and generated .ralphrc template.

Test plan

  • npm test

Allow Ralph users to point Claude Code at custom Anthropic-compatible endpoints while preserving environment-over-.ralphrc precedence.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Adds a new CLAUDE_ANTHROPIC_BASE_URL configuration variable across ralph_loop.sh, .ralphrc template, and README, enabling an override of the Anthropic-compatible API base URL. Includes environment/.ralphrc precedence handling, conditional --anthropic-base-url CLI argument construction, and corresponding unit test coverage.

Changes

CLAUDE_ANTHROPIC_BASE_URL support

Layer / File(s) Summary
Core script: env capture, default, load, and CLI arg wiring
ralph_loop.sh
Captures env value before defaults, sets CLAUDE_ANTHROPIC_BASE_URL default (empty), restores env value in load_ralphrc() for precedence, and conditionally appends --anthropic-base-url in build_claude_command().
Documentation and template updates
README.md, templates/ralphrc.template
Adds commented documentation and example configuration snippet for the new base URL override.
Unit tests for env precedence and CLI arg emission
tests/unit/test_cli_modern.bats
Mirrors env capture/restore and argument-building logic, and adds tests for .ralphrc loading, env-var precedence, and inclusion/omission of --anthropic-base-url.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • frankbria/ralph-claude-code#191: Both PRs extend ralph_loop.sh and tests/unit/test_cli_modern.bats for .ralphrc-driven Claude CLI command construction.
  • frankbria/ralph-claude-code#231: Both PRs extend .ralphrc/environment precedence and build_claude_command flag construction in the same core loading/command-building code paths.

Poem

A rabbit typed a URL so neat,
Tucked into .ralphrc, tidy and sweet,
"--anthropic-base-url" hops into place,
Env vars win the precedence race,
Tests confirm it, snug and complete! 🐇🔗

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding an override for the Anthropic-compatible base URL.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 `@ralph_loop.sh`:
- Around line 1565-1569: The Claude CLI base URL override is being passed as an
unsupported command-line flag, so update the custom-provider handling in the
shell logic around the CLAUDE_CMD_ARGS construction to use the
ANTHROPIC_BASE_URL process environment variable instead. Keep the existing
CLAUDE_ANTHROPIC_BASE_URL input, but export/map it into the environment before
launching Claude rather than appending "--anthropic-base-url" to the argv array,
so startup works with custom endpoints.
🪄 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: 8d9254f4-02e2-4aee-be86-e97b4db97254

📥 Commits

Reviewing files that changed from the base of the PR and between 0c1d7bf and 2c07885.

📒 Files selected for processing (4)
  • README.md
  • ralph_loop.sh
  • templates/ralphrc.template
  • tests/unit/test_cli_modern.bats

Comment thread ralph_loop.sh
Comment on lines +1565 to +1569
# Add Anthropic-compatible API base URL override (for custom providers)
if [[ -n "${CLAUDE_ANTHROPIC_BASE_URL:-}" ]]; then
CLAUDE_CMD_ARGS+=("--anthropic-base-url" "$CLAUDE_ANTHROPIC_BASE_URL")
fi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check if the Claude CLI supports --anthropic-base-url
claude --help 2>&1 | grep -i "base-url\|anthropic" || echo "Flag not found in --help output"

Repository: frankbria/ralph-claude-code

Length of output: 197


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the relevant code path and any references to the env var/flag name.
rg -n "CLAUDE_ANTHROPIC_BASE_URL|anthropic-base-url|api-base-url|base-url" .

# Check the local Claude CLI help more directly for base-url-related options.
claude --help 2>&1 | sed -n '1,220p'

Repository: frankbria/ralph-claude-code

Length of output: 3100


🌐 Web query:

Claude Code CLI --anthropic-base-url option supported flag base url documentation

💡 Result:

Claude Code CLI does not provide a command-line flag named --anthropic-base-url [1][2]. Instead, custom API endpoints are configured exclusively via the ANTHROPIC_BASE_URL environment variable [3][4][5]. You can set this variable in your shell for a single session, as a persistent environment variable, or within the Claude Code settings file [4][5][6]. Configuration Methods: 1. Shell Environment (Temporary): export ANTHROPIC_BASE_URL=https://your-gateway.example.com export ANTHROPIC_AUTH_TOKEN=your-gateway-key 2. Settings File (Persistent): You can define the variable in your ~/.claude/settings.json file using an env block: { "env": { "ANTHROPIC_BASE_URL": "https://your-gateway.example.com", "ANTHROPIC_AUTH_TOKEN": "your-gateway-key" } } Key Details: - Purpose: ANTHROPIC_BASE_URL is used to point the CLI toward LLM gateways, corporate proxies, or local mock servers [4][5][6]. - Authentication: When using a custom base URL, you typically use ANTHROPIC_AUTH_TOKEN to provide the necessary authorization credentials instead of the standard ANTHROPIC_API_KEY [4][7]. - Priority: If both a shell export and a settings-file entry are present, the settings-file value generally takes precedence [4]. You can verify which URL is being used by running the /status command within the Claude Code CLI [4].

Citations:


Use ANTHROPIC_BASE_URL instead of --anthropic-base-url

Claude CLI doesn’t expose a --anthropic-base-url flag; custom endpoints need to be passed via ANTHROPIC_BASE_URL in the process environment (or settings file), otherwise custom-provider runs will fail at startup.

🤖 Prompt for 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.

In `@ralph_loop.sh` around lines 1565 - 1569, The Claude CLI base URL override is
being passed as an unsupported command-line flag, so update the custom-provider
handling in the shell logic around the CLAUDE_CMD_ARGS construction to use the
ANTHROPIC_BASE_URL process environment variable instead. Keep the existing
CLAUDE_ANTHROPIC_BASE_URL input, but export/map it into the environment before
launching Claude rather than appending "--anthropic-base-url" to the argv array,
so startup works with custom endpoints.

@octo-patch

Copy link
Copy Markdown
Author

Closing this PR because the provider registry required for this work item has not been implemented yet; its command-construction foundation is still tracked in #312. The current patch also relies on an unsupported --anthropic-base-url CLI flag, so it is not safe to merge as-is.

@octo-patch octo-patch closed this Jul 13, 2026
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.

1 participant