[BUG] ANTHROPIC_DEFAULT_*_MODEL aliases are ignored with a custom ANTHROPIC_BASE_URL
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report
- [x] I am using the latest version of Claude Code
What's Wrong?
When Claude Code uses an Anthropic-compatible LLM gateway through ANTHROPIC_BASE_URL, the documented ANTHROPIC_DEFAULT_FABLE_MODEL, ANTHROPIC_DEFAULT_OPUS_MODEL, ANTHROPIC_DEFAULT_SONNET_MODEL, and ANTHROPIC_DEFAULT_HAIKU_MODEL variables do not control their corresponding aliases.
Capturing only the model field of outgoing request bodies with a loopback HTTP listener shows:
| CLI selection | Configured value | Model actually sent |
| --- | --- | --- |
| --model fable | custom/fable | claude-fable-5 |
| --model opus | custom/opus | claude-opus-5 |
| --model sonnet | custom/sonnet | claude-sonnet-5 |
| --model haiku | custom/haiku | claude-haiku-4-5 |
The built-in model IDs are selected before the request reaches the gateway, so the behavior does not depend on a particular gateway implementation.
This also affects internal requests that use these model families. For example, background Haiku requests and the auto-mode safety classifier can send built-in model IDs that a gateway cannot route, even though gateway-specific IDs were configured. When the classifier request fails, auto mode fails closed and blocks tool calls that require classification.
What Should Happen?
Each family alias should resolve to the corresponding documented environment-variable value before Claude Code sends the request:
fable->ANTHROPIC_DEFAULT_FABLE_MODELopus->ANTHROPIC_DEFAULT_OPUS_MODELsonnet->ANTHROPIC_DEFAULT_SONNET_MODELhaikuand background functionality ->ANTHROPIC_DEFAULT_HAIKU_MODEL
This is especially important with ANTHROPIC_BASE_URL, where the gateway defines its own model identifiers. The current model configuration documentation says these variables control the model names that aliases map to.
Error Messages/Logs
There is no client-side configuration error. The loopback listener observes the built-in model IDs listed above instead of the configured values. A gateway that does not recognize those built-in IDs then returns its normal model-not-found response.
Steps to Reproduce
- Start a loopback HTTP server that accepts POST requests and prints only the JSON body's
modelfield. For example:
```python
import json
from http.server import BaseHTTPRequestHandler, HTTPServer
class Handler(BaseHTTPRequestHandler):
def do_POST(self):
length = int(self.headers.get('content-length', '0'))
body = json.loads(self.rfile.read(length))
print(self.path, body.get('model'), flush=True)
self.send_response(400)
self.send_header('content-type', 'application/json')
self.end_headers()
self.wfile.write(
b'{"type":"error","error":{"type":"invalid_request_error","message":"captured"}}'
)
def log_message(self, *args):
pass
HTTPServer(('127.0.0.1', 8765), Handler).serve_forever()
```
- In another shell, set a synthetic credential, the loopback base URL, and distinct model IDs:
``shell``
export ANTHROPIC_AUTH_TOKEN=test-token
export ANTHROPIC_BASE_URL=http://127.0.0.1:8765
export ANTHROPIC_DEFAULT_FABLE_MODEL=custom/fable
export ANTHROPIC_DEFAULT_OPUS_MODEL=custom/opus
export ANTHROPIC_DEFAULT_SONNET_MODEL=custom/sonnet
export ANTHROPIC_DEFAULT_HAIKU_MODEL=custom/haiku
- Run each alias in a fresh non-persistent invocation:
``shell``
claude -p --no-session-persistence --model fable 'Reply with ok'
claude -p --no-session-persistence --model opus 'Reply with ok'
claude -p --no-session-persistence --model sonnet 'Reply with ok'
claude -p --no-session-persistence --model haiku 'Reply with ok'
- Observe that the listener receives the built-in model IDs instead of
custom/fable,custom/opus,custom/sonnet, andcustom/haiku.
Claude Model
Multiple models
Is this a regression?
I don't know.
Claude Code Version
2.1.260 (Claude Code)
Platform
Other: Anthropic-compatible LLM gateway through ANTHROPIC_BASE_URL
Operating System
macOS
Terminal/Shell
zsh
Additional Information
Claude Code's model configuration documentation says these variables control the model names that the family aliases map to.
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