Skip to content

Conversation

janaki-sasidhar
Copy link

@janaki-sasidhar janaki-sasidhar commented Jul 15, 2025

Closes: #

Roo Code Task Context (Optional)

Description

This PR adds support for Vertex AI model name formatting when using Claude Code with Vertex AI. The key changes include:

  • Utility Functions: Added convertModelNameForVertex() to convert model names from hyphen format (claude-sonnet-4-20250514) to @ format (claude-sonnet-4@20250514)
  • Environment Integration: Added getClaudeCodeModelId() helper that checks CLAUDE_CODE_USE_VERTEX environment variable
  • Provider Integration: Modified Claude Code provider to use the conversion function when Vertex AI is enabled
  • Test Coverage: Added comprehensive unit tests for both utility functions

The implementation ensures backward compatibility - when CLAUDE_CODE_USE_VERTEX is not set or false, model names remain unchanged.

Test Procedure

Unit Tests:

Run the new tests

npm test packages/types/src/providers/tests/claude-code.spec.ts

Manual Testing:

  1. Set CLAUDE_CODE_USE_VERTEX=true in environment
  2. Use Claude Code with any Claude model (e.g., claude-sonnet-4-20250514)
  3. Verify the model name is converted to claude-sonnet-4@20250514 in Vertex AI calls
  4. Set CLAUDE_CODE_USE_VERTEX=false and verify original format is preserved

Test Cases Covered:

  • ✅ Model name conversion with various Claude models
  • ✅ No conversion when Vertex flag is disabled
  • ✅ Handling of models without date patterns
  • ✅ Edge cases with date patterns in middle of string

Pre-Submission Checklist

  • Issue Linked: This addresses Vertex AI compatibility (feature request)
  • Scope: Changes focused on model name conversion for Vertex AI
  • Self-Review: Performed thorough self-review of implementation
  • Testing: Added comprehensive unit tests for new functions
  • Documentation Impact: No user-facing documentation changes needed
  • Contribution Guidelines: Read and followed contributor guidelines

Screenshots / Videos

N/A - This is a backend utility change with no UI impact.

Documentation Updates

  • No documentation updates are required.

This change is internal to the model name handling and doesn't affect user-facing APIs or configuration beyond the existing CLAUDE_CODE_USE_VERTEX environment variable.

Additional Notes

  • The conversion only affects the 8-digit date pattern at the end of model names (e.g., -20250514 → @20250514)
  • Backward compatible - no breaking changes to existing functionality
  • TypeScript diagnostic about process can be ignored as it's used consistently throughout the codebase

janaki-sasidhar and others added 2 commits July 15, 2025 14:17
- Add convertModelNameForVertex function to convert hyphen-date format to @Date format
- Add getClaudeCodeModelId helper function with useVertex parameter
- Add comprehensive tests for both utility functions
- Enables proper model name formatting when CLAUDE_CODE_USE_VERTEX is true

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Import and use getClaudeCodeModelId function in Claude Code handler
- Check CLAUDE_CODE_USE_VERTEX environment variable at runtime
- Convert model names to @Date format when Vertex AI is enabled
- Ensures proper model name formatting for Vertex AI compatibility

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 15, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jul 15, 2025
@dessitsvetkova
Copy link

This fixes an issue that prevents Claude Code to be used as API provider in Roo Code, when Claude is running with VertexAI keys. i hope it gets approved soon!

@daniel-lxs daniel-lxs moved this from Triage to Roomote/renovate BOT in Roo Code Roadmap Jul 15, 2025
@daniel-lxs daniel-lxs moved this from Roomote/renovate BOT to Triage in Roo Code Roadmap Jul 15, 2025
…mentation

- Add validation before type assertion in claude-code.ts to ensure model ID is valid
- Add comprehensive JSDoc comments for convertModelNameForVertex and getClaudeCodeModelId functions
- Extract regex pattern as named constant VERTEX_DATE_PATTERN for better maintainability
Copy link
Collaborator

@daniel-lxs daniel-lxs left a comment

Choose a reason for hiding this comment

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

Thank you @janaki-sasidhar!

