Skip to content

fix: prioritize ANTHROPIC_MODEL env var over settings.model in model …#505

Merged
benbrandt merged 1 commit intoagentclientprotocol:mainfrom
soddygo:main
Apr 6, 2026
Merged

fix: prioritize ANTHROPIC_MODEL env var over settings.model in model …#505
benbrandt merged 1 commit intoagentclientprotocol:mainfrom
soddygo:main

Conversation

@soddygo
Copy link
Copy Markdown
Contributor

@soddygo soddygo commented Apr 4, 2026

Title:
fix: ANTHROPIC_MODEL env var not respected in ACP agent model selection

Body:

Summary

The ANTHROPIC_MODEL environment variable is not being respected when using Claude Code via the ACP (Agent Client Protocol). This causes users who set their preferred model via
environment variable to have their setting ignored, with the default model (claude-sonnet-4-6) being used instead.

Problem

When using Claude Code through ACP integrations (e.g., agent platforms), users expect the ANTHROPIC_MODEL environment variable to control which model is used for LLM requests.
However, the current implementation only checks settings.model (from configuration files) and completely ignores ANTHROPIC_MODEL.

Root Cause

In src/acp-agent.ts, the getAvailableModels function only checks settings.model:

let currentModel = models[0];

if (settings.model) {                                                                                                                                                              
  const match = resolveModelPreference(models, settings.model);
  if (match) {                                                                                                                                                                     
    currentModel = match;                                       
  }
}

The ANTHROPIC_MODEL environment variable is never read, so environment-based model configuration is silently ignored.                                                              
 
Reproduction                                                                                                                                                                       
                                                                
1. Set ANTHROPIC_MODEL=glm-4.7 (or any custom model)                                                                                                                               
2. Start Claude Code via ACP protocol
3. Send a prompt request                                                                                                                                                           
4. Capture network traffic - the actual model used is claude-sonnet-4-6 instead of glm-4.7
                                                                                                                                                                                   
Fix
                                                                                                                                                                                   
Added priority-based model selection that respects the ANTHROPIC_MODEL environment variable, aligning with the main Claude Code CLI behavior:                                      
 
// Model priority (highest to lowest):                                                                                                                                             
// 1. ANTHROPIC_MODEL environment variable                      
// 2. settings.model (user configuration)
// 3. models[0] (default first model)                                                                                                                                              
if (process.env.ANTHROPIC_MODEL) {
  const match = resolveModelPreference(models, process.env.ANTHROPIC_MODEL);                                                                                                       
  if (match) {                                                  
    currentModel = match;
  }
} else if (settings.model) {
  const match = resolveModelPreference(models, settings.model);                                                                                                                    
  if (match) {
    currentModel = match;                                                                                                                                                          
  }                                                             
}

This matches the model selection priority used by the main Claude Code CLI.                                                                                                        
 
Testing                                                                                                                                                                            
                                                                
- Verified ANTHROPIC_MODEL is now respected when set                                                                                                                               
- Verified settings.model still works when ANTHROPIC_MODEL is not set
- Verified default model (models[0]) is used when neither is set                                                                                                                   
                                                                                                                                                                                   
Breaking Change
                                                                                                                                                                                   
None - this fix makes behavior more consistent with user expectations and the main CLI.                                                                                            
 

…selection

The getAvailableModels function was not checking the ANTHROPIC_MODEL
environment variable, causing it to be ignored when users set model via
environment variables. This aligns with the main Claude Code CLI behavior
where ANTHROPIC_MODEL takes priority over settings.model.

Model priority (highest to lowest):
1. ANTHROPIC_MODEL environment variable
2. settings.model (user configuration)
3. models[0] (default first model)
@soddygo
Copy link
Copy Markdown
Contributor Author

soddygo commented Apr 4, 2026

I noticed this problem was already reported by another user at #504 - this appears to be the same issue.

Copy link
Copy Markdown
Member

@benbrandt benbrandt left a comment

Choose a reason for hiding this comment

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

thanks!

@benbrandt benbrandt enabled auto-merge (squash) April 6, 2026 19:48
@benbrandt benbrandt merged commit bea1a40 into agentclientprotocol:main Apr 6, 2026
1 check passed
benbrandt pushed a commit that referenced this pull request Apr 6, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.25.2](v0.25.1...v0.25.2)
(2026-04-06)


### Bug Fixes

* prioritize ANTHROPIC_MODEL env var over settings.model in model …
([#505](#505))
([bea1a40](bea1a40))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: acp-release-bot[bot] <246668977+acp-release-bot[bot]@users.noreply.github.com>
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