Skip to content

How agent-driven CLIs hand off a device login #130

Closed

Description

@allisonmahmood

Question

patchy login prints a URL and a code that the agent relays to a human, then receives a machine token. An agent's shell tool waits for the process to exit, so a login that blocks until the browser confirms never gets its URL in front of anyone. Grilling on Device login: the protocol, and the machine token's columns could not settle the CLI's shape from the ticket alone. Find how CLIs that people drive from agents and headless machines actually do it, from their docs and source, not from memory:

  1. Blocking or two-step. For each of gh auth login, vercel login, fly auth login / flyctl, wrangler login, netlify login, supabase login, stripe login, railway login, heroku login, doppler login, turbo login, eas login, claude (Claude Code's own sign-in and claude setup-token), codex login, and any other CLI with a headless or agent story: does the command block until the browser confirms? Is there a non-interactive, --no-browser, --browserless, --device, --json or non-TTY behaviour that returns the handoff and finishes on a later call? Where do the URL and code print (stdout, stderr), and in what shape?
  2. What the URL carries. Does the browser URL carry the user code (RFC 8628 verification_uri_complete), a separate opaque id, or nothing (the person types the code)? Does a bare verification page exist alongside?
  3. Confirm or type. Which of them show the code for confirmation rather than asking the person to type it, and what does the confirm page say (machine name, account, expiry)?
  4. What the agent-first tools do. Claude Code, Codex CLI, Cursor's CLI, and any tool whose docs address running under an agent or in CI: how a token gets onto a machine nobody is sitting at, and whether they hand out long-lived tokens from a web page.
  5. Failure copy. What each prints when the code expires or the person denies.

Findings go in this ticket's resolution comment: a table for 1–3 with a source link per row, then the patterns that recur and the one or two shapes worth prototyping. No branch, no file in the tree. Read the docs and the source; say which claims you could not verify.

Activity

  1. added
    wayfinder:research
    on Sep 3, 2026
  2. allisonmahmood commented on Sep 3, 2026

    @allisonmahmood
    OwnerAuthor

    Resolution — how agent-driven CLIs hand off a device login

    Source and docs for 20 CLIs. Two headlines. Stripe and Netlify already ship what this ticket needs — hand back the URL, exit, finish on a later invocation. And Stripe does not gate on isatty; it gates on "is an agent driving me", sniffing CLAUDECODE, CLAUDE_CODE_ENTRYPOINT, CURSOR_AGENT, CODEX_*, GEMINI_CLI, OPENCODE, CLINE_ACTIVE and more. Its comment states our problem:

    // Agents with a real TTY (e.g. Claude Code) and headless environments (CI, /dev/null stdin) both return false, so nothing blocks waiting for an answer nobody is there to give. — login_helpers.go

    1–3. The table

    CLI blocks? headless / two-step path handoff prints URL carries type or confirm source
    stripe login only for a human at a TTY true two-step, auto for agents & non-TTY. --non-interactive → {browser_url, verification_code, next_step}, exits; device mode persists device_code/interval/expires_in to disk, --complete-device resumes stdout JSON opaque /stripecli/confirm?…; device path has no …_complete confirm the pairing code (device path: type) login.go
    netlify login by default true two-step. --request <msg> --json → {ticket_id, url, check_command, agent_next_steps}; --check <id> → pending/authorized/denied stdout JSON opaque ticket id neither login-request.ts
    gh auth login yes none; --with-token on stdin; GH_TOKEN stderr nothing (github.com/login/device) type flow.go
    vercel login yes none; --token rejected on login; VERCEL_TOKEN stderr verification_uri_complete confirm future.ts
    railway login yes --browserless; auto-detects $CI/$SSH_CONNECTION/no-DISPLAY stdout verification_uri_complete and bare code below both offered login.rs
    wrangler login yes — and still blocks 120 s in CI (the guard is only on implicit login) --device (RFC 8628), --browser=false, --callback-host/-port stdout prints bare URI + code, opens …_complete confirm; code printed so a phone works device-flow.ts
    turbo login yes none; degrades cleanly on non-TTY; --manual pastes a token stdout opens complete URI, prints bare URI + code type or confirm login.rs
    supabase login blocks on a stdin prompt, not a poll --token, stdin pipe, --no-browser (still needs a TTY) stdout session_id + ECDH public_key + token_name inverted — the browser shows the code, you type it into the CLI ensure-login.ts
    fly auth login yes, 15 min hard-errors on non-TTY, names the fix; -i + --email/--password/--otp stdout (failures stderr) opaque session id (name = hostname) neither; paste-code is the fallback webauth.go
    doppler login yes (5 min hard cap) --yes only; errors on non-TTY stdout nothing (static page) type (code auto-copied to clipboard) login.go
    heroku login yes (10 min long-poll) none; crashes on non-TTY (setRawMode, no guard); --sso pastes a token back stderr opaque session id confirm login.ts
    eas login yes, no timeout at all none; errors on non-TTY; --no-browser prompts; EXPO_TOKEN stdout PKCE authorize, no code neither; deny → hangs forever expoBrowserAuthFlowLauncher.ts
    claude /login yes unavailable in -p; fallback = page shows a code you paste at Paste code here if prompted terminal nothing (PKCE) paste back authentication
    claude setup-token yes is the CI path: prints a 1-year, inference-only token for CLAUDE_CODE_OAUTH_TOKEN terminal nothing n/a CI docs
    codex login yes (localhost :1455) --device-auth; --with-api-key/--with-access-token read stdin, refuse a TTY; or ssh -L 1455:localhost:1455 stderr (browser) / stdout (device) nothing type, + an anti-phishing line openai/codex
    cursor agent login yes NO_OPEN_BROWSER=1 prints the URL, still waits; CURSOR_API_KEY from the dashboard not verified not verified not verified cli authentication
    gcloud --no-browser yes (A blocks throughout) two machines, not two steps: A prints gcloud auth login --remote-bootstrap="…", B runs it, you paste the redirect URL back stderr the whole auth-code redirect URL paste, bold trust warning each way auth/login
    tailscale up yes --json emits two blocks: {AuthURL, QR, BackendState:"NeedsLogin"} then {BackendState:"Running"}; --auth-key file:… stderr / stdout JSON the URL is the secret neither up.go
    wix login yes non-TTY → "reports its progress as JSON instead of prompting you"; --api-key stdout JSON not verified not verified wix login
    az / aws sso / copilot yes --use-device-code (az falls back automatically); --device-code stderr / stdout / terminal nothing — aka.ms/devicelogin, device.sso…, github.com/login/device type az, aws, copilot

    Patterns that recur

    1. Blocking is the default; the two escapes are both JSON. 18 of 20 finish inside one process. The two that don't answer with one JSON document carrying the next command to run. Stripe's field is literally next_step; Netlify ships the agent's instructions in the payload as agent_next_steps: "Give the URL to the user so they can authorize. Then poll the check_command…". No prose to parse.
    2. isatty is the wrong gate — this ticket's exact bug. An agent's shell tool usually has a TTY. Only Stripe gets this right (interactiveHuman = stdinIsTerminal && DetectAIAgent(env) == ""). Turbo, railway, wix and az degrade on non-TTY-ish signals and mostly land well; wrangler login blocks for 120 s in CI because its guard is on the implicit login path only; heroku crashes.
    3. stdout vs stderr is genuinely split — gh, vercel, heroku, gcloud, az on stderr; railway, turbo, doppler, eas, wrangler, supabase, aws on stdout. The rule that survives is already ADR-0004's: payload a script captures → stdout, progress a human reads → stderr.
    4. Print the bare code even when the URL carries it. Vercel, railway, turbo, wrangler use verification_uri_complete; gh, aws, az, codex, doppler, copilot and Stripe's device path do not. Wrangler and Turborepo do both on purpose and cite the spec — wrangler quotes RFC 8628 §3.3.1 verbatim: "Clients MUST still display the user_code, as the authorization server will require the user to confirm it … as remote phishing mitigation." Railway's comment is the agent argument for the same thing: "a single URL survives being relayed through an agent transcript far better than a URL plus a separate code to transcribe."
    5. Confirm-not-type has precedent (Stripe's pairing code, vercel, heroku, wrangler, Claude Code's gateway SSO) and RFC 8628 §5.4 endorses it. Q2 of Device login: the protocol, and the machine token's columns #122 is on solid ground. Supabase inverts it — the browser shows the code and you type it into the terminal, which is phishing-resistant and needs no loopback or polling, but hard-requires a TTY. Cheapest to build, worst fit for agents.
    6. The CLI names the machine; the page usually doesn't show it. Doppler sends hostname/OS/arch/version, heroku Heroku CLI login from <hostname>, fly os.Hostname(), supabase cli_<user>@<hostname>_<epoch>, Stripe STRIPE_DEVICE_NAME. Supabase's is the one open-source confirm page, and it sends the token name but does not display it: title "Authorize Supabase CLI", subtitle "Enter this verification code in Supabase CLI to finish signing in", an 8-character code in boxed cells with a Copy button, the account's email, a footer pointing at Access Tokens. No scopes, no expiry. That is the whole page (login.tsx) — a useful floor for patchy login end to end: the handoff, the confirm page, the token #131 Q2.
    7. Failure copy is one line naming the retry, varied by how you got there. Stripe: device code expired; please run 'stripe login' again in the blocking path, …run 'stripe login --non-interactive' again in the two-step one. Also Device code expired. Please run 'railway login' again. / authorization denied by user / Device code expired before the request was approved. Please run 'wrangler login --device' again….
    8. The blocking path should name its own escape hatch inline. Codex prints on every run On a remote or headless machine? Use 'codex login --device-auth' instead.; fly's non-TTY error is fly auth login requires an interactive terminal. In headless environments, set FLY_API_TOKEN to a token created with 'fly tokens create'.
    9. Secrets arrive on stdin or a file, never argv, and every one of these has logout/status beside login.

    Shapes worth prototyping

    A — Stripe's shape (recommended). One command, split by the signal ADR-0004 already has plus agent detection. In a real human TTY patchy login blocks and prints the URL and code. Under --json, a non-TTY, or a detected agent, it writes exactly one JSON document to stdout and exits 0:

    { "verification_url": "https://…/login/device?code=WXYZ-4RT9",
      "verification_url_bare": "https://…/login/device", "user_code": "WXYZ-4RT9",
      "expires_at": "…", "interval": 5, "next": "patchy login --complete WXYZ-4RT9",
      "agent_next_steps": "Show the URL and code to the person, then run the next command." }

    patchy login --complete <code> polls and exits 0, 2 (rejected) on deny or expiry, 3 on unreachable — the exit ladder already covers every terminal state, and #122's POST /api/login/device/token is already the poll. Stripe persists the pending device code to disk so --complete needs no argument; worth trying both. This is the only shape here proven to work from inside an agent's shell tool.

    B — the fallback. One blocking command that prints the handoff to stderr before the poll starts (gh's shape) plus Codex's inline escape-hatch line. Cheaper, but it still depends on the agent's shell tool streaming stderr rather than buffering until exit — the exact failure this ticket opens with. Prototype A; keep B as the comparison in #131 Q1.

    Either way: print both the pre-filled URL and the bare code, and keep confirm-not-type on the page.

    Could not verify

    • What most confirm pages render (machine name, account, scopes, expiry) — Vercel, Netlify, Railway, Heroku, Doppler, Stripe, Cloudflare, Fly, Codex and Claude Code are all closed-source templates; Supabase's, quoted above, is the one exception. This is where patchy login end to end: the handoff, the confirm page, the token #131's prototype has no prior art to copy. Includes whether Stripe's page shows device_name (docs say only "visible in the Dashboard").
    • Whether claude setup-token prints to stdout or stderr — docs say only "prints to the terminal"; not run, since it mints a real one-year credential.
    • Cursor CLI's exact strings, stream and failure copy — not installed, no transcripts in the docs.
    • Denial/expiry copy for Vercel, Netlify, Doppler, Supabase and Stripe's device path, and Azure's literal device-code string — all relayed verbatim from the server, none authored in the CLI.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

wayfinder:research

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions