
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
@hcg1023/claude-env-manager
Advanced tools
Claude Environment Manager - Manage and switch Claude Code configurations
CEM 是一个命令行工具,用于管理和快速切换 Claude Code 的多个配置(baseURL 和 TOKEN)。
# 克隆仓库
git clone <your-repo-url>
cd cem
# 安装依赖
npm install
# 构建
npm run build
# 全局链接
npm link
cem add <alias>
交互式添加新配置,需要输入:
示例:
$ cem add work
? Enter baseURL: https://api.claude.ai
? Enter TOKEN: ********
✓ Configuration 'work' added successfully
? Switch to this configuration now? Yes
cem import <json> --alias <alias>
从 JSON 格式的配置导入。支持灵活的字段名:
baseURL 或 ANTHROPIC_BASE_URLtoken 或 ANTHROPIC_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 的方案,具有以下特点:
~/.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 会将对应的 baseURL 和 token 写入到 ~/.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 | 显示版本 |
A: 使用 cem import 命令从 JSON 格式导入配置。适合从其他工具迁移或备份恢复。
示例:
cem import '{"ANTHROPIC_BASE_URL":"https://api.anthropic.com","ANTHROPIC_AUTH_TOKEN":"sk-ant-xxx"}' --alias prod
A: 支持灵活的字段名:
baseURL 或 ANTHROPIC_BASE_URLtoken 或 ANTHROPIC_AUTH_TOKENANTHROPIC_VERSION 等)A: 切换配置后立即对新打开的 Claude Code 会话生效。当前正在运行的会话不受影响。
A: CEM 配置存储在 ~/.cem/config.json,Claude Code 配置在 ~/.claude/settings.json。
A: 可以直接编辑 ~/.cem/config.json 文件,但建议使用 cem 命令进行管理。
A: 使用 cem rename 命令:
cem rename old-alias new-alias
如果重命名的是当前活跃的配置,别名更改后会自动更新当前配置引用。
A: 可以!每个 Claude Code 实例会读取当前的 settings.json 文件,因此在不同终端窗口打开的 Claude Code 可以使用不同配置。
# 安装依赖
npm install
# 开发模式(监听文件变化)
npm run dev
# 构建
npm run build
# 代码格式化
npm run format
# 代码检查
npm run lint
MIT
FAQs
Claude Environment Manager - Manage and switch Claude Code configurations
We found that @hcg1023/claude-env-manager demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.