CCS 是一个 Windows 命令行工具,让你在 不重启 Claude Code、不丢失当前对话上下文 的前提下,无缝切换多个 Claude 账号。
当你的 Claude 账号达到使用限制时,通常需要退出当前会话、重新登录另一个账号、再重新开始对话。CCS 通过本地反向代理拦截请求并替换认证令牌,让你在同一个会话中直接切换到另一个账号继续工作。
- 无缝切换:不中断当前 Claude Code 会话,下一次请求自动使用新账号
- 多账号管理:导入、查看、切换多个 Claude 账号
- Token 保活:独立后台 keepalive 进程,每 30 分钟自动刷新所有即将过期的 token
- 智能 401 恢复:上游返回认证失败时,自动通过三步策略恢复(检查 config → 同步 credentials → OAuth 刷新),对 Claude Code 完全透明
- 双向 token 同步:CCS 与 Claude Code 的凭据文件自动互相同步,避免 token 失效
- 重复导入检测:防止同一 token 被导入为不同账号名
- 零依赖:仅使用 Node.js 内置模块,无需安装任何第三方包
- 与原版共存:
ccs和原版claude命令互不干扰
- Windows 10/11
- Node.js >= 18.0.0
- Claude Code CLI 已安装(
claude命令可用)
git clone https://github.com/guoy0701/claude-code-account-switch.git
cd claude-code-account-switch
npm install -g .安装后 ccs 命令即可全局使用。
先用原版 Claude 登录第一个账号,然后导入:
# 在 Claude Code 中使用 /login 登录账号 A
# 退出 Claude Code 后执行:
ccs import account_a再登录第二个账号并导入:
# 在 Claude Code 中先 /logout,再 /login 登录账号 B
# 退出 Claude Code 后执行:
ccs import account_b导入时会自动启动 keepalive 保活服务,确保 token 不会过期。
ccs claude --dangerously-skip-permissions
# 或简写:
ccs --dangerously-skip-permissions当账号 A 达到限制时,在另一个终端窗口执行:
ccs switch account_b回到 Claude Code 窗口继续输入即可,下一次请求会自动使用账号 B。
| 命令 | 说明 |
|---|---|
ccs [claude] [参数...] |
启动代理模式的 Claude Code |
ccs import <名称> [凭据路径] |
导入账号(默认读取 ~/.claude/.credentials.json) |
ccs switch <名称> |
切换当前账号(下一次请求生效) |
ccs status |
查看当前状态 |
ccs accounts |
列出所有已导入账号 |
ccs keepalive |
启动 token 保活服务 |
ccs keepalive stop |
停止保活服务 |
ccs keepalive status |
查看保活服务状态 |
ccs doctor |
诊断检查 |
ccs stop |
停止后台 daemon |
用户输入 → Claude Code CLI → CCS 本地代理 (127.0.0.1:9876) → Anthropic API
↑
替换 OAuth token
为当前激活账号的 token
CCS 在本地启动一个反向代理服务器,拦截 Claude Code 发出的所有 API 请求,将认证头替换为当前激活账号的 OAuth token 后转发到 Anthropic API。切换账号时只需更改激活账号,下一次请求自动使用新 token。
CCS 通过多层机制确保 token 始终可用:
- Keepalive 保活进程:独立后台进程,每 30 分钟扫描所有账号,提前刷新即将过期(< 1 小时)的 token
- 401 智能恢复:当上游返回 401 时,按优先级尝试三步恢复:
- 检查 config 文件是否已被 keepalive 更新
- 从 Claude Code 的 credentials 文件同步
- 最后才执行 OAuth refresh
- 双向同步:CCS 刷新后会写回 Claude Code 凭据文件,反之亦然
- 登录和登出需要在原版 Claude Code 中使用
/login和/logout命令(不是claude login) ccs不会替换或修改原版claude命令- 同一个账号不要同时在
ccs和原版claude中使用,否则 refresh token 会互相失效 - 此工具面向个人本地使用,请自行评估平台政策风险
CCS is a Windows CLI tool that lets you seamlessly switch between multiple Claude accounts without restarting Claude Code or losing your conversation context.
When your Claude account hits its usage limit, you normally have to quit, log into another account, and start a new conversation. CCS runs a local reverse proxy that swaps the OAuth token on the fly, so you can switch accounts and keep working in the same session.
- Seamless switching: no session restart, the next request uses the new account automatically
- Multi-account management: import, list, and switch between accounts
- Token keepalive: independent background process refreshes all tokens every 30 minutes before they expire
- Smart 401 recovery: automatically recovers from auth failures via a three-step strategy (check config → sync credentials → OAuth refresh), fully transparent to Claude Code
- Bidirectional token sync: CCS and Claude Code's credential files stay in sync automatically
- Duplicate import detection: prevents the same token from being imported under different names
- Zero dependencies: uses only Node.js built-in modules
- Non-invasive:
ccsand the originalclaudecommand coexist without conflict
- Windows 10/11
- Node.js >= 18.0.0
- Claude Code CLI installed (
claudecommand available)
git clone https://github.com/guoy0701/claude-code-account-switch.git
cd claude-code-account-switch
npm install -g .The ccs command will be available globally after installation.
Log in with each account in the original Claude Code and import:
# Log in with account A using /login inside Claude Code
# After exiting Claude Code:
ccs import account_a
# Log out with /logout, log in with account B using /login
# After exiting Claude Code:
ccs import account_bThe keepalive service starts automatically after import to keep tokens fresh.
ccs claude --dangerously-skip-permissions
# or simply:
ccs --dangerously-skip-permissionsWhen account A hits its limit, open another terminal and run:
ccs switch account_bGo back to the Claude Code window and keep typing. The next request will use account B.
| Command | Description |
|---|---|
ccs [claude] [args...] |
Launch Claude Code in proxy mode |
ccs import <name> [cred-path] |
Import account (defaults to ~/.claude/.credentials.json) |
ccs switch <name> |
Switch active account (takes effect on next request) |
ccs status |
Show current status |
ccs accounts |
List all imported accounts |
ccs keepalive |
Start token keepalive service |
ccs keepalive stop |
Stop keepalive service |
ccs keepalive status |
Check keepalive service status |
ccs doctor |
Run diagnostics |
ccs stop |
Stop background daemon |
User input → Claude Code CLI → CCS local proxy (127.0.0.1:9876) → Anthropic API
↑
Replaces OAuth token
with the active account's token
CCS starts a local reverse proxy that intercepts all API requests from Claude Code, replaces the authentication header with the active account's OAuth token, and forwards the request to Anthropic's API. Switching accounts simply changes which token is injected on the next request.
CCS uses multiple layers to keep tokens always valid:
- Keepalive process: an independent background process scans all accounts every 30 minutes and proactively refreshes tokens expiring within 1 hour
- Smart 401 recovery: when the upstream returns 401, recovery is attempted in priority order:
- Check if the config file was already updated by keepalive
- Sync from Claude Code's credentials file
- OAuth refresh as a last resort
- Bidirectional sync: after CCS refreshes a token, it writes back to Claude Code's credential file, and vice versa
- Use
/loginand/logoutcommands inside Claude Code to manage authentication (notclaude login) ccsdoes not replace or modify the originalclaudecommand- Do not use the same account simultaneously in
ccsand the originalclaude— their refresh tokens will invalidate each other - This tool is intended for personal local use. Please evaluate platform policy risks on your own
MIT