npm package: @r2neuron/r2d2
Description: R2D2 CLI - Claude Code model switcher
Author: hatsuka05
Latest version: 1.0.3

# R2D2 CLI

R2D2 CLI - Interactive Claude Code model switcher for managing Claude Code and GLM API configurations.

## Features

- **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

## Installation

### Step 1: Install R2D2 CLI

```bash
npm install -g @r2neuron/r2d2
```

### Step 2: Setup Claude Configs (Optional but Recommended)

For full functionality with R2D2's extended features:

```bash
# Sync Claude configuration templates
npm run claude-configs

# Initialize Claude configuration
r2d2 init
```

### From source

```bash
git clone https://github.com/hatsuka05/r2d2-cli.git
cd r2d2-cli
npm install
npm run build
npm link

# Setup Claude configs (optional)
npm run claude-configs
```

### From Homebrew

```bash
brew install r2d2

# Setup Claude configs (optional)
npm run claude-configs
```

## Setup Instructions

### Quick Setup (Basic)

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`

### Full Setup (Recommended)

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`

### Claude Configs Management

```bash
# Sync latest templates from repository
npm run claude-configs

# Initialize/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

### Interactive Mode (Default)

```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.

### Show Version

```bash
r2d2 --version
r2d2 -V
```

### Check Current Status

```bash
r2d2 status
```

Shows:
- Current mode (Claude Code, Claude API, or GLM)
- Settings file location
- Token configuration status

### Quick Configuration Switches

#### 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 settings

## File 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 templates

## Security

- **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/` directory

## Troubleshooting

### Permission denied

```bash
chmod 600 ~/.claude/settings.json
```

### Settings not found

R2D2 will create the `.claude` directory and default settings if they don't exist.

### Restore from backup

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

### Setup

```bash
git clone https://github.com/hatsuka05/r2d2-cli.git
cd r2d2-cli
npm install
```

### Build

```bash
npm run build
```

### Test locally

```bash
npm link
r2d2 --version
```

### Test Interactive Mode

```bash
r2d2
# Try different configurations and test arrow-key navigation
```

### Unlink

```bash
npm unlink -g @r2neuron/r2d2
```

## Contributing

For detailed contribution guidelines, including our Git workflow and release process, see [docs/publish-guide.md](docs/publish-guide.md).

Quick setup:
1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Submit a pull request

## License

MIT License - see LICENSE file for details.

## Repository

https://github.com/hatsuka05/r2d2-cli

## Support

For issues and feature requests, please use the GitHub issue tracker.