R2D2 CLI - Claude Code model switcher
npm install @r2neuron/r2d2R2D2 CLI - Interactive Claude Code model switcher for managing Claude Code and GLM API configurations.
- Interactive Configuration: Arrow-key navigation for easy setup
- Multiple Model Support: Claude Subscription, Claude API, and GLM modes
- Template System: Preserves existing settings while updating configurations
- Automatic Backup: Settings are backed up before any changes
- Multi-line Instructions: Support for complex onstart instructions
- Cross-platform Support: Works on macOS, Linux, and Windows
``bash`
npm install -g @r2neuron/r2d2
For full functionality with R2D2's extended features:
`bashSync Claude configuration templates
npm run claude-configs
$3
`bash
git clone https://github.com/hatsuka05/r2d2-cli.git
cd r2d2-cli
npm install
npm run build
npm linkSetup Claude configs (optional)
npm run claude-configs
`$3
`bash
brew install r2d2Setup Claude configs (optional)
npm run claude-configs
`Setup Instructions
$3
1. Install R2D2 CLI
2. Run
r2d2 glm or r2d2 cc-api to configure API mode
3. Edit ~/.claude/settings.json to add your API key
4. Start using with r2d2$3
1. Install:
npm install -g @r2neuron/r2d2
2. Sync Templates: npm run claude-configs (requires SSH access to claude-configs repo)
3. Initialize: r2d2 init or r2d2 init --force (overwrites existing files)
4. Configure API: Edit ~/.claude/settings.json with your API key
5. Start: r2d2$3
`bash
Sync latest templates from repository
npm run claude-configsInitialize/update local configuration
r2d2 init # Safe mode (preserves existing files)
r2d2 init --force # Force mode (overwrites existing files)Configure API keys manually
nano ~/.claude/settings.json
`Usage
$3
`bash
r2d2
`First shows action selection:
1. Start: Launch Claude Code CLI with current configuration immediately
2. Configure: Full configuration flow with arrow-key navigation
If Configure is selected:
1. Model Selection: Choose between Claude Subscription, Claude API, or GLM
2. API Configuration: Enter new API key, use existing, or skip
3. CLI Selection: Choose Claude Code (future: more CLI options)
4. Onstart Instructions: Add multi-line custom instructions or skip
After configuration, Claude Code CLI starts automatically with your selected settings.
$3
`bash
r2d2 --version
r2d2 -V
`$3
`bash
r2d2 status
`Shows:
- Current mode (Claude Code, Claude API, or GLM)
- Settings file location
- Token configuration status
$3
#### Claude Subscription Mode
`bash
r2d2 cc
`Switches to Claude Code subscription mode without starting CLI.
#### Claude API Mode
`bash
r2d2 cc-api
`Configures Claude API mode without starting CLI.
#### GLM Mode
`bash
r2d2 glm
`Configures GLM API mode without starting CLI.
To start Claude Code CLI with current configuration:
`bash
r2d2
Select "Start"
`Or configure first then start:
`bash
r2d2
Select "Configure" → Complete setup → Starts automatically
`Configuration Templates
R2D2 uses configuration templates to preserve your existing settings:
- Subscription Template: Full Claude Code settings without API keys
- API Key Template: Complete configuration with
${API_KEY} placeholders
- Automatic Merging: Preserves existing permissions, hooks, plugins, and custom settingsFile Management
R2D2 automatically manages backup files:
-
~/.claude/settings-cc.json - Claude Code subscription backup
- ~/.claude/settings-cc-api.json - Claude API backup
- ~/.claude/settings-glm.json - GLM backup
- ~/.claude/settings.json - Active settings
- configs/claude/ - Configuration templatesSecurity
- API Key Encryption: AES-256-GCM encryption for stored API keys
- Input Validation: Comprehensive protection against command injection attacks
- Secure File Permissions: 0o600 permissions on sensitive files
- No Exposure: API tokens are never logged or displayed (masked format only)
- Automatic Backup: Settings files are backed up before any changes
- No Hardcoded Credentials: All credentials are user-controlled
- Memory Protection: Temporary files are securely handled and cleaned up
Requirements
- Node.js >= 16.0.0
- npm or yarn
- Write access to
~/.claude/ directoryTroubleshooting
$3
`bash
chmod 600 ~/.claude/settings.json
`$3
R2D2 will create the
.claude directory and default settings if they don't exist.$3
If you need to manually restore a backup:
`bash
cp ~/.claude/settings-cc.json ~/.claude/settings.json # Restore Claude Code
cp ~/.claude/settings-glm.json ~/.claude/settings.json # Restore GLM
`Development
$3
`bash
git clone https://github.com/hatsuka05/r2d2-cli.git
cd r2d2-cli
npm install
`$3
`bash
npm run build
`$3
`bash
npm link
r2d2 --version
`$3
`bash
r2d2
Try different configurations and test arrow-key navigation
`$3
`bash
npm unlink -g @r2neuron/r2d2
``For detailed contribution guidelines, including our Git workflow and release process, see docs/publish-guide.md.
Quick setup:
1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Submit a pull request
MIT License - see LICENSE file for details.
https://github.com/hatsuka05/r2d2-cli
For issues and feature requests, please use the GitHub issue tracker.