LGTM

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jul 15, 2025
According to Claude Code docs, the env variable should be checked for value '1', not 'true'
Reference: https://docs.anthropic.com/en/docs/claude-code/google-vertex-ai#4-configure-claude-code
@daniel-lxs
Copy link
Collaborator

Fixed the environment variable check - CLAUDE_CODE_USE_VERTEX should be checked for value "1" not "true" as per the Claude Code documentation.

@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Review] in Roo Code Roadmap Jul 15, 2025
@mrubens mrubens merged commit 9db64de into RooCodeInc:main Jul 15, 2025
11 checks passed
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Jul 15, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jul 15, 2025
@hannesrudolph hannesrudolph added PR - Needs Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Jul 15, 2025
fxcl added a commit to tameslabs/Roo-Cline that referenced this pull request Jul 16, 2025
* main:
  fix: Resolve confusing auto-approve checkbox states (RooCodeInc#5602)
  fix: prevent empty mode names from being saved (RooCodeInc#5766) (RooCodeInc#5794)
  Format time in ISO 8601 (RooCodeInc#5793)
  fix: resolve DirectoryScanner memory leak and improve file limit handling (RooCodeInc#5785)
  Fix settings dirty check (RooCodeInc#5779)
  feat: increase Ollama API timeout values and extract as constants (RooCodeInc#5778)
  fix: Exclude Terraform and Terragrunt cache directories from checkpoints (RooCodeInc#4601) (RooCodeInc#5750)
  Move less commonly used provider settings into an advanced dropdown (RooCodeInc#5762)
  feat: Add configurable error & repetition limit with unified control (RooCodeInc#5654) (RooCodeInc#5752)
  list-files must include at least the first-level directory contents (RooCodeInc#5303)
  Update evals repo link (RooCodeInc#5758)
  Feature/vertex ai model name conversion (RooCodeInc#5728)
  fix(litellm): handle baseurl with paths correctly (RooCodeInc#5697)
  Add telemetry for todos (RooCodeInc#5746)
  feat: add undo functionality for enhance prompt feature (fixes RooCodeInc#5741) (RooCodeInc#5742)
  Fix max_tokens limit for moonshotai/kimi-k2-instruct on Groq (RooCodeInc#5740)
  Changeset version bump (RooCodeInc#5735)
  Add changeset for v3.23.12 patch release (RooCodeInc#5734)
  Update the max-token calculation in model-params to use the shared logic (RooCodeInc#5720)
  Changeset version bump (RooCodeInc#5719)
  chore: add changeset for v3.23.11 patch release (RooCodeInc#5718)
  Add Kimi K2 model and better support (RooCodeInc#5717)
  Fix: Remove invalid skip-checkout parameter from GitHub Actions workflows (RooCodeInc#5676)
  feat: add Cmd+Shift+. keyboard shortcut for previous mode switching (RooCodeInc#5695)
  Changeset version bump (RooCodeInc#5708)
  chore: add changeset for v3.23.10 patch release (RooCodeInc#5707)
  Add padding to the index model options (RooCodeInc#5706)
  fix: prioritize built-in model dimensions over custom dimensions (RooCodeInc#5705)
  Update CHANGELOG.md
  Changeset version bump (RooCodeInc#5702)
  chore: add changeset for v3.23.9 patch release (RooCodeInc#5701)
  Tweaks to command timeout error (RooCodeInc#5700)
  Update contributors list (RooCodeInc#5639)
  feat: enable Claude Code provider to run natively on Windows (RooCodeInc#5615)
  feat: Add configurable timeout for command execution (RooCodeInc#5668)
  feat: add gemini-embedding-001 model to code-index service (RooCodeInc#5698)
  fix: resolve vector dimension mismatch error when switching embedding models (RooCodeInc#5616) (RooCodeInc#5617)
  fix: [5424] return the cwd in the exec tool's response so that the model is not lost after subsequent calls (RooCodeInc#5667)
  Changeset version bump (RooCodeInc#5670)
  chore: add changeset for v3.23.8 patch release (RooCodeInc#5669)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm This PR has been approved by a maintainer PR - Needs Review size:M This PR changes 30-99 lines, ignoring generated files.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants