Skip to content

Conversation

@sahksas
Copy link

@sahksas sahksas commented Jun 18, 2025

Related GitHub Issue

Closes: #4842

Description

Test Procedure

Type of Change

  • πŸ› Bug Fix: Non-breaking change that fixes an issue.
  • ✨ New Feature: Non-breaking change that adds functionality.
  • πŸ’₯ Breaking Change: Fix or feature that would cause existing functionality to not work as expected.
  • ♻️ Refactor: Code change that neither fixes a bug nor adds a feature.
  • πŸ’… Style: Changes that do not affect the meaning of the code (white-space, formatting, etc.).
  • πŸ“š Documentation: Updates to documentation files.
  • βš™οΈ Build/CI: Changes to the build process or CI configuration.
  • 🧹 Chore: Other changes that don't modify src or test files.

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Code Quality:
    • My code adheres to the project's style guidelines.
    • There are no new linting errors or warnings (npm run lint).
    • All debug code (e.g., console.log) has been removed.
  • Testing:
    • New and/or updated tests have been added to cover my changes.
    • All tests pass locally (npm test).
    • The application builds successfully with my changes.
  • Branch Hygiene: My branch is up-to-date (rebased) with the main branch.
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Changeset: A changeset has been created using npm run changeset if this PR includes user-facing changes or dependency updates.
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

Documentation Updates

Additional Notes

All tests have passed, but I have only been able to check the operation in my environment. If possible, please check it in another environment.

Get in Touch


Arigato~ πŸ™πŸ» cline/cline#4111


Important

Integrates Claude Code CLI into Roo Code, adding local execution support, configuration options, documentation, and tests.

  • Behavior:
    • Integrates Claude Code CLI into Roo Code, allowing local execution of Claude Code models.
    • Adds ClaudeCodeHandler to handle Claude Code CLI interactions in src/api/providers/claude-code.ts.
    • Supports model selection, streaming responses, and usage tracking.
  • Configuration:
    • Adds claudeCodePath configuration option in provider-settings.ts for specifying the CLI path.
    • Updates ApiOptions.tsx and ClaudeCode.tsx to include Claude Code settings in the UI.
  • Documentation:
    • Adds claude-code-integration.md detailing setup and usage of Claude Code CLI.
  • Testing:
    • Includes tests for ClaudeCodeHandler in claude-code.spec.ts and CLI execution in run.spec.ts.
  • Localization:
    • Updates localization files to include Claude Code settings descriptions in multiple languages.

This description was created by Ellipsis for 51fe529. You can customize this summary. It will automatically update as commits are pushed.

@sahksas sahksas marked this pull request as ready for review June 18, 2025 17:17
@sahksas sahksas requested review from cte, jr and mrubens as code owners June 18, 2025 17:17
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. documentation Improvements or additions to documentation enhancement New feature or request labels Jun 18, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jun 18, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Jun 18, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Jun 18, 2025
Copy link
Collaborator

@hannesrudolph hannesrudolph left a comment

Choose a reason for hiding this comment

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

Thanks for this contribution! The Claude Code CLI integration is a valuable addition that allows users to run Claude models locally without an API key.

Overall Assessment

The implementation follows the existing provider patterns well and includes comprehensive test coverage. The code quality is good, but there are several issues that need attention before merging.

Critical Issues

  1. Potential infinite loop in the main message processing loop
  2. Missing error handling for CLI binary execution failures
  3. Unused parameter in the API interface

Important Considerations

  1. Process cleanup: No mechanism to terminate Claude processes on cancellation
  2. Incomplete i18n: Only Japanese translations provided
  3. Unimplemented TODO: Session support mentioned but not implemented

Positive Aspects

βœ… Well-structured code following existing patterns
βœ… Comprehensive unit test coverage
βœ… Good documentation
βœ… Proper TypeScript typing
βœ… Streaming response handling

