Skip to content

Commit baba870

Browse files
committed
Merge branch 'pr-132-head' into release-integration-20260320
2 parents 11073f3 + ecdd4ee commit baba870

13 files changed

Lines changed: 787 additions & 61 deletions

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,21 @@ codex auth fix --dry-run
109109
codex auth doctor --fix
110110
```
111111

112+
If the shell should not launch a browser, use the manual callback flow:
113+
114+
```bash
115+
codex auth login --manual
116+
CODEX_AUTH_NO_BROWSER=1 codex auth login
117+
```
118+
119+
In non-TTY/manual shells, provide the full redirect URL on stdin instead of waiting for a browser callback:
120+
121+
```bash
122+
echo "http://127.0.0.1:1455/auth/callback?code=..." | codex auth login --manual
123+
```
124+
125+
No new npm scripts or storage migration steps are required for this login-flow update.
126+
112127
---
113128

114129
## Command Toolkit
@@ -234,6 +249,7 @@ codex auth login
234249
- `codex auth` unrecognized: run `where codex`, then follow `docs/troubleshooting.md` for routing fallback commands
235250
- Switch succeeds but wrong account appears active: run `codex auth switch <index>`, then restart session
236251
- OAuth callback on port `1455` fails: free the port and re-run `codex auth login`
252+
- Browser launch is blocked or you are in a headless shell: re-run `codex auth login --manual` or set `CODEX_AUTH_NO_BROWSER=1`
237253
- `missing field id_token` / `token_expired` / `refresh_token_reused`: re-login affected account
238254

239255
</details>

docs/features.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ User-facing capability map for `codex-multi-auth`.
5454
| Quick switch and search hotkeys | Faster navigation in the dashboard |
5555
| Account action hotkeys | Per-account set, refresh, toggle, and delete shortcuts |
5656
| In-dashboard settings hub | Runtime and display tuning without editing files directly |
57-
| Browser-first OAuth with manual fallback | Works in normal and constrained terminal environments |
57+
| Browser-first OAuth with manual fallback | `codex auth login` stays browser-first, while `--manual`, `--no-browser`, and `CODEX_AUTH_NO_BROWSER=1` keep login usable in browser-restricted shells |
58+
59+
Manual/non-TTY login accepts the full callback URL on stdin, so automation and host-managed shells can complete auth without relying on a local browser handoff.
5860

5961
---
6062

docs/getting-started.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ codex auth list
5656
codex auth check
5757
```
5858

59+
If browser launch is blocked or you want to handle the callback manually:
60+
61+
```bash
62+
codex auth login --manual
63+
CODEX_AUTH_NO_BROWSER=1 codex auth login
64+
```
65+
66+
In non-TTY/manual shells, provide the full redirect URL on stdin:
67+
68+
```bash
69+
echo "http://127.0.0.1:1455/auth/callback?code=..." | codex auth login --manual
70+
```
71+
72+
`codex auth login` remains browser-first by default. No new npm scripts or storage migration steps are required for this auth-flow update.
73+
5974
---
6075

6176
## Add More Accounts
@@ -111,6 +126,7 @@ If the OAuth callback on port `1455` fails:
111126

112127
- stop the process using port `1455`
113128
- rerun `codex auth login`
129+
- if browser launch is unavailable, rerun `codex auth login --manual`
114130

115131
If account state looks stale:
116132

docs/reference/commands.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Compatibility aliases are supported:
4545

4646
| Flag | Applies to | Meaning |
4747
| --- | --- | --- |
48+
| `--manual`, `--no-browser` | login | Skip browser launch and use manual callback flow |
4849
| `--json` | verify-flagged, forecast, report, fix, doctor | Print machine-readable output |
4950
| `--live` | forecast, report, fix | Use live probe before decisions/output |
5051
| `--dry-run` | verify-flagged, fix, doctor | Preview without writing storage |
@@ -55,11 +56,23 @@ Compatibility aliases are supported:
5556

5657
---
5758

59+
## Upgrade Notes
60+
61+
- `codex auth login` remains browser-first by default.
62+
- `codex auth login --manual` and `codex auth login --no-browser` force the manual callback flow instead of launching a browser.
63+
- `CODEX_AUTH_NO_BROWSER=1` suppresses browser launch for automation/headless sessions. False-like values such as `0` and `false` do not disable browser launch by themselves.
64+
- In non-TTY/manual shells, pass the full redirect URL on stdin, for example: `echo "http://127.0.0.1:1455/auth/callback?code=..." | codex auth login --manual`.
65+
- No new npm scripts or storage migration steps were introduced for this auth-flow update.
66+
67+
---
68+
5869
## Compatibility and Non-TTY Behavior
5970

