Skip to content

Feature request: one-shot automatic account switch #147

Description

@bjspi

Hi, thanks for this project — it is very useful for managing multiple Codex accounts.

I would like to request a one-shot auto-switch command, for example:

codex-auth switch --auto

or alternatively:

codex-auth auto-switch --once

Use case

I want to integrate codex-auth into a Codex hook/script.

The script should be able to trigger an account switch on demand without knowing:

  • which accounts are currently logged in
  • which accounts are available
  • which account still has free usage limits
  • which concrete account name/email should be passed to codex-auth switch

Desired behavior

The command should check the locally known accounts and switch once to the next account that still has available/free limits.

Important: this should not enable automatic background switching or start a daemon. It should only perform a single switch when explicitly called.

So the behavior would be:

  1. User/script calls codex-auth switch --auto
  2. codex-auth checks available accounts / usage state
  3. It selects the next suitable account with remaining limits
  4. It switches the active Codex session once
  5. The command exits

Why this is useful

This would make codex-auth much easier to use in automation hooks.

For example, a Codex hook could simply call:

codex-auth switch --auto

without needing to parse account names, emails, aliases, or usage status manually.

This would provide the benefits of automatic account selection, but only as an explicit one-time action, without background behavior.

Possible command names

Possible options could be:

  • codex-auth switch --auto
  • codex-auth switch --auto --once
  • codex-auth auto-switch --once
  • codex-auth auto --once

The main point is: automatic account selection, but only for one explicit command execution.

This would be especially useful for scripting hooks that just want to switch to any currently usable account without having to know the concrete account name in advance.

Thanks!

Activity

  1. Loongphy commented on Jul 3, 2026

    @Loongphy
    Owner

    Have you tested that?

    It seems that Codex CLI does not invoke user-configured hooks when a usage limit is triggered.

  2. bjspi commented on Jul 3, 2026

    @bjspi
    Author

    I tested and it's as you described: Unfortunately the hooks don't run in case usage limits are triggered.

    BUT: I still use this feature because I have a simple Batchfile on my Desktop which triggers "codex-auth switch --auto" without the need of giving a concrete account.

    I like this because it is generic and works, instead of checking the list and table of your accounts manually and then switch from there. My PR makes codex-auth "work automatically" without any need for user-interaction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions