-
Notifications
You must be signed in to change notification settings - Fork 2.6k
integrate claude code #4846
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
integrate claude code #4846
Changes from 5 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
6aa8c54
integrate claude code
sahksas 6cf5ca7
refactor
sahksas c0afb00
add test
sahksas 7b33bd5
update docs
sahksas 05874c1
fix platform-unit-test error
sahksas bfd0716
fix: add missing Claude Code translations for all locales
hannesrudolph a817985
fix infinity loop
sahksas a427fb9
add error handling
sahksas 24aea3b
rm metadata
sahksas c5a846f
add process cleanup and AbortSignal support
sahksas c157c6d
add input validation
sahksas cf5a402
feat session management
sahksas daa5d32
fix test path
sahksas b242e0d
Merge branch 'main' into fix-4842
sahksas 51fe529
fix security validation and CLI compatibility
sahksas a984cc2
Update webview-ui/src/i18n/locales/ja/settings.json
sahksas 2103471
rm duplicate
sahksas 4b5fe06
fix type AssistantMessage
sahksas ed046eb
revert to JSON message format for consistency
sahksas c853ea0
implement session fallback and improve CLI compatibility
sahksas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,179 @@ | ||
| # Claude Code Integration | ||
|
|
||
| This document describes how to use Claude Code CLI integration with Roo Code. | ||
|
|
||
| ## Overview | ||
|
|
||
| The Claude Code integration allows Roo Code to use the Claude Code CLI instead of directly calling the Anthropic API. This provides several benefits: | ||
|
|
||
| - **Local CLI Control**: Use your locally installed Claude Code CLI | ||
| - **Custom Configuration**: Configure Claude Code CLI path and settings | ||
| - **Consistent Experience**: Same interface as other providers | ||
| - **No API Key Required**: Uses Claude Code's authentication | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| 1. **Install Claude Code CLI** | ||
|
|
||
| ```bash | ||
| # Follow Claude Code installation instructions | ||
| # Ensure 'claude' command is available in PATH | ||
| ``` | ||
|
|
||
| 2. **Verify Installation** | ||
| ```bash | ||
| claude --version | ||
| ``` | ||
|
|
||
| ## Configuration | ||
|
|
||
| ### 1. Select Provider | ||
|
|
||
| 1. Open Roo Code settings | ||
| 2. Go to "Providers" section | ||
| 3. Select "Claude Code" from the API Provider dropdown | ||
|
|
||
| ### 2. Configure CLI Path | ||
|
|
||
| - **Default**: `claude` (uses system PATH) | ||
| - **Custom Path**: Specify full path to Claude Code CLI | ||
| ``` | ||
| /usr/local/bin/claude | ||
| /path/to/custom/claude | ||
| ``` | ||
|
|
||
| ### 3. Select Model | ||
|
|
||
| Choose from available Claude Code models: | ||
|
|
||
| - `claude-sonnet-4-20250514` (default) | ||
| - `claude-opus-4-20250514` | ||
| - `claude-3-7-sonnet-20250219` | ||
| - `claude-3-5-sonnet-20241022` | ||
| - `claude-3-5-haiku-20241022` | ||
|
|
||
| ## Usage | ||
|
|
||
| Once configured, Claude Code integration works seamlessly: | ||
|
|
||
| 1. **Start Conversation**: Ask Roo Code any question | ||
| 2. **CLI Execution**: Roo Code executes Claude Code CLI | ||
| 3. **Streaming Response**: Receive real-time streaming responses | ||
| 4. **Usage Tracking**: Monitor token usage and costs | ||
|
|
||
| ## Verification | ||
|
|
||
| To verify Claude Code is being used: | ||
|
|
||
| ### Console Logs (Development) | ||
|
|
||
| Open Developer Tools β Console and look for: | ||
|
|
||
| ``` | ||
| Claude Code Handler: Starting Claude Code CLI execution | ||
| Claude Code CLI: Process started with PID: 12345 | ||
| ``` | ||
|
|
||
| ### System Process Monitoring | ||
|
|
||
| ```bash | ||
| # Linux/macOS | ||
| ps aux | grep claude | ||
|
|
||
| # Windows | ||
| tasklist | findstr claude | ||
| ``` | ||
|
|
||
| ### Test Script | ||
|
|
||
| Run the integration test: | ||
|
|
||
| ```bash | ||
| node test-claude-code-integration.js | ||
| ``` | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### Common Issues | ||
|
|
||
| 1. **"claude: command not found"** | ||
|
|
||
| - Solution: Install Claude Code CLI or specify full path | ||
|
|
||
| 2. **"Permission denied"** | ||
|
|
||
| - Solution: Make Claude Code CLI executable | ||
|
|
||
| ```bash | ||
| chmod +x /path/to/claude | ||
| ``` | ||
|
|
||
| 3. **Model not available** | ||
| - Solution: Check Claude Code CLI version and available models | ||
| ```bash | ||
| claude --help | ||
| ``` | ||
|
|
||
| ### Debug Mode | ||
|
|
||
| For development debugging, check console logs in Developer Tools. | ||
|
|
||
| ## Implementation Details | ||
|
|
||
| ### Architecture | ||
|
|
||
| ``` | ||
| Roo Code β ClaudeCodeHandler β runClaudeCode() β Claude Code CLI | ||
| ``` | ||
|
|
||
| ### Key Components | ||
|
|
||
| - **ClaudeCodeHandler**: Main API handler class | ||
| - **runClaudeCode()**: CLI execution function | ||
| - **ClaudeCodeMessage**: Type definitions for CLI output | ||
| - **Stream Processing**: Real-time response handling | ||
|
|
||
| ### CLI Arguments | ||
|
|
||
| The integration uses these Claude Code CLI arguments: | ||
|
|
||
| ```bash | ||
| claude -p <messages> --system-prompt <prompt> --verbose --output-format stream-json --max-turns 1 --model <model> | ||
| ``` | ||
|
|
||
| ## API Compatibility | ||
|
|
||
| The Claude Code integration maintains full compatibility with Roo Code's provider interface: | ||
|
|
||
| - β Streaming responses | ||
| - β Token usage tracking | ||
| - β Cost calculation | ||
| - β Error handling | ||
| - β Model selection | ||
| - β System prompts | ||
|
|
||
| ## Security Considerations | ||
|
|
||
| - Claude Code CLI runs locally with user permissions | ||
| - No API keys stored in Roo Code settings | ||
| - Authentication handled by Claude Code CLI | ||
| - Process isolation and error handling | ||
|
|
||
| ## Contributing | ||
|
|
||
| To contribute to Claude Code integration: | ||
|
|
||
| 1. **Tests**: Run `npm test -- claude-code.test.ts` | ||
| 2. **Types**: Update types in `packages/types/src/providers/claude-code.ts` | ||
| 3. **Handler**: Modify `src/api/providers/claude-code.ts` | ||
| 4. **UI**: Update `webview-ui/src/components/settings/providers/ClaudeCode.tsx` | ||
|
|
||
| ## Support | ||
|
|
||
| For issues with Claude Code integration: | ||
|
|
||
| 1. Check Claude Code CLI installation | ||
| 2. Verify configuration settings | ||
| 3. Review console logs for errors | ||
| 4. Test with integration script | ||
| 5. Report issues with detailed logs | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import type { ModelInfo } from "../model.js" | ||
| import { anthropicModels } from "./anthropic.js" | ||
|
|
||
| // Claude Code models - subset of Anthropic models available through Claude Code CLI | ||
|
|
||
| export type ClaudeCodeModelId = keyof typeof claudeCodeModels | ||
| export const claudeCodeDefaultModelId: ClaudeCodeModelId = "claude-sonnet-4-20250514" | ||
|
|
||
| export const claudeCodeModels = { | ||
| "claude-sonnet-4-20250514": anthropicModels["claude-sonnet-4-20250514"], | ||
| "claude-opus-4-20250514": anthropicModels["claude-opus-4-20250514"], | ||
| "claude-3-7-sonnet-20250219": anthropicModels["claude-3-7-sonnet-20250219"], | ||
| "claude-3-5-sonnet-20241022": anthropicModels["claude-3-5-sonnet-20241022"], | ||
| "claude-3-5-haiku-20241022": anthropicModels["claude-3-5-haiku-20241022"], | ||
| } as const satisfies Record<string, ModelInfo> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.