Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 130 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ A powerful CLI tool for managing multiple Claude Code configurations with ease.
- **Smart Directory Launch**: Remember last working directory and support project aliases for quick access
- **Environment Import**: Automatically detect and import existing Claude configurations from environment variables
- **Automatic Installation**: Automatically installs and updates Claude CLI when needed
- **API Validation**: Tests API connectivity before saving configurations
- **API Validation**: Tests API connectivity before saving configurations and provides testing tools
- **Cross-Platform**: Support for Linux, macOS, and Windows (amd64 & arm64)
- **Zero Configuration**: Works out of the box with sensible defaults
- **Configuration Management**: Global configuration settings for CLI behavior
- **Permission Control**: Manage --dangerously-skip-permissions flag for Claude CLI
- **Flexible Startup Behavior**: Control where Claude starts when no arguments provided

## Installation

Expand Down Expand Up @@ -167,6 +170,105 @@ Lists the latest 20 available versions from npm and allows you to:
- Enter a specific version number (e.g., `1.2.3`)
- Type `latest` to install the newest version

### `codes test`

Test API configuration connectivity and validate configurations.

```bash
# Test all configured API endpoints
codes test

# Test a specific configuration
codes test my-config
```

**Features**:
- Tests API connectivity using actual Claude API endpoint (`/v1/messages`)
- Shows model being used for each test
- Updates configuration status (active/inactive) based on test results
- Displays test results with clear success/failure indicators
- Tests all environment variables including authentication tokens and base URLs
- Validates that required fields are present and properly formatted

### `codes config`

Manage global CLI configuration settings.

```bash
# Show all configuration values
codes config get

# Show specific configuration value
codes config get <key>

# Set configuration value
codes config set <key> <value>
```

**Current Configuration Keys**:
- `defaultBehavior` - Controls where Claude starts when no arguments are provided

**Environment Variables Managed**:
- While the config command itself doesn't directly manage environment variables, it works with configurations that contain environment variables for:
- `ANTHROPIC_BASE_URL` - API endpoint URL
- `ANTHROPIC_AUTH_TOKEN` - Authentication token
- `ANTHROPIC_MODEL` - Default model
- `ANTHROPIC_DEFAULT_HAIKU_MODEL` - Haiku model override
- `ANTHROPIC_DEFAULT_OPUS_MODEL` - Opus model override
- `ANTHROPIC_DEFAULT_SONNET_MODEL` - Sonnet model override
- And other Claude CLI recognized environment variables
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Minor grammar fix: use hyphen for compound modifier.

Change "Claude CLI recognized environment variables" to "Claude-CLI-recognized environment variables" or rephrase to "environment variables recognized by Claude CLI".

🧰 Tools
🪛 LanguageTool

[grammar] ~219-~219: Use a hyphen to join words.
Context: ... model override - And other Claude CLI recognized environment variables ### `c...

(QB_NEW_EN_HYPHEN)

🤖 Prompt for AI Agents
In README.md around line 219, the phrase "Claude CLI recognized environment
variables" uses incorrect grammar for a compound modifier; change it to
"Claude-CLI-recognized environment variables" or rephrase as "environment
variables recognized by Claude CLI" to use a hyphenated compound modifier or a
clearer passive construction.


### `codes defaultbehavior`

Manage the default startup behavior when running `codes` without arguments.

```bash
# Show current default behavior
codes defaultbehavior get

# Set default behavior
codes defaultbehavior set <behavior>

# Reset to default
codes defaultbehavior reset
```

**Available Behaviors**:
- `current` - Start Claude in the current working directory (default)
- `last` - Start Claude in the last used directory (remembered from previous runs)
- `home` - Start Claude in the user's home directory

**Important Details**:
- Behavior is saved in config.json under `DefaultBehavior` field
- When `codes` is run without arguments, it uses this setting to determine the working directory
- The `codes start` command still works with project aliases and specific paths

### `codes skippermissions`

Manage the global `--dangerously-skip-permissions` flag setting for Claude CLI.

```bash
# Show current global skipPermissions setting
codes skippermissions get

# Set global skipPermissions
codes skippermissions set <true|false>

# Reset to default
codes skippermissions reset
```

**How It Works**:
- Global setting applies to all configurations that don't have their own `skipPermissions` setting
- When `true`, Claude runs with `--dangerously-skip-permissions` flag
- When `false` (default), Claude runs without the flag
- Individual configurations can override this global setting during `codes add` or by editing the config file

**Important Details**:
- Setting is stored in config.json under `SkipPermissions` field
- Individual configurations can have their own `skipPermissions` setting that takes precedence
- This controls whether Claude bypasses certain security checks for file system access

### `codes install`

