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

@hcg1023/claude-env-manager

v1.0.14

Published

Claude Environment Manager - Manage and switch Claude Code configurations

Readme

CEM (Claude Version Manager)

CEM 是一个命令行工具,用于管理和快速切换 Claude Code 的多个配置(baseURL 和 TOKEN)。

特性

  • 🚀 快速切换多个 Claude Code 配置
  • 🎯 直接修改 Claude Code 的 settings.json,无需手动 source
  • 📦 支持从 JSON 批量导入配置,方便迁移和备份
  • 🔐 安全的配置存储(文件权限 600)
  • ⚡ 立即生效,对新会话有效
  • 🎨 友好的交互式界面和彩色输出

安装

# 克隆仓库
git clone <your-repo-url>
cd cem

# 安装依赖
npm install

# 构建
npm run build

# 全局链接
npm link

使用方法

添加配置

方式一:交互式添加

cem add <alias>

交互式添加新配置,需要输入:

  • Base URL:Claude API 的基础 URL
  • Token:认证令牌

示例:

$ cem add work
? Enter baseURL: https://api.claude.ai
? Enter TOKEN: ********
✓ Configuration 'work' added successfully
? Switch to this configuration now? Yes

方式二:从 JSON 导入

cem import <json> --alias <alias>

从 JSON 格式的配置导入。支持灵活的字段名:

  • baseURLANTHROPIC_BASE_URL
  • tokenANTHROPIC_AUTH_TOKEN

示例:

# 使用 ANTHROPIC 字段名
cem import '{"ANTHROPIC_BASE_URL":"https://api.anthropic.com","ANTHROPIC_AUTH_TOKEN":"sk-ant-xxx"}' --alias prod

# 包含自定义变量
cem import '{
  "ANTHROPIC_BASE_URL": "https://api.anthropic.com",
  "ANTHROPIC_AUTH_TOKEN": "sk-ant-xxx",
  "ANTHROPIC_VERSION": "2023-06-01",
  "DEBUG": "true"
}' --alias dev

# 交互式模式(不提供 JSON 参数)
cem import

列出所有配置

cem ls
# 或
cem list

以表格形式显示所有配置:

┌──────────┬───────────────────────────┬─────────┐
│ Alias    │ Base URL                  │ Current │
├──────────┼───────────────────────────┼─────────┤
│ default  │ https://api.claude.ai     │ ✓       │
│ work     │ https://work.claude.ai    │         │
└──────────┴───────────────────────────┴─────────┘

查看配置详情

cem show <alias>

示例:

$ cem show work
Configuration: work
──────────────────────────────────────────────────
  Base URL: https://work.claude.ai
  Token: sk-xxx...******
  Status: Active

查看当前配置

cem current

显示当前激活的配置信息。

切换配置

cem use <alias>

切换到指定的配置。CEM 会直接修改 Claude Code 的 settings.json 文件。

示例:

$ cem use work
✓ Switched to configuration 'work'
✓ Claude settings: /Users/username/.claude/settings.json

  Configuration will take effect immediately for new Claude Code sessions

删除配置

cem rm <alias>
# 或
cem remove <alias>
cem delete <alias>
cem del <alias>

删除指定配置(需确认)。注意:不能删除当前正在使用的配置。

重命名配置

cem rename <oldAlias> <newAlias>

重命名已存在的配置别名。

示例:

# 重命名配置
$ cem rename old-name new-name
? 确定要将配置 'old-name' 重命名为 'new-name' 吗? Yes
✓ 配置 'old-name' 已成功重命名为 'new-name'

# 重命名当前配置会自动更新当前配置引用
$ cem rename current-config renamed-config
✓ 配置 'current-config' 已成功重命名为 'renamed-config'

当前配置已更新为 'renamed-config'

工作原理

CEM 使用直接修改 Claude Code settings.json 的方案,具有以下特点:

  1. 直接修改配置:CEM 直接读取和修改 Claude Code 的 settings.json 文件
  2. 即时生效:切换配置后立即对新打开的 Claude Code 会话生效
  3. 持久化存储:所有配置信息存储在 ~/.cem/config.json

文件结构

~/.cem/
└── config.json       # CEM 配置管理文件

~/.claude/
└── settings.json     # Claude Code 配置文件(由 CEM 自动管理)

配置文件格式

~/.cem/config.json:

{
  "version": "1.0.0",
  "current": "work",
  "configs": {
    "default": {
      "baseURL": "https://api.claude.ai",
      "token": "sk-xxx..."
    },
    "work": {
      "baseURL": "https://work.claude.ai",
      "token": "sk-yyy..."
    }
  }
}

当切换配置时,CEM 会将对应的 baseURLtoken 写入到 ~/.claude/settings.json 文件中,格式如下:

~/.claude/settings.json:

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://work.claude.ai",
    "ANTHROPIC_AUTH_TOKEN": "sk-yyy..."
  }
}

命令参考

| 命令 | 别名 | 说明 | |------|------|------| | cem add <alias> | - | 添加新配置(交互式) | | cem import <json> | - | 从 JSON 导入配置 | | cem ls | list | 列出所有配置 | | cem show <alias> | - | 显示配置详情 | | cem current | - | 显示当前配置 | | cem use <alias> | - | 切换配置 | | cem rename <old> <new> | - | 重命名配置别名 | | cem rm <alias> | remove, delete, del | 删除配置 | | cem edit <alias> | - | 编辑配置 | | cem local | - | 设置或显示语言 | | cem --help | -h | 显示帮助 | | cem --version | -V | 显示版本 |

常见问题

Q: 如何批量导入多个配置?

A: 使用 cem import 命令从 JSON 格式导入配置。适合从其他工具迁移或备份恢复。

示例:

cem import '{"ANTHROPIC_BASE_URL":"https://api.anthropic.com","ANTHROPIC_AUTH_TOKEN":"sk-ant-xxx"}' --alias prod

Q: import 命令支持哪些 JSON 字段?

A: 支持灵活的字段名:

  • URL 字段:baseURLANTHROPIC_BASE_URL
  • Token 字段:tokenANTHROPIC_AUTH_TOKEN
  • 还可以添加任意自定义变量(如 ANTHROPIC_VERSION 等)

Q: 切换配置后什么时候生效?

A: 切换配置后立即对新打开的 Claude Code 会话生效。当前正在运行的会话不受影响。

Q: 配置文件存储在哪里?

A: CEM 配置存储在 ~/.cem/config.json,Claude Code 配置在 ~/.claude/settings.json

Q: 如何手动编辑配置?

A: 可以直接编辑 ~/.cem/config.json 文件,但建议使用 cem 命令进行管理。

Q: 如何重命名配置别名?

A: 使用 cem rename 命令:

cem rename old-alias new-alias

如果重命名的是当前活跃的配置,别名更改后会自动更新当前配置引用。

Q: 不同终端窗口可以使用不同配置吗?

A: 可以!每个 Claude Code 实例会读取当前的 settings.json 文件,因此在不同终端窗口打开的 Claude Code 可以使用不同配置。

开发

# 安装依赖
npm install

# 开发模式(监听文件变化)
npm run dev

# 构建
npm run build

# 代码格式化
npm run format

# 代码检查
npm run lint

许可证

MIT