达到用量限制时自动切换账号
本页由英文机器翻译而来,欢迎指正。 在 GitHub 上编辑此页
设置 auto_switch = true 后(Linux 和 macOS),Claude Code 因用量限制停下会话时,ccam 会自己把会话移到另一个账号,不用你输入任何命令,对话就在那里接着进行。这个功能默认关闭,属于实验性功能,开启后可能违反你所用套餐的条款(见下文)。不开启时,你可以用 ccam next --continue 或 /ccam:switch 自己切换(达到用量限制后继续工作)。
ccam: personal hit its 5-hour limit; continuing this conversation as side
→ personal → side
continuing "Fix the flaky tests" (about 182k tokens); prompt caches are not shared between organizations, so the first reply reads it all again; side does not share personal's history, so Claude Code copies it into sideTeam 和 Enterprise 席位。 在 Team 和 Enterprise 席位上,auto_switch 会把你的工作移到同一组织的另一个席位,这可能违反 Anthropic 的条款。依赖这项功能之前,请先阅读常见问题,并向你所在的组织和 Anthropic 确认。
开启方法
在每个账号中开启 ccam 插件,并使用 Claude Code 2.1.214 或更高版本,这些版本会把自己的进程 ID 传给插件的钩子(
CLAUDE_PID)。在
config.toml顶部、第一个[[group]]、[[profile]]或[[folder]]之前加上这项设置:# ~/.config/ccam/config.toml auto_switch = true # Linux and macOS; turns the relay on too通过 ccam 启动新会话:
ccam <name>、快捷命令或仪表盘。auto_switch会同时开启接力,所以 ccam 不再用 Claude Code 替换自身,而是在每个交互式会话旁边一直运行。代价是每个会话多一个等待中的 ccam 进程。运行
ccam doctor。开启auto_switch后,它会对没有装 ccam 插件的账号和低于 2.1.214 的 Claude Code 版本发出警告,对席位账号还会重申 Anthropic 关于席位的规定(检查项)。
在 Windows 上,这项设置会被忽略,ccam doctor 会说明这一点。不过在 Windows 上设置 relay = true 后,仍然可以用 /ccam:switch 和 /exit 把对话移到另一个账号。
达到限额时会发生什么
- Claude Code 因用量限制停下某一轮对话。插件的钩子选出另一个还有余量的账号,然后结束 Claude Code。
- 在会话旁边运行的 ccam 会在支持桌面通知的终端中显示通知,例如
ccam: personal hit its 5-hour limit (resets 3:29am). Moving this conversation to side (12% of its 5 hours used, the least). - ccam 打印上面示例的第一行,然后以选中的账号为这个会话运行
ccam next --continue。这条命令打印另外两行,并像接力那样,带着会话原来的选项、权限模式、推理强度和代理启动 Claude Code。 - 新会话以一条固定消息开始,这也是移动时唯一代你发送的消息(
/ccam:switch之后的移动什么也不发送):
Your usage limit was reached and ccam moved this conversation to another account. Continue the task you were working on when the limit was reached; do not repeat work that is already complete.如果是子代理达到了限额,消息会换成下面这条,因为子代理、工作流和后台命令已经随旧会话一起停止了:
A subagent hit your usage limit and ccam moved this conversation to another account. The subagents, workflows and background commands that were running then have stopped, and their results may be missing: run again what the task still needs, then continue it; do not repeat work that is already complete.如果新账号也达到了限额,同样的过程会在那里再来一次。用量限制记录保证这条链不会在某个账号重置之前又回到它那里,所以所有账号都满了时,会话就停在最后一个账号上。
要取消已经开始的移动,请在 Claude Code 关闭时按 Ctrl+C:ccam: switch cancelled. Run `ccam next --continue` later to continue the conversation.
ccam 何时移动会话
只有以下条件全部满足时,ccam 才会移动会话:
- 会话由 ccam 在终端中启动,并且 ccam 一直在它旁边运行。开启
auto_switch之后启动的交互式会话都满足这一条。在此之前启动的会话,或者在旧版 ccam 下启动的会话,会收到一条以This session started before auto_switch was on or under an older ccam, so ccam cannot move it: type /exit, then run `ccam next --continue`.结尾的通知。无人值守的会话(-p运行和后台会话)、claude remote-control以及不通过 ccam 启动的 Claude Code 永远不会被移动。 - 这个账号开启了 ccam 插件,并且运行 Claude Code 2.1.214 或更高版本。
- Claude Code 已把被拒绝的请求连同重置时间写入对话,并且触发的是这个账号的 5 小时、每周、Opus、Sonnet 或 Fable 限额。
- Fable 模型用完每周额度时,Claude Code 会显示
You've hit your Fable limit或You're out of usage credits,被拒绝的请求会注明是 Fable 的每周窗口。这就是 Fable 限额,下一个账号必须在它自己的 Fable 每周窗口中还有余量。 - 支出上限、其他请求中用量积分耗尽、组织设置的停用、服务器限流以及 API 密钥的速率限制,都不会让会话移动。
- 子代理或工作流代理遇到的限额也算,即使主对话只是在等它。如果那是 Opus、Sonnet 或 Fable 的每周限额,只有对话本身也使用这个模型时,会话才会移动。
- Fable 模型用完每周额度时,Claude Code 会显示
- ccam 知道这个账号的套餐,信息来自它的
.claude.json或ccam login记录的内容。不知道时,通知的结尾会是ccam does not know personal's plan, so auto_switch leaves this session. - 会话没有连接到 Remote Control。换成另一个账号后,它不会重新连上你用来操控它的应用,所以会话保持不动,通知也会说明这一点。
- 限额要在 15 分钟以后才重置。等待时间更短时,ccam 会把会话留给 Claude Code 处理:
ccam: personal hit its 5-hour limit, which resets in 9m; ccam leaves this session to wait for it. - 达到限额之后,你还没有输入过新的提示。
- 另一个账号还有余量(见下文)。
移到哪个账号
ccam 的选择方式和 ccam next --auto 相同,会考虑 auto_max_usage、auto_strategy 和对话所用的模型,并且只在与你离开的账号同类的账号中选择:同一个 Team 或 Enterprise 组织的另一个席位,或者另一个个人套餐(Pro 或 Max)。cross_org 和 --cross-org 在这里不适用。此外,目标账号还必须:已经登录,且登录信息能由 Claude Code 续期;有 ccam 知道的套餐;关闭了用量积分;已在 Claude Code 中信任这个文件夹;如果对话以某个代理运行,还要共享这个代理。完整的条件见 ccam 如何选择账号。
有用量限制记录的时间窗口按已满计算;最近 2 分钟内刚有其他会话移入的账号,排在其他账号之后。
不移动的情况
如果没有其他账号还有余量,就什么都不移动:Claude Code 照常处理这次限额,在会话中等待,或者给出它自己的选项。通知会告诉你哪个账号最先恢复,例如 ccam: personal hit its 5-hour limit (resets 3:29am). None of your other personal plans has room now; side frees up first, at 12:30am. Claude Code waits for personal here; /ccam:switch side after 12:30am moves it sooner. 对于席位,通知会说 None of your other accounts in Acme has room now。
如果上一节最后那几项账号条件把所有还有余量的账号都排除了,通知会指出是哪个账号以及原因:
side has not trusted this folder yet, so the conversation was not moved there. Open the folder once as side to allow it.side has room but its usage credits are on, so auto_switch did not move the conversation there; /ccam:switch side moves it.This conversation runs as agent "reviewer", and side does not share personal's agents, plugins and settings, so auto_switch did not move it there.
钩子通过 agent 设置得知对话以某个代理运行,或者从对话中指明代理的那一行得知;这一行由 Claude Code 不时写入,会话结束时也会写入。如果目前只有会话的 --agent 指明了代理,而选中的账号又不共享这些代理,ccam next --continue 就不会启动任何东西,并保留交接记录,同时第二条桌面通知会说明:ccam: this conversation runs as agent "reviewer", and side does not share personal's agents, plugins and settings, so ccam did not move it there. 标准错误上的错误信息还会补充:Its note stays: `ccam next --continue` continues it later, and `ccam personal --resume <session id>` continues it as personal after the reset。
移动的代价
- Claude Code 会重新启动,需要几秒钟。
- Claude 启动的后台 shell、开发服务器和代理会随旧会话一起停止。
- 和
ccam next --continue一样,新账号在第一次回复时要重读整段对话,ccam 会告诉你对话有多大。移动从不使用--brief。
它绝不会做的事
auto_switch 从不在 Claude Code 报告限额之前切换,从不在后台监视你的用量,也从不复制、续期或转交登录信息。
Anthropic 的条款
在 Team 和 Enterprise 席位上,auto_switch 会把你的工作移到同一组织的另一个席位。Anthropic 帮助中心关于 Team 套餐的说明写道:“Each seat on a Team plan is assigned to one named individual, and only that person may use it”(Team 套餐的每个席位都分配给一位指定的个人,只有这个人可以使用),以及“Users can't route their work through another user's account to use that user's remaining usage”(用户不能通过另一位用户的账号来处理自己的工作,以使用对方剩余的用量);关于 Enterprise 套餐的说明也是如此。
对于个人套餐(Pro、Max),Anthropic 的条款没有说明你自己的多个账号能否在达到限额时自动接替彼此。消费者条款(Consumer Terms)禁止“through automated or non-human means, whether through a bot, script, or otherwise”(通过自动化或非人工的方式,无论是借助机器人、脚本还是其他方式)访问服务,除非 Anthropic 明确允许;而一次移动会代你发送上面的某条固定消息。自 2026 年 11 月 12 日起生效的使用政策(Usage Policy)把“Intentionally bypass or interfere with capabilities, restrictions, or guardrails established within our products”(故意绕过或干扰我们产品中设定的功能、限制或防护措施)列为禁止事项之一。
ccam 不声称 auto_switch 符合这些条款。是否开启由你决定,风险也由你承担:如果 Anthropic 认为条款遭到违反,可能会暂停某个账号,或者暂停某个 Team 或 Enterprise 组织的访问权限。