Skip to content

wyl1924/LNP-Manager

Repository files navigation

LNP

中文 | English


中文

简洁、跨平台的 Codex (ChatGPT) / Antigravity (Google Gemini) / Claude 多账号切换工具,支持网页面板、额度检查、精准刷新、账号排序,以及回到默认干净环境。

👤 作者信息

  • 作者: WYL
  • 项目: LNP
  • 版本: 1.0.0
  • 许可证: MIT License

⚙️ 环境依赖

  • 本工具基于 Python 编写,运行前需确保已安装 Python 3.10+
  • 无第三方依赖库,无需额外执行 pip install,下载即用。
  • 如果设置了环境变量 CODEX_HOME,本项目会优先使用该目录;否则默认使用 ~/.codex

✨ 核心功能

  • 轻量管理:保存当前账号并归档认证文件,便于多账号切换。
  • 智能识别:自动从 JWT 解析邮箱、套餐和账号信息。
  • 网页总览:提供 Web 面板查看账号、额度、会员状态和重置时间。
  • 精准刷新:支持调用官方 usage 接口获取更准确的额度数据。
  • 自动刷新:支持账户 token 自动刷新,并在启动时检查到期额度后自动重试刷新。
  • Token 保活队列:支持手动开关;开启后后台按账号串行刷新登录凭据。
  • 智能排序:按当前使用状态、会员、额度、重置时间对账号排序。
  • 跨平台:提供 Windows / macOS / Linux 启动脚本和安装脚本。

🚀 快速开始

直接运行即可,无需任何额外配置。 代码内置了各平台的默认 OAuth 凭据,开箱即用。

🔧 自定义凭据(可选)

什么时候需要这一步? 只有当你想用自己申请的 OAuth App 凭据替换内置默认值时才需要操作。普通用户直接跳过,正常运行即可。

如果内置凭据因官方更新失效,或者你希望使用自己的 OAuth App,请按以下方式修改:

第一步:创建本地配置文件

cp config/secrets.json.example config/secrets.json

config/secrets.json 已被 .gitignore 忽略,不会上传到 Git。

第二步:填入你的凭据

打开 config/secrets.json,按需填写以下字段(只填要替换的,其余留空即用内置值):

