https://github.com/xavier2code/llm-switch
Switch Claude Code settings.json profiles from the command line
https://github.com/xavier2code/llm-switch
claude-code cli llm nodejs
Last synced: 3 days ago
JSON representation
Switch Claude Code settings.json profiles from the command line
- Host: GitHub
- URL: https://github.com/xavier2code/llm-switch
- Owner: xavier2code
- License: mit
- Created: 2026-06-22T08:22:02.000Z (25 days ago)
- Default Branch: main
- Last Pushed: 2026-07-01T02:49:04.000Z (16 days ago)
- Last Synced: 2026-07-01T03:20:10.972Z (16 days ago)
- Topics: claude-code, cli, llm, nodejs
- Language: TypeScript
- Homepage:
- Size: 485 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# llm-switch
[](https://www.npmjs.com/package/@xavier2code/llm-switch)
[](https://www.npmjs.com/package/@xavier2code/llm-switch)
[](https://github.com/xavier2code/llm-switch/actions/workflows/ci.yml)
[](./LICENSE)
[](https://nodejs.org/)
[](https://prettier.io/)
Switch LLM profiles for Claude Code, OpenCode, Codex, and other AI CLI tools.
The recommended command name is `sw`; `llm-switch` is installed as a legacy alias.
> **Note:** The unscoped `llm-switch` package is deprecated. Install
> `@xavier2code/llm-switch` for the latest releases.
## Install
```bash
npm i -g @xavier2code/llm-switch
```
## Quick start
```bash
sw create # create and activate a new profile
sw switch glm # switch active config to the "glm" profile
sw restore # undo the last switch from the automatic backup
sw list # list profiles and show the active one
sw # launch the interactive TUI (TTY only)
```
Every command prompts for targets (Claude Code, OpenCode, Codex) and remembers
the choice. Use `--target ` or `LLM_SWITCH_TARGET` to skip the prompt.
## Supported targets
| Target | Active config | Config dir env var | Format |
| ---------- | ---------------------------------- | ---------------------- | ------ |
| `claude` | `~/.claude/settings.json` | `CLAUDE_CONFIG_DIR` | JSON |
| `opencode` | `~/.config/opencode/opencode.json` | `OPENCODE_CONFIG_DIR` | JSON |
| `codex` | `~/.codex/config.toml` | `CODEX_HOME` | TOML |
Anthropic-family targets use `ANTHROPIC_BASE_URL`, `ANTHROPIC_MODEL`, and
`ANTHROPIC_AUTH_TOKEN`. Codex uses `model`, `base_url`, and `api_key` in TOML.
## Layout
```
~/.llm-switch/
profiles//.[json|toml] saved profiles (central store)
state.json last-selected targets
~/.claude/
settings.json active config
settings.json.bak previous active config
```
Profiles are stored centrally; each tool's active config and backup stay in its
own config directory.
## Built-in providers
| Provider | Default BASE URL | Default model |
| -------------- | ------------------------------------------------------- | ----------------- |
| GLM (智谱) | `https://open.bigmodel.cn/api/anthropic` | `glm-4.5` |
| DeepSeek | `https://api.deepseek.com/anthropic` | `deepseek-chat` |
| Kimi (Moonshot)| `https://api.kimi.com/coding/` | `kimi-for-coding` |
| MiniMax | `https://api.minimaxi.com/anthropic` | `MiniMax-Text-01` |
| Qwen (DashScope)| `https://dashscope.aliyuncs.com/compatible-mode/anthropic` | `qwen-plus` |
| OpenAI | `https://api.openai.com/v1` | `gpt-4.1` |
The `create` wizard validates Anthropic-family endpoints and writes TOML for
Codex. A single run can create and activate a profile across every selected
target.
## Security
API keys are stored in plaintext in active config and profile files. All files
created by `sw` are set to `0600` so they are readable only by your Unix user.
## Usage examples
```bash
sw --target opencode list # operate on a single target
sw -t codex create # create a Codex TOML profile
sw save -f glm # overwrite an existing profile
LLM_SWITCH_TARGET=opencode sw current # default target for scripts
sw --help # full help and env vars
sw --help # per-command help and exit codes
```
## Migration
`sw` automatically migrates profiles from earlier layouts on first run:
- `0.5.x` and earlier (legacy `llm-switch` package): flat
`settings.json.` files are moved into the central store.
- `0.7.x` (legacy `llm-switch` package): per-tool `llm-switch/profiles/`
directories are copied into the central store; originals are left in place.
Run `sw init` to review detected tools and directory status.
## Development
```bash
pnpm install
pnpm -r test # run all tests
pnpm -r lint
pnpm -r format:check
pnpm -r build
```
See [CONTRIBUTING.md](./CONTRIBUTING.md) and [SECURITY.md](./SECURITY.md).
## License
MIT