关于 caam
CAAM 是用于 Claude Code、Codex CLI 和 Gemini CLI 的 Go 命令行工具,可备份和切换多个账号的认证文件。它还支持隔离配置并行运行、轮换选择和遇到速率限制时自动故障切换。
主要功能
- 01备份与即时切换认证配置
- 02通过内容哈希识别当前账号
- 03隔离账号目录以支持并行会话
- 04按健康度和冷却状态轮换账号
- 05速率限制后自动故障切换
- 06提供终端仪表板与项目关联
适用场景
- 01达到使用限制后切换到另一账号
- 02在不同终端同时运行多个账号
- 03让命令按项目目录使用指定账号
- 04查看账号状态并管理冷却时间
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ dicklesworthstone/ agent_flywheel_clawdbot_skills_and_integrations --skill caam安装后在 Claude Code 中输入/caam确认已加载。
详细介绍
CAAM — 编码 Agent 账户管理器
一款 Go 命令行工具,可在固定费用的 AI 编码订阅账号(Claude Max、GPT Pro、Gemini Ultra)之间即时切换。达到速率限制时,可在约 50 毫秒内切换账号,无需经历 30–60 秒的浏览器 OAuth 操作。
为什么要开发这个工具
你每月要为固定费用的 AI 编码订阅支付 200–275 美元。这些套餐有滚动使用限额——不是账单上限,而是会随时间重置的速率限制。若在工作流程中途达到限额:
问题:
/login → browser opens → sign out of Google → sign into different Google →
authorize app → wait for redirect → back to terminal
每天在多个工具中遇到 5 次以上,就要经历 30–60 秒的操作延迟。
解决方案:
caam activate claude [email protected] # ~50ms, done
无需浏览器,无需繁琐的 OAuth 流程,也不会打断当前工作。
工作原理
每个 AI CLI 都会将 OAuth 令牌存储在普通文件中。CAAM 会备份并恢复这些文件:
~/.claude.json ←→ ~/.local/share/caam/vault/claude/[email protected]/
~/.codex/auth.json ←→ ~/.local/share/caam/vault/codex/[email protected]/
就是这么简单。 无需守护进程、数据库或网络调用,只不过是多做几步的 cp 操作。
为什么这样可行
OAuth 令牌是持有者令牌——持有令牌即拥有访问权限。除了令牌文件中已有的信息,CLI 工具不会进一步采集机器指纹。替换文件就相当于“成为”该已认证会话。
配置文件检测
caam status 使用内容哈希:
- 对当前身份验证文件计算 SHA-256 哈希值
- 与保险库中的所有配置文件进行比较
- 匹配成功 = 当前活动配置
这意味着:
- 即使手动切换,仍能检测到配置文件
- 没有可能导致状态不同步的隐藏状态文件
- 重启后也能正常工作
快速开始
# Install
curl -fsSL "https://raw.githubusercontent.com/Dicklesworthstone/coding_agent_account_manager/main/install.sh?$(date +%s)" | bash
# Backup current account
caam backup claude [email protected]
# Clear and login to another account
caam clear claude
claude # /login with [email protected]
caam backup claude [email protected]
# Switch instantly forever
caam activate claude [email protected] # < 100ms
caam activate claude [email protected] # < 100ms
# Check status
caam status
两种运行模式
1. 保险库配置文件(简单切换)
原位替换身份验证文件。每个工具一次只能激活一个账号,可即时切换。
caam backup claude [email protected]
caam activate claude [email protected]
适用场景: 需要依次在多个账号之间切换(最常见)。
2. 隔离配置文件(并行会话)
使用完整的目录隔离,同时运行多个账号。
caam profile add codex [email protected]
caam profile add codex [email protected]
caam exec codex [email protected] -- "implement feature X"
caam exec codex [email protected] -- "review code"
每个配置文件都有自己的 $HOME 和 $CODEX_HOME,并通过符号链接连接到你实际使用的 .ssh、.gitconfig 等目录。
适用场景: 需要在不同终端中同时运行两个账号。
支持的工具
| 工具 | 订阅 | 身份验证文件 |
|---|---|---|
| Claude Code | Claude Max(200 美元/月) | ~/.claude.json、~/.config/claude-code/auth.json、~/.claude/settings.json |
| Codex CLI | GPT Pro(200 美元/月) | ~/.codex/auth.json(或 $CODEX_HOME/auth.json) |
| Gemini CLI | Gemini Ultra(约 275 美元/月) | ~/.gemini/settings.json、~/.gemini/oauth_credentials.json、~/.gemini/.env |
各工具详情
Claude Code(Claude Max)
- 登录: 在 CLI 中输入
/login - 速率限制: 5 小时滚动使用时段
- 备注: 达到限额时会看到速率限制提示。切换账号即可继续使用。
Codex CLI(GPT Pro)
- 登录: 使用
codex login或codex login --device-auth(无头模式) - 备注: 支持
CODEX_HOME。CAAM 会通过向~/.codex/config.toml写入cli_auth_credentials_store = "file",强制使用基于文件的身份验证。
Gemini CLI(Google One AI Premium)
- 登录: 启动
gemini,选择“Login with Google”,或使用/auth切换模式 - 备注: OAuth 缓存存储在
oauth_credentials.json中,API 密钥模式使用.env。
命令参考
身份验证文件切换(主要功能)
| 命令 | 说明 |
|---|---|
caam backup <tool> <email> | 将当前身份验证文件保存到保险库 |
caam activate <tool> <email> | 从保险库恢复身份验证文件(即时切换) |
caam status [tool] | 显示当前活动配置文件 |
caam ls [tool] | 列出保险库中保存的所有配置文件 |
caam delete <tool> <email> | 删除已保存的配置文件 |
caam paths [tool] | 显示各工具的身份验证文件路径 |
caam clear <tool> | 删除身份验证文件(退出登录状态) |
caam uninstall | 恢复原始文件并移除 caam 数据/配置 |
别名: caam switch 和 caam use 的作用与 caam activate 相同
激活选项
| 标志 | 说明 |
|---|---|
--auto | 使用轮换算法选择最佳配置文件 |
--backup-current | 切换前备份当前身份验证信息 |
--force | 即使配置文件处于冷却状态也激活 |
卸载选项
| 标志 | 说明 |
|---|---|
--dry-run | 显示将恢复/移除的内容 |
--keep-backups | 恢复原始内容后保留保险库 |
--force | 跳过确认提示 |
智能配置文件管理
| 命令 | 说明 |
|---|---|
caam activate <tool> --auto | 使用轮换算法自动选择最佳配置文件 |
caam next <tool> | 预览轮换算法将选择的配置文件 |
caam run <tool> [-- args] | 包装 CLI,在遇到速率限制时自动故障转移 |
caam cooldown set <provider/profile> | 将配置文件标记为受到速率限制(默认:60 分钟) |
caam cooldown list | 列出有效冷却及剩余时间 |
caam cooldown clear <provider/profile> | 清除配置文件的冷却状态 |
caam cooldown clear --all | 清除所有有效冷却状态 |
caam project set <tool> <profile> | 将当前目录与某个配置文件关联 |
caam project get [tool] | 显示当前目录的项目关联 |
caam tui | 交互式 TUI 仪表板 |
配置文件隔离(高级)
| 命令 | 说明 |
|---|---|
caam profile add <tool> <email> | 创建隔离的配置文件目录 |
caam profile ls [tool] | 列出隔离的配置文件 |
caam profile delete <tool> <email> | 删除隔离的配置文件 |
caam profile status <tool> <email> | 显示隔离配置文件的状态 |
caam login <tool> <email> | 为隔离配置文件运行登录流程 |
caam exec <tool> <email> [-- args] | 使用隔离配置文件运行 CLI |
智能配置文件管理
当你在多个提供商拥有多个账户时,手动跟踪哪些账户还有可用额度会变得很繁琐。智能配置文件管理可自动完成这一决策过程。
配置文件健康评分
每个配置文件都会显示健康状态指示器:
| 图标 | 状态 | 含义 |
|---|---|---|
| 🟢 | 健康 | Token 有效期超过 1 小时,且近期没有错误 |
| 🟡 | 警告 | Token 将在 1 小时内过期,或存在轻微问题 |
| 🔴 | 严重 | Token 已过期,或最近 1 小时内反复出现错误 |
| ⚪ | 未知 | 暂无可用健康数据 |
健康评分综合考虑:
- Token 过期时间:距离 OAuth Token 过期的时间
- 错误历史:近期的身份验证或速率限制错误
- 惩罚分数:累积的问题及其指数衰减(每 5 分钟减少 20%)
- 套餐类型:Enterprise/Pro 套餐可获得轻微评分加成
约 30 分钟没有错误后,惩罚分数会降至接近零。
主动刷新 Token
CAAM 会在 OAuth Token 过期前自动刷新,防止会话中途出现身份验证失败。
智能轮换算法
运行 caam activate claude --auto 时:
| 算法 | 说明 |
|---|---|
| smart(默认) | 多因素:冷却状态、健康状况、最近使用时间(避开最近 30 分钟内使用的配置文件)、套餐类型、随机抖动 |
| round_robin | 按顺序轮换,跳过处于冷却状态的配置文件 |
| random | 从未处于冷却状态的配置文件中随机选择 |
在 ~/.caam/config.yaml 中配置:
stealth:
rotation:
enabled: true
algorithm: smart # smart | round_robin | random
cooldown:
enabled: true # Warn when activating cooldown profiles
冷却跟踪
当账户触发速率限制时,将其标记出来,以便轮换时跳过该账户:
# Mark current Claude profile (default: 60 min cooldown)
caam cooldown set claude
# Specify profile and duration
caam cooldown set claude/[email protected] --minutes 120
# View active cooldowns
caam cooldown list
# Clear a cooldown early
caam cooldown clear claude/[email protected]
当 stealth.cooldown.enabled: true 时,激活处于冷却状态的配置文件会发出警告并提示确认。使用 --force 可跳过此限制。
使用 caam run 自动故障转移
通过自动处理速率限制来包装 CLI 执行:
caam run claude -- "explain this code"
# If Claude hits rate limit mid-session:
# 1. Current profile goes into cooldown
# 2. Next best profile selected via rotation
# 3. Command re-executed with new account
选项:
| 标志 | 默认值 | 描述 |
|---|---|---|
--max-retries N | 1 | 最大重试次数 |
--cooldown DURATION | 60m | 触发速率限制后的冷却时长 |
--algorithm NAME | smart | 轮换算法 |
--quiet | off | 不显示配置切换通知 |
零摩擦别名:
alias claude='caam run claude --'
alias codex='caam run codex --'
alias gemini='caam run gemini --'
现在,claude "explain this" 会透明地处理速率限制。
项目与配置关联
将配置关联到项目目录:
cd ~/projects/work-app
caam project set claude [email protected]
# Now whenever you're in this directory
caam activate claude # Automatically uses [email protected]
关联会逐级继承:在 /home/user/projects 上设置的关联会应用于所有子目录,除非存在更具体的关联。
TUI 快捷键: 按 p 将当前配置设为工作目录的默认配置。
预览轮换选择
$ caam next claude
Recommended: [email protected]
+ Healthy token (expires in 4h 32m)
+ Not used recently (2h ago)
Alternatives:
[email protected] - Used recently (15m ago)
In cooldown:
[email protected] - In cooldown (45m remaining)
可用于了解轮换选择,或编写条件逻辑脚本。
使用情况分析
CAAM 会跟踪各配置的启用模式和会话时长,帮助你了解使用分布。
TUI 仪表板
用于可视化管理配置的交互式终端 UI:
caam tui
TUI 功能
- 带健康状态指示器的可视化配置列表
- 冷却状态显示
- 状态栏中显示项目关联
- 热重载:在另一个终端修改配置时自动刷新
TUI 快捷键
| 按键 | 操作 |
|---|---|
↑/↓ | 浏览配置 |
Enter | 启用所选配置 |
p | 设置项目关联 |
c | 标记/清除冷却状态 |
r | 刷新 |
q | 退出 |
保管库结构
~/.local/share/caam/
├── vault/ # Saved auth profiles
│ ├── claude/
│ │ ├── [email protected]/
│ │ │ ├── .claude.json # Backed up auth
│ │ │ ├── auth.json # From ~/.config/claude-code/
│ │ │ └── meta.json # Timestamp, original paths
│ │ └── [email protected]/
│ ├── codex/
│ │ └── [email protected]/
│ │ └── auth.json
│ └── gemini/
│ └── [email protected]/
│ └── settings.json
│
└── profiles/ # Isolated profiles (advanced)
└── codex/
└── [email protected]/
├── profile.json # Profile metadata
├── codex_home/ # Isolated CODEX_HOME
│ └── auth.json
└── home/ # Pseudo-HOME with symlinks
├── .ssh -> ~/.ssh
└── .gitconfig -> ~/.gitconfig
工作流示例
日常工作流
# Morning: Check what's active
caam status
# claude: [email protected] (active)
# codex: [email protected] (active)
# gemini: [email protected] (active)
# Afternoon: Hit Claude usage limit
caam activate claude [email protected]
claude # Continue immediately with new account
多账户初始设置
# 1. Login to first account using normal flow
claude # /login → authenticate with [email protected]
# 2. Backup the auth using email as profile name
caam backup claude [email protected]
# 3. Clear and login to second account
caam clear claude
claude # /login → authenticate with [email protected]
# 4. Backup that too
caam backup claude [email protected]
# 5. Switch instantly forever!
caam activate claude [email protected] # < 100ms
caam activate claude [email protected] # < 100ms
并行会话设置
# Create isolated profiles
caam profile add codex [email protected]
caam profile add codex [email protected]
# Login to each (one-time, opens browser)
caam login codex [email protected]
caam login codex [email protected]
# Run simultaneously in different terminals
caam exec codex [email protected] -- "implement auth system"
caam exec codex [email protected] -- "review PR #123"
智能轮换工作流
# Let rotation pick the best profile
caam activate claude --auto
# Using rotation: claude/[email protected]
# Recommended: [email protected]
# + Healthy token (expires in 4h 32m)
# + Not used recently (2h ago)
# Hit a rate limit? Mark it
caam cooldown set claude
# Recorded cooldown for claude/[email protected] until 14:30 (58m remaining)
# Next activation picks another profile automatically
caam activate claude --auto
# Using rotation: claude/[email protected]
零摩擦模式
# Add aliases to .bashrc/.zshrc
alias claude='caam run claude --'
alias codex='caam run codex --'
# Use tools normally
claude "explain this authentication flow"
# If rate limited mid-session, caam automatically:
# 1. Marks current profile as in cooldown
# 2. Selects next best profile via rotation
# 3. Re-runs command with new profile
# All transparent - you just see the output
安装
# One-liner (recommended)
curl -fsSL "https://raw.githubusercontent.com/Dicklesworthstone/coding_agent_account_manager/main/install.sh?$(date +%s)" | bash
# From source
git clone https://github.com/Dicklesworthstone/coding_agent_account_manager
cd coding_agent_account_manager
go build -o caam ./cmd/caam
sudo mv caam /usr/local/bin/
# Go install
go install github.com/Dicklesworthstone/coding_agent_account_manager/cmd/caam@latest
提示
- 使用真实邮箱作为配置名称——便于自我说明,永远不会忘记对应的账户
- 清除前先备份:
caam backup claude [email protected] && caam clear claude - 使用 --backup-current 标志:
caam activate claude [email protected] --backup-current - 经常检查状态:
caam status会显示所有工具的当前启用状态 - 不要在多台机器间同步保管库——身份验证令牌通常包含特定于机器的标识符
- 使用
caam paths——如果工具更新改变了身份验证文件位置,此命令会显示当前路径
常见问题
问:这适用于 API 密钥吗? 不适用。CAAM 面向使用 OAuth 的固定费用订阅计划(Claude Max、GPT Pro、Gemini Ultra)。API 密钥无需切换——只需使用不同的密钥即可。
问:这违反服务条款吗? 不违反。你使用的是自己合法购买的订阅。CAAM 管理本地身份验证文件,不会共享账户、绕过速率限制或修改 API 流量。每个账户仍受各自使用限额约束。
问:如果工具更新并更改了身份验证文件位置,该怎么办?
运行 caam paths 查看当前位置。如果位置发生变化,我们会更新 CAAM。如果发现不一致,请提交问题反馈。
问:我可以在多台机器间同步保管库吗? 不要这样做。身份验证令牌通常包含特定于机器的标识符(设备 ID 等)。请在每台机器上分别备份和恢复。
问:保管库配置与隔离配置有什么区别?
- 保管库配置(
backup/activate):原地切换身份验证,一次只能启用一个账户 - 隔离配置(
profile add/exec):完全隔离目录,可同时运行多个账户
问:切换会中断正在运行的会话吗? 可能会导致正在运行的 CLI 出现身份验证错误。最佳做法是在开始新会话前切换,而不是在会话进行时切换。
问:如何知道当前使用的是哪个账户?
运行 caam status。它会根据内容哈希匹配,显示每个工具的当前启用配置。
与 Flywheel 集成
| 工具 | 集成方式 |
|---|---|
| NTM | 每个 tmux 窗格都可通过隔离的配置文件使用不同账户 |
| Agent Mail | Agent 可在各会话之间协调账户切换 |
| CASS | 按账户搜索会话,以跟踪使用模式 |
| DCG | 无交互(CAAM 管理身份验证,DCG 防护命令) |