Install the codes binary to your system PATH.
Expand Down Expand Up @@ -243,26 +345,42 @@ Create a `config.json` file with the following structure:
"configs": [
{
"name": "official",
"ANTHROPIC_BASE_URL": "https://api.anthropic.com",
"ANTHROPIC_AUTH_TOKEN": "sk-ant-xxxxx"
},
{
"name": "proxy",
"ANTHROPIC_BASE_URL": "https://your-proxy.com/api",
"ANTHROPIC_AUTH_TOKEN": "your-token"
"env": {
"ANTHROPIC_BASE_URL": "https://api.anthropic.com",
"ANTHROPIC_AUTH_TOKEN": "sk-ant-xxxxx",
"ANTHROPIC_MODEL": "claude-3-5-sonnet-20241022"
},
"skipPermissions": false
}
],
"default": "official"
"default": "official",
"skipPermissions": false,
"defaultBehavior": "current",
"projects": {
"my-project": "/path/to/project"
},
"lastWorkDir": "/path/to/last/directory"
}
```

### Configuration Fields

#### Global Settings
- `default`: The configuration name to use by default
- `skipPermissions`: Global setting for `--dangerously-skip-permissions` flag (applies to all configs unless overridden)
- `defaultBehavior`: Controls where Claude starts when no arguments provided ("current", "last", "home")
- `projects`: Object mapping project names to their directory paths
- `lastWorkDir`: Last working directory remembered from previous runs

#### Configuration Object
- `name`: Unique identifier for the configuration
- `ANTHROPIC_BASE_URL`: Base URL for the Claude API endpoint
- `ANTHROPIC_AUTH_TOKEN`: Authentication token for the API
- `env`: Object containing environment variables for Claude CLI:
- `ANTHROPIC_BASE_URL`: Base URL for the Claude API endpoint
- `ANTHROPIC_AUTH_TOKEN`: Authentication token for the API
- `ANTHROPIC_MODEL`: Default model to use
- And other Claude CLI recognized environment variables
- `skipPermissions`: Per-configuration setting that overrides global `skipPermissions`
- `status`: (optional) API status - "active", "inactive", or "unknown"
- `default`: The configuration name to use by default

### Example Configurations

Expand Down
6 changes: 5 additions & 1 deletion cmd/codes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@ func init() {
rootCmd.AddCommand(commands.InstallCmd)
rootCmd.AddCommand(commands.AddCmd)
rootCmd.AddCommand(commands.SelectCmd)
rootCmd.AddCommand(commands.TestCmd)
rootCmd.AddCommand(commands.UpdateCmd)
rootCmd.AddCommand(commands.VersionCmd)
rootCmd.AddCommand(commands.StartCmd)
rootCmd.AddCommand(commands.ProjectCmd)
rootCmd.AddCommand(commands.ConfigCmd)
rootCmd.AddCommand(commands.DefaultBehaviorCmd)
rootCmd.AddCommand(commands.SkipPermissionsCmd)

// 设置默认运行时行为 - 现在使用智能启动
rootCmd.Run = func(cmd *cobra.Command, args []string) {
// Check if claude is installed
if _, err := exec.LookPath("claude"); err != nil {
commands.RunClaudeWithConfig(nil)
commands.RunClaudeWithConfig([]string{})
return
}
// 使用 start 命令的逻辑,支持目录记忆
Expand Down
38 changes: 30 additions & 8 deletions config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,41 @@
"configs": [
{
"name": "official",
"ANTHROPIC_BASE_URL": "https://api.anthropic.com",
"ANTHROPIC_AUTH_TOKEN": "sk-ant-xxxxxxxxxxxxxxxxxxxxx"
"env": {
"ANTHROPIC_BASE_URL": "https://api.anthropic.com",
"ANTHROPIC_AUTH_TOKEN": "sk-ant-xxxxxxxxxxxxxxxxxxxxx",
"ANTHROPIC_MODEL": "claude-3-5-sonnet-20241022",
"MAX_THINKING_TOKENS": "32768"
},
"skipPermissions": false
},
{
"name": "proxy",
"ANTHROPIC_BASE_URL": "https://your-proxy.example.com/api",
"ANTHROPIC_AUTH_TOKEN": "your-proxy-token"
"env": {
"ANTHROPIC_BASE_URL": "https://your-proxy.example.com/api",
"ANTHROPIC_AUTH_TOKEN": "your-proxy-token",
"ANTHROPIC_API_KEY": "your-proxy-api-key",
"HTTP_PROXY": "http://proxy.example.com:8080",
"HTTPS_PROXY": "http://proxy.example.com:8080",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-3-haiku-20240307-custom",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-3-sonnet-20240229-custom"
},
"skipPermissions": true
},
{
"name": "alternative",
"ANTHROPIC_BASE_URL": "https://api.alternative-provider.com",
"ANTHROPIC_AUTH_TOKEN": "your-alternative-token"
"name": "custom-model",
"env": {
"ANTHROPIC_BASE_URL": "https://api.anthropic.com",
"ANTHROPIC_AUTH_TOKEN": "sk-ant-xxxxxxxxxxxxxxxxxxxxx",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "my-custom-haiku-model",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "my-custom-sonnet-model",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "my-custom-opus-model",
"CLAUDE_CODE_API_KEY_HELPER_TTL_MS": "3600000",
"MAX_THINKING_TOKENS": "65536"
}
}
],
"default": "official"
"default": "official",
"skipPermissions": false,
"defaultBehavior": "current"
}
Loading