fix(llm): support ANTHROPIC_API_KEY as fallback in environment and shell RC resolution
Author: DevCop95Created Sep 17, 2026Updated Sep 18, 2026
OpenCodeReview Version
v1.12.4
Operating System
Windows / Linux / macOS
Installation Method
npm (global) / Built from source
LLM Provider
Anthropic (Claude)
Bug Description
When running ocr review with Anthropic credentials configured via environment variables (without ~/.opencodereview/config.json), OCR fails with:
Error: resolve LLM endpoint: no valid LLM endpoint configured; one of OCR_LLM_URL/OCR_LLM_TOKEN/OCR_LLM_MODEL, ~/.opencodereview/config.json, or ANTHROPIC_BASE_URL/ANTHROPIC_AUTH_TOKEN/ANTHROPIC_MODEL must be setIn internal/llm/resolver.go:
tryCCEnvandparseShellRConly check forANTHROPIC_AUTH_TOKENand ignoreANTHROPIC_API_KEY, even thoughANTHROPIC_API_KEYis the standard variable used across the Anthropic SDK, Claude ecosystem, and even in OCR's owninternal/llm/providers.go(EnvVar: "ANTHROPIC_API_KEY").tryCCEnvstrictly hardcodesAuthHeader: "authorization". WhenANTHROPIC_API_KEYis used, the header should bex-api-key.tryCCEnvandparseShellRCrequireANTHROPIC_BASE_URLto be explicitly set. For official Anthropic API usage,ANTHROPIC_BASE_URLis omitted and should default tohttps://api.anthropic.com.
Steps to Reproduce
- Set
ANTHROPIC_API_KEY="sk-..."andANTHROPIC_MODEL="claude-opus-4-6"(or proxyANTHROPIC_BASE_URL). Do not setANTHROPIC_AUTH_TOKEN. - Ensure no
~/.opencodereview/config.jsonexists. - Run
ocr review. - Observe the error:
resolve LLM endpoint: no valid LLM endpoint configured; one of ... must be set.
Expected Behavior
tryCCEnv and parseShellRC should fall back to ANTHROPIC_API_KEY when ANTHROPIC_AUTH_TOKEN is unset, default baseURL to https://api.anthropic.com if omitted, and use x-api-key auth header when authenticating with ANTHROPIC_API_KEY.
Proposed Fix
In internal/llm/resolver.go:
- In
tryCCEnv: fall back toANTHROPIC_API_KEYwhenANTHROPIC_AUTH_TOKENis unset, setauthHeader = "x-api-key", and defaultbaseURL = "https://api.anthropic.com". - In
parseShellRC: parseANTHROPIC_API_KEYexports and defaultbaseURL = "https://api.anthropic.com". - Unit tests added in
resolver_norm_test.goandresolver_shellrc_test.gocovering fallback, precedence, and default URL. All tests pass withgo test ./internal/llm.
Linked Pull Request: #1375 (Complete fix, unit tests, CLA signed, and CI checks passing).
Source: alibaba/open-code-review