Skip to content

feat(cli): add interactive account switcher and management tool#70

Open
quangnv13 wants to merge 2 commits into
Lampese:mainfrom
quangnv13:main
Open

feat(cli): add interactive account switcher and management tool#70
quangnv13 wants to merge 2 commits into
Lampese:mainfrom
quangnv13:main

Conversation

@quangnv13

Copy link
Copy Markdown

🚀 Add Interactive CLI Tool for Account Switching and Management

📝 Description

This Pull Request introduces an interactive command-line interface (CLI) to manage and switch between OpenAI/ChatGPT accounts. It allows users to quickly monitor account usage limits (5-hour and weekly quotas), rename/delete accounts, and perform OAuth authentication flows directly from the terminal.

To prevent console prints from interfering with the interactive terminal UI rendering, this PR also refactors the account usage logging to only output messages when the CODEX_DEBUG environment variable is defined.


✨ Key Features

  • 🖥️ Interactive Terminal Interface: Built with dialoguer and crossterm for clean navigation using arrow keys (or j/k) and Enter.
  • 📊 Real-time Quota Monitoring: Displays dynamic status bars representing remaining percentages for both 5-hour and weekly usage limits.
  • 💳 Credits & Balance Info: Shows credit status (unlimited, balance, or general status) for each account.
  • 🔑 OAuth Login Flow: Integrates with the existing authentication backend to trigger browser-based logins, listening for authorization completion directly from the CLI.
  • 🔄 Background Auto-Refresh: Auto-refreshes account usage in the background based on a configurable interval (stored in cli-config.json, defaults to 60 seconds), with support for manual refresh by pressing r.
  • 🛠️ Account Management: Quick access to Switch active account, Add account, Rename account, or Delete account from storage.

🛠️ Changes Details

1. New Binary: codex-switch

  • Added src-tauri/src/bin/codex-switch.rs implementing the full terminal user interface, keyboard event handling, auto-refresh scheduling, and terminal restoration safety.

2. Dependency Upgrades (src-tauri/Cargo.toml)

Added libraries to build the interactive CLI:

  • clap (v4.4 with derive) for parsing CLI args and metadata.
  • dialoguer (v0.11) for input prompts, confirmation boxes, and select menus.
  • console (v0.15) for terminal styling and colors.
  • crossterm (v0.29.0) for low-level terminal manipulation (raw mode, cursor hide/show, event polling).

3. Log Cleanup (src-tauri/src/api/usage.rs)

  • Replaced standard println! messages with a log_debug! macro. It ensures console logs are only printed when debugging is explicitly requested via CODEX_DEBUG=1, keeping the interactive CLI display clean and flicker-free.

4. Convenient Command Script (package.json)

  • Added a new shortcut command:
    pnpm cli
    Which translates to: cargo run --manifest-path src-tauri/Cargo.toml --bin codex-switch --

5. Documentation (README.md)

  • Added a new section Run the Interactive CLI describing how to run the CLI, its key features, and configuration.

🧪 How to Test

  1. Make sure dependencies are installed:
    pnpm install
  2. Start the interactive CLI:
    pnpm cli
  3. Test the navigation using $\uparrow$ / $\downarrow$ or j / k.
  4. Try switching accounts and verifying the active account marker (* [Active]).
  5. Add a new account using [Add Account], complete the browser authentication, and check if it gets registered and set as active in the CLI table.
  6. Press r to manually refresh account usage information.
  7. Verify that setting the environment variable CODEX_DEBUG=1 before running exposes the background debug logs.

quangnv13 added 2 commits June 8, 2026 22:37
- Implement interactive CLI switcher in codex-switch.rs

- Add CLI dependency libraries (clap, dialoguer, console, crossterm)

- Add cli script to package.json

- Refactor console prints in usage.rs to only log when CODEX_DEBUG is set
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant