npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@redchili/model-switch

v1.2.3

Published

AI Model Switcher (AMS) - AI模型配置切换工具 | AI Model Configuration Switcher for CLI Tools

Readme

Model Switch

AI 模型配置切换工具 | AI Model Configuration Switcher for CLI Tools

项目介绍

Model Switch 是一个 CLI 工具,用于管理多个 AI CLI 工具的配置(Claude Code、Codex、Gemini CLI 等),支持存储多个配置并快速切换。

功能特性

  • ✅ 管理多个 AI 模型配置(Claude Code、Codex、Gemini CLI)
  • ✅ 快速切换不同模型配置
  • ✅ 自动应用配置到对应的 CLI 工具
  • ✅ 显示当前使用的配置
  • ✅ 首次使用自动创建默认配置文件
  • ✅ 交互式命令行界面(使用 @clack/prompts)
  • ✅ TypeScript 编写,类型安全
  • ✅ 使用 Bun 运行时,快速高效
  • ✅ JSON5 配置格式,支持注释和更灵活的语法

安装

# 从 npm 安装(推荐)
npm install -g @redchili/model-switch

# 或者从源代码安装
git clone <repository-url>
cd model-switch

# 安装依赖
bun install

# 构建项目
bun run build

# 全局安装
bun link

首次使用

首次运行任何命令时,工具会自动创建默认配置:

# 首次运行时会自动创建 ~/.model-switch/ 目录和默认配置文件
model list

# 输出示例:
# ✅ 已创建默认配置文件: /Users/your-name/.model-switch/.models.json5
# 💡 请编辑配置文件,添加你的 API 密钥和代理配置
#    使用 'model open' 命令打开配置文件进行编辑

配置文件位置:

  • 主配置文件: ~/.model-switch/.models.json5
  • 当前配置追踪: ~/.model-switch/.current.json5 (自动生成)

下一步操作:

  1. 使用 model open 命令打开配置文件
  2. 添加你的 API 密钥和代理配置(参考 .models.example.json5 示例文件)
  3. 使用 model use 选择要使用的配置

使用方法

命令列表

# 显示所有模型配置
model list

# 显示特定 CLI 工具的配置
model list -cc    # 只显示 Claude Code 配置
model list -cx    # 只显示 Codex 配置
model list -gc    # 只显示 Gemini CLI 配置

# 切换模型配置
model use

# 切换特定 CLI 工具的配置
model use -cc     # 只切换 Claude Code 配置
model use -cx     # 只切换 Codex 配置
model use -gc     # 只切换 Gemini CLI 配置

# 显示当前配置
model current -cc # 显示当前 Claude Code 配置
model current -cx # 显示当前 Codex 配置
model current -gc # 显示当前 Gemini CLI 配置

# 显示帮助信息
model help

示例

查看所有配置

$ bun run dev list
📋 模型配置列表
◇  Claude 3 Opus
│  Claude 3 Opus - Most powerful model for complex tasks [claude code]
◇  OpenAI GPT-4o
│  OpenAI GPT-4o - Advanced reasoning and multimodal capabilities [codex]
◇  Gemini 1.5 Flash
│  Gemini 1.5 Flash - Fast and efficient Google AI model [gemini cli]
└  共 3 个模型配置

切换配置

$ bun run dev use
🔄 切换模型配置
◆  选择要使用的模型配置
│  ○ Claude 3 Opus
│  ○ OpenAI GPT-4o
│  ● Gemini 1.5 Flash
└  请在终端中运行导出命令来设置环境变量

检查连通性

$ bun run dev check
🌐 检查模型连通性
检测到 3 个模型
✅ 可连通 Claude 3 Opus
❌ 缺少 API Key OpenAI GPT-4o — OPENAI_API_KEY 未设置
⚠️ 未配置 URL Gemini 1.5 Flash — 无法进行连通性检查

项目结构

model-switch/
├── src/
│   ├── commands/          # CLI 命令实现
│   │   ├── check.ts       # 检查连通性命令
│   │   ├── current.ts     # 显示当前配置命令
│   │   ├── list.ts        # 列出配置命令
│   │   ├── open.ts        # 打开配置文件命令
│   │   └── use.ts         # 切换配置命令
│   ├── utils/             # 工具函数
│   │   ├── checker.ts     # 模型连通性检查工具
│   │   ├── config.ts      # 配置文件加载工具
│   │   └── settings.ts    # CLI 工具设置文件管理
│   ├── types.ts           # TypeScript 类型定义
│   └── index.ts           # 主入口文件
├── ~/.model-switch/       # 用户配置目录
│   ├── .models.json5      # 模型配置文件
│   └── .current.json5     # 当前配置追踪文件
├── package.json           # 项目配置
└── tsconfig.json          # TypeScript 配置

配置文件格式

配置文件 ~/.model-switch/.models.json5 使用 JSON5 格式,支持注释和更灵活的语法:

{
  // Claude Code 配置
  claudeCode: [
    {
      cli: "claude code",
      settings: [
        {
          key: "anyRouter",
          name: "AnyRouter Claude",
          description: "Claude via AnyRouter proxy",
          model: "claude-3-5-sonnet-20241022",
          prompt: "Hello Claude",
          other: "",
          appendKeyToUrl: false,
          env: {
            ANTHROPIC_BASE_URL: "https://anyrouter.top",
            ANTHROPIC_AUTH_TOKEN: "your-api-key-here",
          },
        },
        {
          key: "zenMux",
          name: "ZenMux Claude",
          description: "Claude via ZenMux proxy",
          model: "claude-3-5-sonnet-20241022",
          prompt: "Hello Claude",
          other: "",
          appendKeyToUrl: false,
          env: {
            ANTHROPIC_BASE_URL: "https://zenmux.example.com",
            ANTHROPIC_AUTH_TOKEN: "your-api-key-here",
          },
        },
      ],
    },
  ],

  // Codex 配置
  codex: [
    {
      cli: "codex",
      settings: [
        {
          key: "openai",
          name: "OpenAI GPT-4",
          description: "OpenAI GPT-4 model",
          model: "gpt-4",
          prompt: "Hello",
          other: "",
          appendKeyToUrl: false,
          env: {
            OPENAI_API_KEY: "your-openai-key-here",
          },
        },
      ],
    },
  ],

  // Gemini CLI 配置
  geminiCli: [
    {
      cli: "gemini cli",
      settings: [
        {
          key: "gemini",
          name: "Google Gemini",
          description: "Google Gemini Pro model",
          model: "gemini-pro",
          prompt: "Hello",
          other: "",
          appendKeyToUrl: true,
          env: {
            GEMINI_API_KEY: "your-gemini-key-here",
          },
        },
      ],
    },
  ],
}

技术栈

  • 运行时: Bun - 快速的 JavaScript/TypeScript 运行时
  • 语言: TypeScript - 类型安全的 JavaScript 超集
  • CLI 框架: @clack/prompts - 现代化的命令行交互界面
  • 配置解析: JSON5 - 支持注释和更灵活语法的 JSON 解析器

开发

# 开发模式运行
bun run dev <command>

# 构建生产版本
bun run build

# 运行构建后的版本
bun run start <command>

License

MIT