Recommendations

  1. Fix the critical issues, especially the potential infinite loop
  2. Add error handling for CLI execution
  3. Complete i18n translations for all supported languages
  4. Consider implementing process cleanup for better resource management
  5. Either implement session support or remove the TODO comment

Once these issues are addressed, this will be a great addition to Roo Code!

async *createMessage(
systemPrompt: string,
messages: Anthropic.Messages.MessageParam[],
metadata?: ApiHandlerCreateMessageMetadata,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Type Safety: The metadata parameter is accepted but never used. Is this intentional for API compatibility?

If it's not needed for Claude Code, consider either:

  1. Using it if there's relevant metadata to process
  2. Adding a comment explaining why it's unused
  3. Removing it if the interface allows
// @ts-expect-error - metadata not used for Claude Code CLI integration
metadata?: ApiHandlerCreateMessageMetadata,

Copy link
Author

Choose a reason for hiding this comment

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

rm unnecessary 24aea3b

Copy link
Member

Choose a reason for hiding this comment

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

Seems like it got readded on c5a846f934ca8fbc8bededcab6cc91f184289027

- Added claudeCodePath and claudeCodePathDescription translations
- Covers all supported languages: ca, de, en, es, fr, hi, id, it, ja, ko, nl, pl, pt-BR, ru, tr, vi, zh-CN, zh-TW
- Addresses PR review feedback
@hannesrudolph
Copy link
Collaborator

βœ… Added missing translations for all locales

I've implemented the Claude Code translations (claudeCodePath and claudeCodePathDescription) for all 18 supported languages. The changes have been pushed in commit bfd0716.

This addresses the i18n coverage issue from the review.

@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Jun 19, 2025
@sahksas sahksas marked this pull request as draft June 19, 2025 11:31
@sahksas sahksas marked this pull request as ready for review June 19, 2025 12:29
sahksas and others added 2 commits June 19, 2025 21:33
Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
@sahksas
Copy link
Author

sahksas commented Jun 19, 2025

@hannesrudolph
Thank you for taking the time to review my PR!
You're absolutely right on all points. I've updated the code according to your feedback.

@sahksas sahksas requested a review from hannesrudolph June 19, 2025 13:08
daniel-lxs

This comment was marked as outdated.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jun 19, 2025
@daniel-lxs daniel-lxs dismissed their stale review June 19, 2025 21:06

accidentally approved

Copy link
Member

@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 @sahksas!

I've left a few comments on the PR with some suggestions for improvement. Overall, this is a great addition, and I appreciate the detailed implementation!

validateMessageContent(content)

promptText += `${role}: ${content}\n\n`
}
Copy link
Member

Choose a reason for hiding this comment

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

The current implementation converts messages to plain text format, but this seems inconsistent with the original approach.

The comment on line 117 states "Claude CLI doesn't accept JSON messages", but looking at the original implementation pattern, it appears the CLI should accept JSON-formatted messages. The current text conversion approach:

  1. Loses message structure and metadata
  2. Makes it harder to handle complex message types
  3. Differs from how other providers handle messages

Could you verify if the Claude Code CLI actually requires text format? If it does accept JSON, consider reverting to:

const args = [
  "-p",
  JSON.stringify(messages),
  "--system-prompt",
  systemPrompt,
  // ... other args
]

This would also simplify the validation logic since JSON.stringify handles escaping automatically.

Copy link
Author

Choose a reason for hiding this comment

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

@daniel-ks You're absolutely right! I've reverted to using JSON format as suggested: ed046eb

  • Removed the plain text conversion logic
  • Now using the existing safeSerializeMessages function
  • Updated CLI arguments to properly pass JSON messages

