|
| 1 | +# Claude Code Integration |
| 2 | + |
| 3 | +This document describes how to use Claude Code CLI integration with Roo Code. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The Claude Code integration allows Roo Code to use the Claude Code CLI instead of directly calling the Anthropic API. This provides several benefits: |
| 8 | + |
| 9 | +- **Local CLI Control**: Use your locally installed Claude Code CLI |
| 10 | +- **Custom Configuration**: Configure Claude Code CLI path and settings |
| 11 | +- **Consistent Experience**: Same interface as other providers |
| 12 | +- **No API Key Required**: Uses Claude Code's authentication |
| 13 | + |
| 14 | +## Prerequisites |
| 15 | + |
| 16 | +1. **Install Claude Code CLI** |
| 17 | + |
| 18 | + ```bash |
| 19 | + # Follow Claude Code installation instructions |
| 20 | + # Ensure 'claude' command is available in PATH |
| 21 | + ``` |
| 22 | + |
| 23 | +2. **Verify Installation** |
| 24 | + ```bash |
| 25 | + claude --version |
| 26 | + ``` |
| 27 | + |
| 28 | +## Configuration |
| 29 | + |
| 30 | +### 1. Select Provider |
| 31 | + |
| 32 | +1. Open Roo Code settings |
| 33 | +2. Go to "Providers" section |
| 34 | +3. Select "Claude Code" from the API Provider dropdown |
| 35 | + |
| 36 | +### 2. Configure CLI Path |
| 37 | + |
| 38 | +- **Default**: `claude` (uses system PATH) |
| 39 | +- **Custom Path**: Specify full path to Claude Code CLI |
| 40 | + ``` |
| 41 | + /usr/local/bin/claude |
| 42 | + /path/to/custom/claude |
| 43 | + ``` |
| 44 | + |
| 45 | +### 3. Select Model |
| 46 | + |
| 47 | +Choose from available Claude Code models: |
| 48 | + |
| 49 | +- `claude-sonnet-4-20250514` (default) |
| 50 | +- `claude-opus-4-20250514` |
| 51 | +- `claude-3-7-sonnet-20250219` |
| 52 | +- `claude-3-5-sonnet-20241022` |
| 53 | +- `claude-3-5-haiku-20241022` |
| 54 | + |
| 55 | +## Usage |
| 56 | + |
| 57 | +Once configured, Claude Code integration works seamlessly: |
| 58 | + |
| 59 | +1. **Start Conversation**: Ask Roo Code any question |
| 60 | +2. **CLI Execution**: Roo Code executes Claude Code CLI |
| 61 | +3. **Streaming Response**: Receive real-time streaming responses |
| 62 | +4. **Usage Tracking**: Monitor token usage and costs |
| 63 | + |
| 64 | +## Verification |
| 65 | + |
| 66 | +To verify Claude Code is being used: |
| 67 | + |
| 68 | +### Console Logs (Development) |
| 69 | + |
| 70 | +Open Developer Tools → Console and look for: |
| 71 | + |
| 72 | +``` |
| 73 | +Claude Code Handler: Starting Claude Code CLI execution |
| 74 | +Claude Code CLI: Process started with PID: 12345 |
| 75 | +``` |
| 76 | +
|
| 77 | +### System Process Monitoring |
| 78 | +
|
| 79 | +```bash |
| 80 | +# Linux/macOS |
| 81 | +ps aux | grep claude |
| 82 | +
|
| 83 | +# Windows |
| 84 | +tasklist | findstr claude |
| 85 | +``` |
| 86 | + |
| 87 | +### Test Script |
| 88 | + |
| 89 | +Run the integration test: |
| 90 | + |
| 91 | +```bash |
| 92 | +node test-claude-code-integration.js |
| 93 | +``` |
| 94 | + |
| 95 | +## Troubleshooting |
| 96 | + |
| 97 | +### Common Issues |
| 98 | + |
| 99 | +1. **"claude: command not found"** |
| 100 | + |
| 101 | + - Solution: Install Claude Code CLI or specify full path |
| 102 | + |
| 103 | +2. **"Permission denied"** |
| 104 | + |
| 105 | + - Solution: Make Claude Code CLI executable |
| 106 | + |
| 107 | + ```bash |
| 108 | + chmod +x /path/to/claude |
| 109 | + ``` |
| 110 | + |
| 111 | +3. **Model not available** |
| 112 | + - Solution: Check Claude Code CLI version and available models |
| 113 | + ```bash |
| 114 | + claude --help |
| 115 | + ``` |
| 116 | + |
| 117 | +### Debug Mode |
| 118 | + |
| 119 | +For development debugging, check console logs in Developer Tools. |
| 120 | + |
| 121 | +## Implementation Details |
| 122 | + |
| 123 | +### Architecture |
| 124 | + |
| 125 | +``` |
| 126 | +Roo Code → ClaudeCodeHandler → runClaudeCode() → Claude Code CLI |
| 127 | +``` |
| 128 | +
|
| 129 | +### Key Components |
| 130 | +
|
| 131 | +- **ClaudeCodeHandler**: Main API handler class |
| 132 | +- **runClaudeCode()**: CLI execution function |
| 133 | +- **ClaudeCodeMessage**: Type definitions for CLI output |
| 134 | +- **Stream Processing**: Real-time response handling |
| 135 | +
|
| 136 | +### CLI Arguments |
| 137 | +
|
| 138 | +The integration uses these Claude Code CLI arguments: |
| 139 | +
|
| 140 | +```bash |
| 141 | +claude -p <messages> --system-prompt <prompt> --verbose --output-format stream-json --max-turns 1 --model <model> |
| 142 | +``` |
| 143 | + |
| 144 | +## API Compatibility |
| 145 | + |
| 146 | +The Claude Code integration maintains full compatibility with Roo Code's provider interface: |
| 147 | + |
| 148 | +- ✅ Streaming responses |
| 149 | +- ✅ Token usage tracking |
| 150 | +- ✅ Cost calculation |
| 151 | +- ✅ Error handling |
| 152 | +- ✅ Model selection |
| 153 | +- ✅ System prompts |
| 154 | + |
| 155 | +## Security Considerations |
| 156 | + |
| 157 | +- Claude Code CLI runs locally with user permissions |
| 158 | +- No API keys stored in Roo Code settings |
| 159 | +- Authentication handled by Claude Code CLI |
| 160 | +- Process isolation and error handling |
| 161 | + |
| 162 | +## Contributing |
| 163 | + |
| 164 | +To contribute to Claude Code integration: |
| 165 | + |
| 166 | +1. **Tests**: Run `npm test -- claude-code.test.ts` |
| 167 | +2. **Types**: Update types in `packages/types/src/providers/claude-code.ts` |
| 168 | +3. **Handler**: Modify `src/api/providers/claude-code.ts` |
| 169 | +4. **UI**: Update `webview-ui/src/components/settings/providers/ClaudeCode.tsx` |
| 170 | + |
| 171 | +## Support |
| 172 | + |
| 173 | +For issues with Claude Code integration: |
| 174 | + |
| 175 | +1. Check Claude Code CLI installation |
| 176 | +2. Verify configuration settings |
| 177 | +3. Review console logs for errors |
| 178 | +4. Test with integration script |
| 179 | +5. Report issues with detailed logs |
0 commit comments