# Codex (ChatGPT subscription)

> Sign in to a ChatGPT Plus or Pro subscription with sc auth codex, declare the codex endpoint in config.toml, and build a codex profile.
>
> Sign in with sc auth codex and run Claude Code's roles on GPT models through your ChatGPT Plus or Pro subscription, with no API key.

1. Declare the codex endpoint

   ```toml
   [endpoints.codex]
   url = "https://chatgpt.com/backend-api/codex"
   format = "openai-responses"
   auth = "oauth"

   [endpoints.codex.oauth]
   provider = "codex"
   ```

   The `config.toml` that `sc` writes on first run carries this endpoint commented out. Uncomment it or paste the block. Do this before you sign in, because the login reads `oauth.provider`.

2. Sign in

   ```sh
   sc auth codex
   ```

   Your browser opens at the OpenAI sign-in page, and `sc` waits up to five minutes. On success it prints:

   ```text
   sc: signed in to `codex` as `default` (account <account-id>).
   ```

3. Add a profile and check it

   ```toml
   [profiles.codex]
   opus   = { slug = "codex/gpt-5.5", reasoning = { effort = "high" } }
   sonnet = { slug = "codex/gpt-5.4", reasoning = { effort = "medium" } }
   haiku  = { slug = "codex/gpt-5.4", reasoning = { effort = "low" } }
   ```

   ```sh
   sc profiles codex
   ```

   The part after `codex/` is any model id your subscription serves. The ids above come from the Codex profile that the starter `config.toml` carries commented out.

4. Launch on it

   ```sh
   sc -u codex <project> <agent>
   ```

   A profile row whose OAuth endpoint has no signed-in identity fails the launch before Claude Code starts, with the message in the fold below.

The tokens go into `config.toml`. The file stays at mode `0600`, `sc` never prints a token, and the daemon refreshes the access token when a request finds it within two minutes of expiry. There is nothing to rotate by hand.

**Sign in on a machine with no browser**

```sh
sc auth codex --device
```

`sc` prints a URL and a one-time code:

```text
To sign in on another device, open:
  https://auth.openai.com/codex/device
and enter the code:
  <code>
```

Open the URL on any device and enter the code; `sc` finishes when you approve it.

The browser flow needs port `1455` on `localhost`, because the provider's OAuth client registration fixes it. If another `sc auth` or another Codex client holds that port, the login fails with `cannot bind the OAuth loopback callback server`. Stop the other process and retry, or use `--device`, which needs no local port.

**See what sc stored for my sign-in**

After a login, the identity table looks like this. The values are written by `sc auth`; leave the table alone, because the daemon rewrites it on every refresh:

```toml
[endpoints.codex.oauth.identities.default]
refresh_token = "<written by sc auth>"
access_token = "<written by sc auth>"
expires_at = 0
account_id = "<written by sc auth>"
```

- `expires_at` is the access token's expiry, in Unix seconds.
- `account_id` is your ChatGPT account id, read from the token. The gateway sends it as the `ChatGPT-Account-Id` header, so Codex bills the right account.

List every OAuth endpoint and its stored labels:

```sh
sc auth list
```

```text
OAuth identities — ~/.superclaude/config.toml
  codex  [codex]
      default  ••••xY   valid (52m left)  account <account-id>
```

| Status | Meaning |
|---|---|
| `valid (<n>m left)` | the access token is good for more than two minutes |
| `expiring soon (refreshes on next use)` | under two minutes left |
| `expired (refreshes on next use)` | past expiry; the next request refreshes it |
| `(no access token yet)` | the identity has no expiry recorded |

Expired is not an error. The gateway refreshes the token before it sends a request, and writes the new pair back to `config.toml`.

With no signed-in identity, the launch fails with:

```text
endpoint `codex` (role `opus`) has auth=oauth but no signed-in identities — run `sc auth codex [--label <name>]`
```

**Add a second ChatGPT account**

```sh
sc auth codex --label work
sc auth remove codex --label work
```

Every stored label joins the endpoint's pool, and the gateway spreads requests across them. Codex rate-limits per ChatGPT account, not per token, so a second label for the same account gives you two tokens that share one limit. Add labels only for different accounts; `sc` cannot check this, and prints a note when you add a second label. `remove` always needs `--label`, including for `default`.

**Sign in again**

```sh
sc auth codex --label default
```

Signing in to an existing label replaces its tokens. You need it when the refresh token is rejected, for example after you revoke access or your subscription lapses, or when Codex answers `401` or `403` although the local token had not expired. In both cases the session gets an error naming the fix:

```text
oauth identity `default` for endpoint `codex` needs sign-in — run `sc auth codex --label default`
```

If the pool holds another label, the gateway also cools the failed label for 60 seconds, so the next request goes to the other label while you sign in again.

**Sign in to a different OAuth endpoint**

| Command | What it does |
|---|---|
| `sc auth <endpoint>` | browser login into the `default` label |
| `sc auth <endpoint> --label <name>` | log in another, named identity |
| `sc auth <endpoint> --device` | login with a one-time code, for a machine with no browser |
| `sc auth list` | every OAuth endpoint's labels, masked tokens and expiry |
| `sc auth remove <endpoint> --label <name>` | delete one stored identity |

`sc auth` supports two providers, `codex` and [`grok`](/docs/provider-grok). Any other `oauth.provider` value fails with `unknown oauth provider`.