Thanks for catching this inconsistency and providing the clear solution!

}) {
const claudePath = path || "claude"
const workspacePath = getCwd()
const sessionId = SessionManager.getSessionId(workspacePath)
Copy link
Member

Choose a reason for hiding this comment

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

Nice work on implementing the SessionManager, it looks solid overall. One thing though: the session ID you're generating isn't actually passed to the Claude CLI, so each call ends up being treated as a new conversation. That could impact:

  • Performance (no context reuse)
  • User experience (no conversation continuity)

It looks like session management wasn't added to Cline’s implementation yet. From their notes:

I didn't implement sessions because it seems overly complex.
We have to store session IDs somewhere within the tasks (or messages), and handle tasks where the user changes the provider.
On the other hand, the current implementation works well (at least with the simple tasks I've been giving it).
We can rethink this if users raise issues.

That said, you actually can get a task-specific ID from the metadata parameter in the createMessage method, and pass that to the Claude CLI. Something like this:

// In src/api/providers/claude-code.ts
async *createMessage(
    systemPrompt: string,
    messages: Anthropic.Messages.MessageParam[],
    metadata?: ApiHandlerCreateMessageMetadata,
): ApiStream {
    // The taskId is available here:
    const taskId = metadata?.taskId

    // You can then pass it to runClaudeCode
}

The metadata type includes:

  • taskId: string - the unique task ID, which could double as a session ID
  • mode?: string - current mode
  • signal?: AbortSignal - cancellation support

So you've already got the foundation in place. You could either hook that task ID into the CLI call (if sessions are supported), or skip the SessionManager for now and revisit later if needed.

Let me know what you think!

Copy link
Author

Choose a reason for hiding this comment

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

@daniel-lxs

Thank you for your thoughtful review.

You're absolutely right that including session management implementation in this PR would make the scope too large. Even the basic state management and persistence would require careful design considerations, and when we factor in UX improvements like session state visualization and performance optimization, it becomes a project-wide change with significant impact.

I've created a separate issue (#4934 ) to address comprehensive session management, and we'll tackle that there.

For this PR, I'd like to limit the scope to implementing the foundational part of your suggestion (extracting taskId from metadata and passing it to Claude CLI).

Copy link
Author

Choose a reason for hiding this comment

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

@daniel-lxs

Thank you for your valuable review comments.
I apologize for my insufficient understanding and for creating an inappropriate issue.

I have implemented the improvements you suggested: c853ea0

  • Functionality to use taskId as session identifier and pass it to Claude CLI's -r option
  • Practical session management with safe error handling

This implementation should achieve efficient session management at the Claude CLI level.
Thank you for your technically accurate suggestions.

role: "assistant"
model: string
content: ClaudeCodeContent[]
stop_reason: null
Copy link
Member

Choose a reason for hiding this comment

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

The stop_reason field is typed as null, but based on the error handling in claude-code.ts, it can also be a string value (e.g., "error").

This type definition could cause runtime errors. Consider updating to:

stop_reason: string | null

This would properly handle cases where Claude returns error reasons or other stop conditions.

Copy link
Author

Choose a reason for hiding this comment

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

fixed 4b5fe06

@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Changes Requested] in Roo Code Roadmap Jun 19, 2025
@heyseth
Copy link
Contributor

heyseth commented Jun 21, 2025

Excited for this integration! :--)

@avi12
Copy link

avi12 commented Jun 23, 2025

IMO this PR shouldn't solely focus on a Claude Code integration, but also generalize it to support competing pieces of software like Codex

@sahksas
Copy link
Author

sahksas commented Jun 26, 2025

Closing this PR as the Claude Code integration feature has already been implemented and merged through PR #4864 and PR #5038, and is now available in release v3.21.4.

@sahksas sahksas closed this Jun 26, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jun 26, 2025
@github-project-automation github-project-automation bot moved this from PR [Changes Requested] to Done in Roo Code Roadmap Jun 26, 2025
@sahksas sahksas mentioned this pull request Jun 26, 2025
5 tasks
@daniel-lxs
Copy link
Member

Thank you @sahksas for your contribution. It's genuinely appreciated, and I'm looking forward to more from you in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request lgtm This PR has been approved by a maintainer PR - Changes Requested size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Integrate Claude Code

5 participants