字段 说明
antigravity_client_id Google OAuth Client ID
antigravity_client_secret Google OAuth Client Secret
codex_auth_client_id OpenAI/Codex OAuth App ID
claude_client_id Anthropic Claude OAuth App ID
archive_dir_name 账号归档目录名(默认 wyl-lnp

各平台凭据怎么获取:

🟦 Antigravity (Google Gemini) — 申请 Google OAuth App(可自助)

Google 支持自行注册 OAuth App,步骤如下:

  1. 打开 Google Cloud Console 并登录
  2. 新建或选择一个项目
  3. 左侧菜单 → APIs & ServicesCredentials
  4. 点击 + CREATE CREDENTIALSOAuth client ID
  5. Application type 选 Desktop app,名称随意
  6. 创建成功后,复制显示的 Client IDClient Secret
  7. APIs & ServicesLibrary 中搜索并启用 Cloud AI Platform API
  8. 把 Client ID 填入 antigravity_client_id,Secret 填入 antigravity_client_secret
⬛ Codex (ChatGPT / OpenAI) — 获取 OpenAI 官方 App Client ID

OpenAI 官方 Codex CLI 使用固定的 App Client ID,不支持自助注册。获取最新值的方法:

  • 查看 openai/codex 开源仓库源码,搜索 CLIENT_ID 常量
  • 或直接安装 Codex CLI 后在本地文件中查找

将获取到的值填入 codex_auth_client_id

🟠 Claude (Anthropic) — 获取 Claude 官方 App Client ID

Anthropic 官方 Claude Code 使用固定的 App Client ID,不支持自助注册。获取最新值的方法:

  • 查看 anthropics/claude-code 开源仓库源码,搜索 CLIENT_ID 常量
  • 或直接安装 Claude Code 后在本地文件中查找

将获取到的值填入 claude_client_id

  • Windows (PowerShell / 双击):
start-LNP.bat
  • macOS / Linux (Terminal):
./start-LNP.sh
  • Python:
python codex.py

默认会打开 Web 面板;如果要进入命令行菜单,可以追加 --cli

方式 2:安装全局命令

安装后会把当前项目复制到本地目录,并写入全局快捷命令 LNP

  • Windows:
install-LNP-command.ps1
  • macOS / Linux:
./install-LNP-command.sh

默认安装到 ~/.codex/LNP-app;如果设置了 CODEX_HOME,则安装到 $CODEX_HOME/LNP-app

方式 3:命令行模式

python codex.py --cli

或:

python -m scripts --cli

📖 使用说明

💡 如何登录并保存新账号?(重要指引)

  1. 请不要在 Codex 软件内点击"退出登录 (Logout)"。
  2. 先运行本工具,通过网页按钮"添加当前账号"或 CLI 菜单 2"保存当前登录",把当前已登录账号保存下来,并起一个别名,例如 work
  3. 如果要登录一个全新账号,可以切换到"默认 / 干净状态"。
  4. 重新打开 Codex 软件并登录新账号。
  5. 再次运行本工具,把新账号保存进来,例如命名为 gmail
  6. 之后就可以在这些已收录账号之间自由切换。

🧭 日常操作说明

  1. 启动 Web 面板:平时直接启动 Web 面板,即可查看当前账号(如 Codex, Antigravity, Claude 等)和全部已保存账号的状态及额度。
  2. 账号平滑切换:如果只是切换账号,不需要手动做 token 刷新。后台系统会按队列自动维护已保存账号的登录凭据,保持 Token 鲜活。
  3. 获取最新额度:如果想看最新额度,优先点击“刷新额度”;只有在需要和官网后台数据严格对齐时,再点击“精准刷新”。
  4. 处理失效账号:如果某个账号提示“自动刷新登录凭据失败”或提示 refresh token 已失效,请在 Web 页面切换到该账号,进入相应的平台重新登录一次,再回到 Web 面板使用“添加当前账号”重新保存并覆盖即可。
  5. 环境重置与隔离:当需要登录一个全新账号时,可以点击“重置环境”(分别支持 Codex / Antigravity / Claude),确保环境干净不串号,然后再进行新账号登录。

📦 基于 Git 的项目更新与维护

我们强烈推荐使用 Git 管理本项目,以便您能随时获取最新功能和修复。

1. 获取最新版本更新 当项目有新版本或新功能发布时,您可以通过以下命令快速拉取远程的最新代码:

git pull origin main

提示:如果在拉取后遇到依赖变更,请参考本文档中的说明重启服务。

2. 解决本地修改导致的更新冲突 如果您在本地修改了部分脚本或配置文件,在拉取更新时可能会遇到代码冲突报错。您可以通过以下流程安全更新:

# 1. 暂存您本地的修改
git stash

# 2. 获取最新的官方代码
git pull origin main

# 3. 恢复您的本地修改并处理冲突
git stash pop

📁 目录结构

.codex/
└── LNP/                    # 已保存账号的认证归档目录
    ├── work/auth.json
    └── ...

LNP/
├── codex.py
├── start-LNP.bat
├── start-LNP.sh
├── install-LNP-command.ps1
├── install-LNP-command.sh
├── config/
│   ├── secrets.json.example  # 凭据模板(已提交到 Git)
│   ├── secrets.json          # 你的凭据(已被 gitignore,自己填写)
│   └── accounts.json
└── scripts/
    ├── main.py
    ├── service.py
    ├── web.py
    └── mcp_stdio_proxy.py

⚠️ 注意事项

  • 当前登录信息默认来自 ~/.codex/auth.json;如果设置了 CODEX_HOME,则使用 $CODEX_HOME/auth.json
  • 已保存账号默认备份到 ~/.codex/LNP/<别名>/auth.json;如果设置了 CODEX_HOME,则使用 $CODEX_HOME/LNP/<别名>/auth.json
  • 本地额度快照默认来自 ~/.codex/sessions;如果设置了 CODEX_HOME,则使用 $CODEX_HOME/sessions
  • 工具不会上传本地认证文件,数据默认只保留在本机。

📄 许可证

本项目采用 MIT License 许可证。

🤝 贡献

欢迎提交问题反馈和功能建议!

📧 联系方式

如有问题或建议,请通过邮件联系:

  • 邮箱:[您的邮箱]

English

A lightweight, cross-platform multi-account switcher for Codex (ChatGPT) / Antigravity (Google Gemini) / Claude, with a Web dashboard, quota checks, precise refresh, account sorting, and clean-session reset.

👤 Author Information

  • Author: WYL
  • Project: LNP
  • Version: 1.0.0
  • License: MIT License

⚙️ Prerequisites

  • This tool is written in Python. You need Python 3.10+ installed.
  • No third-party dependencies are required. No pip install step is needed.
  • If CODEX_HOME is set, the project uses that directory first; otherwise it defaults to ~/.codex.

✨ Core Features

  • Lightweight management: save current accounts and archive auth files for switching.
  • Smart parsing: extract email, plan, and account identity from JWT tokens.
  • Web dashboard: inspect accounts, quota, member status, and reset times visually.
  • Precise refresh: call the official usage endpoint for more accurate quota data.
  • Auto refresh: refresh account tokens automatically and retry quota refresh on startup when needed.
  • Token keepalive queue: can be enabled manually for background credential maintenance.
  • Smart sorting: sort accounts by current state, membership, quota, and reset time.
  • Cross-platform: provide launcher and installer scripts for Windows / macOS / Linux.

🚀 Quick Start

Works out of the box — no configuration required. Built-in default credentials for each platform are included.

🔧 Custom Credentials (Optional)

If you want to use your own OAuth App (e.g. a Google Cloud OAuth app you registered yourself), create config/secrets.json to override the defaults:

# Copy the template
cp config/secrets.json.example config/secrets.json
# Then open config/secrets.json and fill in your values

config/secrets.json is listed in .gitignore and will never be committed to Git.

Field Description How to obtain
antigravity_client_id Google OAuth Client ID See below ↓
antigravity_client_secret Google OAuth Client Secret See below ↓
codex_auth_client_id OpenAI/Codex OAuth App ID See below ↓
claude_client_id Anthropic Claude OAuth App ID See below ↓
archive_dir_name Account archive folder name (default: wyl-lnp) Customize freely
🟦 Antigravity (Google Gemini) — Create a Google OAuth App
  1. Open Google Cloud Console and sign in
  2. Create or select a project
  3. Go to APIs & ServicesCredentials
  4. Click + CREATE CREDENTIALSOAuth client ID
  5. Choose Desktop app as the application type
  6. After creation, copy the Client ID and Client Secret
  7. Enable the required API: search for Cloud AI Platform API and enable it
  8. Paste the values into config/secrets.json
⬛ Codex (ChatGPT / OpenAI) — Get the OpenAI App Client ID

OpenAI's Codex CLI uses a fixed official App Client ID that cannot be self-registered via Console. Look up the CLIENT_ID constant in the openai/codex source code and paste it into codex_auth_client_id.

🟠 Claude (Anthropic) — Get the Claude OAuth Client ID

Anthropic's Claude Code uses a fixed official App Client ID that cannot be self-registered via Console. Look up the CLIENT_ID constant in the anthropics/claude-code source code and paste it into claude_client_id.

  • Windows:
start-LNP.bat
  • macOS / Linux:
./start-LNP.sh
  • Python:
python codex.py

The default behavior is to open the Web dashboard. Add --cli to open the terminal menu instead.

Method 2: Install a global command

  • Windows:
install-LNP-command.ps1
  • macOS / Linux:
./install-LNP-command.sh

The default install path is ~/.codex/LNP-app; if CODEX_HOME is set, the install path becomes $CODEX_HOME/LNP-app.

Method 3: CLI mode

python codex.py --cli

📖 Usage Instructions

💡 How to log in and save a new account? (Important Guide)

  1. Please do not click "Logout" within the Codex/Claude software.
  2. Run this tool first, and use the Web "Add Current Account" button or CLI menu 2 to save the currently logged-in account with an alias, e.g., work.
  3. If you want to log in to a completely new account, switch to the "Default / Clean Environment" state.
  4. Reopen the software and log in with the new account.
  5. Run this tool again to save the new account, e.g., gmail.
  6. Afterward, you can freely switch between these saved accounts.

🧭 Daily Operation Instructions

  1. Launch Web Dashboard: For regular use, start the Web dashboard directly to view the status and quotas of the current account (e.g., Codex, Antigravity, Claude) and all saved accounts.
  2. Smooth Account Switching: If you are simply switching accounts, there is no need to manually refresh the tokens. The background queue will automatically maintain login credentials for saved accounts to keep the tokens alive.
  3. Fetching Latest Quota: If you want to see the latest quota, click "Refresh Quota" first. Only click "Precise Refresh" if you strictly need to align with the official data.
  4. Handling Invalid Accounts: If an account shows "Auto refresh credentials failed" or indicates the refresh token is invalid, switch to that account on the Web page, log in again on the respective platform, and then use "Add Current Account" on the Web dashboard to save and overwrite the credentials.
  5. Environment Reset & Isolation: When you need to log in to a completely new account, click "Reset Environment" (supported independently for Codex / Antigravity / Claude) to ensure a clean session, then proceed to log in with the new account.

📦 Git-based Project Update and Maintenance

We highly recommend using Git to manage this project so you can easily receive the latest features and bug fixes.

1. Fetching Latest Updates When a new version or feature is available, you can quickly pull the latest code using:

git pull origin main

Tip: If you encounter changes requiring restarts, refer to this document to restart your services.

2. Resolving Update Conflicts from Local Changes If you have modified some scripts or config files locally, you might encounter conflict errors when pulling updates. You can update safely using this workflow:

# 1. Stash your local changes
git stash

# 2. Get the latest code from the remote
git pull origin main

# 3. Restore your local changes and resolve any conflicts
git stash pop

📁 Directory Layout

.codex/
└── LNP/                    # Archived auth files for saved accounts
    ├── work/auth.json
    └── ...

LNP/
├── codex.py
├── start-LNP.bat
├── start-LNP.sh
├── install-LNP-command.ps1
├── install-LNP-command.sh
├── config/
│   ├── secrets.json.example  # Credential template (committed to Git)
│   ├── secrets.json          # Your credentials (gitignored, fill in yourself)
│   └── accounts.json
└── scripts/
    ├── main.py
    ├── service.py
    ├── web.py
    └── mcp_stdio_proxy.py

⚠️ Notes

  • The current login state comes from ~/.codex/auth.json by default, or $CODEX_HOME/auth.json when CODEX_HOME is set.
  • Saved accounts are archived under ~/.codex/LNP/<alias>/auth.json by default, or $CODEX_HOME/LNP/<alias>/auth.json when CODEX_HOME is set.
  • The tool does not upload local auth files; data stays on the local machine by default.

📄 License

This project is licensed under the MIT License.

🤝 Contributing

Issues and suggestions are welcome!

📧 Contact

For questions or suggestions:

  • Email: [Your Email]

About

本地codex、 claude、 Antigravity 号池管理系统

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages