Support Anthropic-compatible base URL override - #336
Conversation
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>
WalkthroughAdds a new ChangesCLAUDE_ANTHROPIC_BASE_URL support
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
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
📒 Files selected for processing (4)
README.mdralph_loop.shtemplates/ralphrc.templatetests/unit/test_cli_modern.bats
| # 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 | ||
|
|
There was a problem hiding this comment.
🎯 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:
- 1: https://github.com/ytrofr/claude-code-guide/blob/main/docs/guide/part6-reference/02-cli-flags-and-env.md
- 2: https://code.claude.com/docs/en/cli-reference
- 3: https://code.claude.com/docs/en/env-vars
- 4: https://code.claude.com/docs/en/llm-gateway-connect
- 5: https://claude-codex.fr/en/reference/environment/
- 6: https://fazm.ai/blog/route-claude-api-through-custom-endpoint-anthropic-base-url
- 7: https://www.requesty.ai/blog/claude-code-environment-variables-anthropic-base-url-auth-token
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.
|
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 |
Summary
CLAUDE_ANTHROPIC_BASE_URLconfiguration for custom Anthropic-compatible endpoints..ralphrcvalues..ralphrctemplate.Test plan
npm test