360 Secure SkillHub
360 安全技能中心

Codex Account Switcher

通过捆绑脚本读取 OpenClaw 中 openai-codex 的 OAuth 配置,向 ChatGPT 使用量接口查询各账号配额,按邮箱或 profile id 调整 auth-state.json 的 provider 顺序切换首选账号,并可在 5 小时剩余额度低于阈值时自动切换;另含 Codex CLI 登录导入与备份,脚本不打印令牌等凭据内容。

unknown-shu
unknown-shu
热度 32.87
最近更新 2026-05-11 17:46:21
分类:自动化依赖:代码执行 / 读写文件 / 第三方 API应用场景:自动化脚本 / 工作流 / DevOps

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add unknownshu-codex-account-switcher
Metadata
name
codex-account-switcher
description
Query OpenAI Codex OAuth account quotas in OpenClaw, switch the preferred account by email/profile id, and optionally auto-switch when 5h quota drops below a threshold. Use for OpenClaw model account management and quota-aware failover.
metadata
{"openclaw":{"emoji":"🔁","requires":{"bins":["python3","openclaw"]},"optionalEnv":["OPENCLAW_HOME","OPENCLAW_AGENT_ID","OPENCLAW_AUTH_STATE","OPENCLAW_AUTH_PROFILES","OPENCLAW_CODEX_SWITCH_THRESHOLD","OPENCLAW_CODEX_SWITCH_SUFFICIENT_THRESHOLD","OPENCLAW_CODEX_SWITCH_NOTIFY_GROUP"]}}

Codex Account Switcher

Use the bundled scripts to manage openai-codex OAuth profiles without exposing tokens.

Commands

From this skill directory:

python3 scripts/openclaw-accounts-query.py
python3 scripts/openclaw-account-switch.py user@example.com --dry-run
python3 scripts/openclaw-account-switch.py user@example.com
python3 scripts/codex-cli-sync.py --dry-run
python3 scripts/codex-cli-sync.py
python3 scripts/openai-codex-auto-switch.py --dry-run
python3 scripts/openai-codex-quota-query.py --json

Behavior

  • Reads OpenClaw auth profile metadata from the selected agent directory.
  • Queries quota directly from ChatGPT WHAM usage using each profile's OAuth access token.
  • Never prints access tokens, refresh tokens, API keys, or credential file contents.
  • Account switching only rewrites auth-state.json provider order for openai-codex.
  • codex-cli-sync.py is advanced/explicit: it imports the current Codex CLI ~/.codex/auth.json login into OpenClaw and writes backups first.
  • Auto-switch defaults to switching only when the active account's 5h remaining quota is below 20%.

Useful environment variables

export OPENCLAW_HOME="$HOME/.openclaw"
export OPENCLAW_AGENT_ID="main"
export OPENCLAW_CODEX_SWITCH_THRESHOLD=20
export OPENCLAW_CODEX_SWITCH_SUFFICIENT_THRESHOLD=20

For cron, use an absolute path to scripts/openai-codex-auto-switch.py and redirect output to logs.

Safety

Do not paste script output containing local paths into public places without review. Do not commit auth-state.json, auth-profiles.json, .env, logs, or screenshots containing account emails unless you intend to share them.