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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@jackgreen/msw

v0.2.1

Published

Provider switch CLI for Claude Code, Codex, and OpenCode.

Readme

msw

npm | GitHub

msw 用来统一管理 Claude Code、Codex、OpenCode 的 provider 配置。

Provider 保存在 ~/.msw/config.jsonc。API key 只保存在这个文件里;写入各 agent 配置时只写环境变量名或引用,不写明文 key。

快速开始

安装:

pnpm install -g @jackgreen/msw

添加 provider:

msw add openrouter \
  --base-url https://openrouter.ai/api/v1 \
  --api-key sk-... \
  --model openai/gpt-4o \
  --name OpenRouter

切换 agent:

msw switch codex openrouter
msw switch claude openrouter

msw sync opencode
msw switch opencode openrouter

注入环境变量到当前 shell:

eval "$(msw env claude)"
eval "$(msw env codex)"

Shell 配置

推荐在 ~/.zshrc 中添加以下内容,新 shell 自动加载环境变量,且 msw switch 后无需执行 eval 环境变量:

# --- msw runtime env ---
msw() {
  command msw "$@"
  local ret=$?
  if [[ $ret -eq 0 && "$1" == "switch" ]]; then
    eval "$(command msw env "$2")"
  fi
  return $ret
}
# --- msw runtime env ---

修改后重启 shell:

exec zsh

环境变量

| 环境变量 | agent | | ------------------------------------- | -------- | | ANTHROPIC_BASE_URL | claude | | ANTHROPIC_AUTH_TOKEN | claude | | ANTHROPIC_MODEL | claude | | ANTHROPIC_DEFAULT_SONNET_MODEL | claude | | ANTHROPIC_DEFAULT_OPUS_MODEL | claude | | ANTHROPIC_DEFAULT_HAIKU_MODEL | claude | | MSW_CODEX_API_KEY | codex | | MSW_OPENCODE_<PROVIDER_ID>_API_KEY | opencode |

配置文件

主配置文件:

~/.msw/config.jsonc

示例:

{
  "version": 1,
  "providers": {
    "openrouter": {
      "name": "OpenRouter",
      "baseURL": "https://openrouter.ai/api/v1",
      "apiKey": "sk-...",
      "defaultModel": "openai/gpt-4o",
      "models": {
        "openai/gpt-4o": {
          "name": "openai/gpt-4o",
        },
      },
    },
  },
  "active": {
    "codex": {
      "provider": "openrouter",
      "model": "openai/gpt-4o",
    },
  },
}

Provider 可为不同 agent 设置不同 baseURL,例如 Claude 使用 Anthropic-compatible 端点,Codex/OpenCode 使用 OpenAI-compatible 端点:

{
  "baseURL": "https://openrouter.ai/api/v1",
  "baseURLs": {
    "claude": "https://openrouter.ai/api/anthropic",
  },
}

Model 可配置 limit.context 指定上下文窗口大小。msw env claude 会导出带有 [1M] 标记的 model,Claude Code 据此判断是否启用长上下文:

{
  "defaultModel": "mimo-v2.5-pro",
  "models": {
    "mimo-v2.5-pro": {
      "name": "mimo-v2.5-pro",
      "limit": {
        "context": 1048576
      }
    }
  }
}

命令

msw list                         # 查看 providers 和 active 状态
msw status                       # 查看配置文件路径和 active 状态
msw add <id> --base-url ... --api-key ... --model ... [--name ...]  # 添加 provider
msw delete <id> [--force]        # 删除 provider
msw switch <agent> <provider>    # 切换 agent 的 provider
msw switch <agent> <provider> --model <model>  # 临时指定模型
msw sync opencode                # 同步所有 provider 到 OpenCode
msw env <agent> [provider] [--model <model>]  # 打印 shell exports(无 active provider 时静默退出)

OpenCode 需要先 sync 再 switch:

msw sync opencode
msw switch opencode openrouter

Agent 行为

Claude Code:

  • msw switch claude <provider> 更新 ~/.msw/config.jsoncactive.claude
  • 同时清理 ~/.claude/settings.jsonenv 字段的 ANTHROPIC_*,避免 settings 覆盖 shell env。
  • Claude Code 不支持在 settings.jsonenv 中展开 $VAR,所以运行时变量由 msw env claude 直接导出。

Codex:

  • msw switch codex <provider> 更新 ~/.codex/config.toml
  • 写入 model_providermodel[model_providers.<id>]
  • 写入 env_key = "MSW_CODEX_API_KEY",不写 API key 明文。

OpenCode:

  • msw sync opencode~/.msw/config.jsonc 中所有 provider 同步到 ~/.config/opencode/opencode.json
  • msw switch opencode <provider> 只更新 OpenCode 当前 active model,例如 "model": "openrouter/openai/gpt-4o"
  • provider key 使用 {env:MSW_OPENCODE_<PROVIDER_ID>_API_KEY}

恢复原始配置

恢复某个 agent 到第一次被 msw 修改前的配置:

msw switch codex origin
msw switch claude origin
msw switch opencode origin

恢复后,msw 会清理 ~/.msw/config.jsonc 中对应的 active.<agent>

恢复查找顺序:

  1. 优先使用 agent 配置同目录下的固定 bak 文件。
  2. 如果同目录 bak 不存在,再使用 ~/.msw/backups/<agent>/ 下的固定 bak 文件。

固定 bak 路径:

~/.codex/config.msw-bak.toml
~/.msw/backups/codex/config.msw-bak.toml

~/.claude/settings.msw-bak.json
~/.msw/backups/claude/settings.msw-bak.json

~/.config/opencode/opencode.msw-bak.json
~/.msw/backups/opencode/opencode.msw-bak.json

第一次修改某个 agent 配置前,msw 会按上面的路径保存原始配置。后续普通备份仍会写入带时间戳的文件,但不会覆盖固定 bak。

恢复 origin 后,当前 shell 中旧的环境变量不会自动消失。使用了上面的 msw 函数包装,switch 到 origin 时会自动 unset。如需手动清理,exec zsh 即可。

开发

pnpm install
pnpm dev -- --help

本地全局使用:

pnpm install
pnpm build
pnpm link --global
msw --help

开发检查:

pnpm check
pnpm test
pnpm build