6071
- `codex` remains the primary wrapper entrypoint. It routes `codex auth ...` and the compatibility aliases to the multi-auth runtime, and forwards every other command to the official `@openai/codex` CLI.
6172
- In non-TTY or host-managed sessions, including `CODEX_TUI=1`, `CODEX_DESKTOP=1`, `TERM_PROGRAM=codex`, or `ELECTRON_RUN_AS_NODE=1`, auth flows degrade to deterministic text behavior.
6273
- The non-TTY fallback keeps `codex auth login` predictable: it defaults to add-account mode, skips the extra "add another account" prompt, and auto-picks the default workspace selection when a follow-up choice is needed.
74+
- `codex auth login --manual` keeps the login flow usable in browser-restricted shells by printing the OAuth URL and accepting manual callback input instead of trying to open a browser.
75+
- In non-TTY/manual shells, provide the full redirect URL on stdin, for example: `echo "http://127.0.0.1:1455/auth/callback?code=..." | codex auth login --manual`.
6376

6477
---
6578

docs/upgrade.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ codex auth forecast --live --model gpt-5-codex
4949

5050
---
5151

52+
## Login Flow Upgrade Notes
53+
54+
- `codex auth login` remains the default browser-first path.
55+
- `codex auth login --manual` and `codex auth login --no-browser` force manual callback handling for browser-restricted shells.
56+
- `CODEX_AUTH_NO_BROWSER=1` suppresses browser launch for automation/headless sessions. False-like values such as `0` and `false` no longer force manual mode.
57+
- In non-TTY/manual shells, provide the full redirect URL on stdin, for example: `echo "http://127.0.0.1:1455/auth/callback?code=..." | codex auth login --manual`.
58+
- No new npm scripts, storage migrations, or extra upgrade steps were introduced for this auth-flow change.
59+
60+
For the full command/behavior reference, see [reference/commands.md](reference/commands.md).
61+
62+
---
63+
5264
## Configuration Upgrade Notes
5365

5466
During upgrades, runtime config source precedence is:

index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import {
3434
REDIRECT_URI,
3535
} from "./lib/auth/auth.js";
3636
import { queuedRefresh } from "./lib/refresh-queue.js";
37-
import { openBrowserUrl } from "./lib/auth/browser.js";
37+
import { isBrowserLaunchSuppressed, openBrowserUrl } from "./lib/auth/browser.js";
3838
import { startLocalOAuthServer } from "./lib/auth/server.js";
3939
import { promptAddAnotherAccount, promptLoginMode } from "./lib/cli.js";
4040
import {
@@ -2386,9 +2386,10 @@ while (attempted.size < Math.max(1, accountCount)) {
23862386

23872387
const accounts: TokenSuccessWithAccount[] = [];
23882388
const noBrowser =
2389+
inputs?.manual === "true" ||
23892390
inputs?.noBrowser === "true" ||
23902391
inputs?.["no-browser"] === "true";
2391-
const useManualMode = noBrowser;
2392+
const useManualMode = noBrowser || isBrowserLaunchSuppressed();
23922393
const explicitLoginMode =
23932394
inputs?.loginMode === "fresh" || inputs?.loginMode === "add"
23942395
? inputs.loginMode

lib/auth/browser.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import fs from "node:fs";
88
import path from "node:path";
99
import { PLATFORM_OPENERS } from "../constants.js";
1010

11+
const BROWSER_DISABLED_VALUES = new Set(["0", "false", "no", "off", "none"]);
12+
const NO_BROWSER_TRUTHY_VALUES = new Set(["1", "true", "yes", "on"]);
13+
1114
/**
1215
* Gets the platform-specific command to open a URL in the default browser
1316
* @returns Browser opener command for the current platform
@@ -19,6 +22,16 @@ export function getBrowserOpener(): string {
1922
return PLATFORM_OPENERS.linux;
2023
}
2124

25+
export function isBrowserLaunchSuppressed(): boolean {
26+
const explicitNoBrowser = (process.env.CODEX_AUTH_NO_BROWSER ?? "").trim().toLowerCase();
27+
if (explicitNoBrowser.length > 0) {
28+
return NO_BROWSER_TRUTHY_VALUES.has(explicitNoBrowser);
29+
}
30+
31+
const browserSetting = (process.env.BROWSER ?? "").trim().toLowerCase();
32+
return BROWSER_DISABLED_VALUES.has(browserSetting);
33+
}
34+
2235
/**
2336
* Determines whether a given command name exists on the system PATH.
2437
*
@@ -92,6 +105,10 @@ function commandExists(command: string): boolean {
92105
*/
93106
export function openBrowserUrl(url: string): boolean {
94107
try {
108+
if (isBrowserLaunchSuppressed()) {
109+
return false;
110+
}
111+
95112
// Windows: use PowerShell Start-Process to avoid cmd/start quirks with URLs containing '&' or ':'
96113
if (process.platform === "win32") {
97114
if (!commandExists("powershell.exe")) {

0 commit comments

Comments
 (0)