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

@yulongsheng123/cc-cli

v1.0.0

Published

快速切换Claude Code环境变量token的CLI工具

Readme

CC-CLI - Claude Code 配置管理工具

一个用于快速管理和切换 Claude Code 环境变量配置的命令行工具。

✨ 主要特性

  • 🚀 快速切换:轻松在多个 API 配置之间切换
  • 🎯 交互式界面:使用箭头键选择配置,直观易用
  • 🔐 安全存储:配置文件权限设置为 0600,仅所有者可读写
  • 🛠️ 自动配置:自动更新 Shell 配置文件(支持 bash 和 zsh)
  • 📦 轻量级:无额外依赖,即装即用

📦 安装

全局安装

npm install -g @yulongsheng123/cc-cli

要求

  • Node.js >= 14.0.0
  • 操作系统:macOS、Linux
  • Shell:bash、zsh

🚀 快速开始

1. 添加第一个配置

cc add work https://api.deerapi.com "sk-ant-xxxxx"

2. 查看所有配置

cc list

使用箭头键选择要激活的配置,按回车确认。

3. 使配置生效

source ~/.zshrc  # 或 source ~/.bashrc

📖 命令参考

cc -vcc --version

显示工具版本号。

cc -v
# 输出:cc version 1.0.0

cc add <name> <base_url> <token>

添加新的环境变量配置。

参数:

  • name:配置名称(唯一标识,仅允许字母、数字、下划线、连字符)
  • base_url:API 中转路径(必须是有效的 URL 格式,http 或 https)
  • token:认证令牌(支持引号包裹)

示例:

# 添加工作配置
cc add work https://api.deerapi.com "sk-ant-xxxxx"

# 添加个人配置
cc add personal https://api.example.com "sk-ant-yyyyy"

输出:

✓ 配置 'work' 已成功添加
✓ 环境变量已写入 shell 配置文件
⚠ 请执行以下命令使配置生效:
  source ~/.zshrc

cc list

列出所有配置并支持交互式切换。

cc list

交互界面:

? 请选择要激活的配置: (Use arrow keys)
❯ * work - https://api.deerapi.com
    personal - https://api.example.com
    test - https://api.test.com
  • * 标记表示当前激活的配置
  • 使用 箭头键移动
  • Enter 确认选择

输出:

✓ 已切换到配置 'personal'
⚠ 请执行以下命令使配置生效:
  source ~/.zshrc

cc remove <name>

删除指定的配置。

参数:

  • name:要删除的配置名称

示例:

cc remove work

输出:

✓ 配置 'work' 已成功删除

如果删除的是当前激活的配置,工具会自动切换到第一个可用配置:

✓ 配置 'work' 已成功删除
已自动切换到配置 'personal'
⚠ 请执行以下命令使配置生效:
  source ~/.zshrc

cc update

升级工具到最新版本。

cc update

输出:

正在检查更新...
发现新版本:1.2.0(当前版本:1.0.0)
正在升级...
✓ 升级成功!当前版本:1.2.0

cc --help

显示帮助信息。

cc --help

📁 配置文件说明

配置文件位置

配置文件存储在用户主目录下:

~/.cc-config.json

配置文件结构

{
  "version": "1.0.0",
  "activeConfig": "work",
  "configs": [
    {
      "name": "work",
      "baseUrl": "https://api.deerapi.com",
      "token": "sk-ant-xxxxx",
      "createdAt": "2024-12-29T10:00:00.000Z"
    },
    {
      "name": "personal",
      "baseUrl": "https://api.example.com",
      "token": "sk-ant-yyyyy",
      "createdAt": "2024-12-29T10:30:00.000Z"
    }
  ]
}

Shell 配置文件

工具会自动在以下文件中写入环境变量:

  • ~/.bash_profile
  • ~/.bashrc
  • ~/.zshrc

写入格式:

export ANTHROPIC_AUTH_TOKEN="sk-ant-xxxxx"
export ANTHROPIC_BASE_URL="https://api.deerapi.com"

❓ 常见问题

环境变量不生效怎么办?

每次添加或切换配置后,需要执行 source 命令使配置生效:

# zsh 用户
source ~/.zshrc

# bash 用户
source ~/.bashrc
# 或
source ~/.bash_profile

或者重新打开终端窗口。

如何查看当前激活的配置?

使用 cc list 命令,带 * 标记的即为当前激活的配置。

如何备份配置?

配置文件位于 ~/.cc-config.json,可以直接复制该文件进行备份:

cp ~/.cc-config.json ~/.cc-config.json.backup

如何手动编辑配置?

可以直接编辑 ~/.cc-config.json 文件,但请确保 JSON 格式正确。建议使用工具提供的命令进行管理。

如何卸载?

# 卸载 npm 包
npm uninstall -g @yulongsheng123/cc-cli

# 删除配置文件(可选)
rm ~/.cc-config.json

# 手动移除 Shell 配置文件中的环境变量(可选)
# 编辑 ~/.zshrc 或 ~/.bashrc,删除以下行:
# export ANTHROPIC_AUTH_TOKEN="..."
# export ANTHROPIC_BASE_URL="..."

Token 安全性如何?

  • 配置文件 ~/.cc-config.json 的权限设置为 0600(仅所有者可读写)
  • Token 以明文形式存储在配置文件中
  • 建议:请妥善保护好配置文件,不要将其上传到公共仓库

支持哪些 Shell?

目前支持:

  • bash
  • zsh

工具会自动检测当前使用的 Shell 类型并提供相应的提示。

可以在多台机器上使用相同的配置吗?

可以。只需将 ~/.cc-config.json 文件复制到其他机器的相同位置即可。

🔧 开发

本地开发

# 克隆项目
git clone <repository-url>
cd cc-cli

# 安装依赖
npm install

# 链接到全局(用于本地测试)
npm link

# 测试命令
cc --help

项目结构

cc-cli/
├── bin/
│   └── cli.js              # CLI入口文件
├── src/
│   ├── commands/           # 命令处理模块
│   │   ├── add.js
│   │   ├── list.js
│   │   ├── remove.js
│   │   ├── update.js
│   │   └── version.js
│   ├── utils/              # 工具函数
│   │   ├── config.js       # 配置文件管理
│   │   ├── logger.js       # 日志输出
│   │   ├── shell.js        # Shell操作
│   │   └── validator.js    # 参数验证
│   └── constants.js        # 常量定义
├── package.json
└── README.md

📝 许可证

MIT License

Copyright (c) 2024

🤝 贡献

欢迎提交 Issue 和 Pull Request!

📮 联系方式

如有问题或建议,请通过 Issue 联系。


享受更高效的配置管理体验! 🎉