Skip to content

Codex 0.147.0: token_exchange_failed after successful browser authentication on Windows and WSL #37467

Open

Description

@HansKohlhaas

What version of the Codex App are you using (From “About Codex” dialog)?

Codex 0.147.0

What subscription do you have?

ChatGPT Plus account

What platform is your computer?

No response

What issue are you seeing?

Codex 0.147.0: token_exchange_failed after successful browser authentication on Windows and WSL

Environment

  • Windows 11 x64
  • ChatGPT Plus account
  • Codex CLI: codex-cli 0.147.0
  • Codex installed via npm on Windows
  • Tested with Codex Desktop as well as Codex CLI
  • Additionally tested with a fresh Codex installation inside WSL/Linux

Problem

Codex authentication cannot be completed.

The browser authentication itself succeeds. After signing in, the browser confirms that authentication was successful and says that the page can be closed.

However, Codex subsequently fails when exchanging the authorization code for a token:

Sign-in could not be completed

Token exchange failed: error sending request for url
(https://auth.openai.com/oauth/token)

Error code: token_exchange_failed

Details:
Token exchange failed: error sending request for url
(https://auth.openai.com/oauth/token)

This occurs both with Codex Desktop and the Codex CLI.

Device authentication also fails

I also tested:

codex login --device-auth

This fails with:

Error logging in with device code:
error sending request for url
(https://auth.openai.com/api/accounts/deviceauth/usercode)

Network tests

DNS resolution works:

nslookup auth.openai.com

Name: auth.openai.com.cdn.cloudflare.net
Addresses:
2a06:98c1:310c::ac40:920f
2606:4700:4400::6812:29f
104.18.41.241
172.64.146.15
Aliases: auth.openai.com

HTTPS connectivity to the authentication server also exists:

curl -I https://auth.openai.com

returns:

HTTP/1.1 403 Forbidden
Cf-Mitigated: challenge
Server: cloudflare

So the machine can reach auth.openai.com, but Cloudflare responds with a challenge to the curl request.

Proxy tests

Windows WinHTTP configuration:

netsh winhttp show proxy

DirectAccess (no proxy server)

No proxy environment variables are present:

set | findstr /I "proxy"

returns no output.

Different network tested

To rule out the router, ISP connection, or public IP address, I disconnected the PC from the normal network and connected it through a mobile phone hotspot.

The Codex authentication failure remained exactly the same.

Therefore, the problem does not appear to be specific to the normal internet connection, router, or public IP.

WSL/Linux test

To rule out a problem specific to the native Windows Codex runtime, I installed WSL and a Linux environment.

Node.js/npm and Codex were installed natively inside WSL.

The Linux Codex installation was verified:

which codex
/usr/local/bin/codex

codex --version
codex-cli 0.147.0

I then ran:

codex login

The browser opened and authentication completed successfully. The browser explicitly indicated that the login was successful and that the page could now be closed.

After closing the browser page, however, Codex did not complete the login successfully.

The token exchange failed again.

Thus, the problem can be reproduced with:

  • Codex Desktop on Windows
  • Codex CLI on Windows
  • Codex CLI running natively inside WSL/Linux
  • normal internet connection
  • separate mobile hotspot

Additional symptom

Before investigating the authentication problem, Codex had also repeatedly produced connection errors similar to:

stream disconnected before completion:
error sending request for url
(https://chatgpt.com/backend-api/codex/responses)

It is unclear whether this is related, but it may indicate a more general connectivity problem between the Codex client and OpenAI endpoints.

At approximately the same time, the normal ChatGPT browser session unexpectedly required a new login. The ChatGPT browser login itself succeeded.

Summary

Browser authentication works, but Codex cannot complete the subsequent communication with OpenAI's authentication endpoints.

The issue persists after ruling out:

  • DNS resolution
  • normal internet connection
  • router
  • public IP (tested via mobile hotspot)
  • WinHTTP proxy
  • proxy environment variables
  • native Windows Codex runtime
  • alternative device authentication
  • Codex running inside WSL/Linux

The most notable observation is that the browser reports a successful Codex authentication, but the subsequent token exchange performed by Codex fails.

Please advise whether this could be related to the current Codex authentication/token exchange implementation, Cloudflare handling, or an account/session-side issue.

What steps can reproduce the bug?

I cant use codex or Chatgpt localy

What is the expected behavior?

It works until this afternoon - suddenly the connection was frozen

Additional information

No response

Activity

  1. added
    app
    on Aug 7, 2026
  2. added
    bug
    CLI
    windows-os
    auth
    connectivity
    on Aug 7, 2026
  3. github-actions commented on Aug 7, 2026

    @github-actions
    Contributor

    Potential duplicates detected. Please review them and close your issue if it is a duplicate.

    Powered by Codex Action

  4. HansKohlhaas commented on Aug 7, 2026

    @HansKohlhaas
    Author

    Related to #36490 — same token-exchange failure; additional evidence: WSL + hotspot + Cloudflare challenge.

  5. yxy050208 commented on Sep 21, 2026

    @yxy050208

    I recently reproduced the same Windows-side pattern: browser authentication completed successfully, but Codex failed during the final OAuth token exchange because the browser/system route and the route actually used by Codex were different.

    I turned the diagnostics from that investigation into a small open-source Windows utility: DevNet Doctor
    https://github.com/yxy050208/DevNetDoctor

    It compares WinINET/Windows system proxy, WinHTTP, process/user proxy environment variables, local proxy listener state, and direct vs system-proxy vs env-proxy reachability to the OpenAI OAuth endpoint. It also checks Codex respect_system_proxy without reading token contents.

    v0.1.0 release:
    https://github.com/yxy050208/DevNetDoctor/releases/tag/v0.1.0

    Disclosure: I'm the maintainer. This is diagnostic-first and does not assume every token_exchange_failed has the same cause. For this issue, the useful output is the redacted Findings + Route matrix, which can show whether Windows/WSL/Codex are actually taking different network paths.

  6. kushkatech commented on Sep 22, 2026

    @kushkatech

    I can reproduce a very similar issue on the current Windows Codex Desktop build.

    Important: started immediately after an update

    This issue started immediately after Codex Desktop updated to 26.915.4065.0.

    Before that update, Codex Desktop was working normally on the same machine, with the same ChatGPT account, VPN configuration, WSL2 environment, and projects.

    After the update, Codex started experiencing repeated connectivity problems, eventually logged me out, and I have not been able to sign in again since then.

    Environment

    • Codex Desktop: 26.915.4065.0
    • Windows x64
    • Agent environment: WSL2
    • WSL distro: OracleLinux 9.5
    • ChatGPT works normally in the browser on the same PC
    • No HTTP/HTTPS proxy configured
    • The Windows host normally routes IPv4 traffic through a VPN interface

    Error

    After completing the browser login, Codex Desktop fails with:

    Sign-in failed: Login server error: Token exchange failed: error sending request for url (https://auth.openai.com/oauth/token)

    Network tests

    The token endpoint itself is reachable from both Windows and WSL.

    From Windows, IPv4 through the VPN:

    curl.exe -4 -v -d "grant_type=test" https://auth.openai.com/oauth/token

    successfully establishes TLS and returns:

    HTTP/1.1 400 Bad Request

    with the expected OpenAI response saying that test is not a supported grant_type.

    The same POST over IPv6 also succeeds and returns the expected HTTP 400 response.

    From WSL:

    curl -4 -v -d "grant_type=test" https://auth.openai.com/oauth/token

    also successfully completes DNS, TLS 1.3 and HTTP/2, and OpenAI returns:

    HTTP/2 400

    with the expected invalid grant_type JSON response.

    So TCP connectivity, DNS, TLS certificate verification, Cloudflare access, and POST access to /oauth/token all work from both Windows and the WSL environment.

    Test-NetConnection auth.openai.com -Port 443 also succeeds.

    Rollback tests

    I also tested older Windows Desktop packages:

    • 26.908.4834.0
    • 26.911.7940.0

    Both older versions can launch, but I encounter persistent Reconnecting... behavior when trying to use the chat, so rollback has not provided a usable workaround.

    The application also attempted to automatically update back to 26.915.4065.0 after rollback.

    Additional observations

    The Desktop logs repeatedly contain WSL git watcher errors such as:

    EISDIR: illegal operation on a directory, watch '\\wsl$\OracleLinux_9_5\...'

    but I have not found the actual OAuth token_exchange_failed error in the Electron desktop log.

    Given that:

    • the exact same setup worked before the update,
    • the problem started immediately after updating to 26.915.4065.0,
    • browser authentication works,
    • /oauth/token is reachable from both Windows and WSL,
  7. kushkatech commented on Sep 23, 2026

    @kushkatech

    The sign-in issue (Token exchange failed) persists in Windows Codex Desktop 26.917.8451.0.

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

    CLIappauthbugconnectivitywindows-os

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions