Codex CLI fails on native Termux (Android) - authentication, request, and lock failures

Open 💬 10 comments Opened Feb 14, 2026 by wallentx
💡 Likely answer: A maintainer (etraut-openai, contributor) responded on this thread — see the highlighted reply below.

What version of Codex CLI is running?

codex-cli 0.98.0

What subscription do you have?

Plus

Which model were you using?

All

What platform is your computer?

Linux 6.1.145-android14-11-gb812b232b095-ab14605088 aarch64 unknown

What terminal emulator and version are you using (if applicable)?

Termux 0.119.0-beta.3

What issue are you seeing?

Codex CLI does not function correctly on \\native Termux / Android\\. There are multiple related failure modes.\
\
\---\
\
\### 1) Authentication fails\
\
Both authentication flows fail:\
\
\- \\Sign in with ChatGPT\\\
\- \\Sign in with Device Code\\\
\
The failure manifests as:\
\
\Stream disconnected before completion: error sending request for url (https\://chatgpt.com/backend-api/codex/responses)\\
\
\strace\ indicates resolver-related activity and DNS traffic toward \127.0.0.1:53\. This environment does not provide a traditional \/etc/resolv.conf\, which is typical for Android.\
\
Because authentication fails, Codex cannot complete the initial login flow on Termux.\
\
\#### Workaround\
\
If \\~/.codex/auth.json\ is generated on another system and copied into Termux, authentication succeeds. \
Similarly, if \auth.json\ was created previously, Codex can start.\
\
However:\
\
Once a valid \auth.json\ is present, the same request failure appears during interactive use (e.g. \codex exec "hello"\ or starting a session).\
\
So the resolver issue affects both:\
\- authentication\
\- normal request execution\
\
\---\
\
\### 2) Startup lock errors (non-fatal)\
\
On startup, Codex emits lock-related errors consistent with file-lock operations not being supported in this environment. The errors are of the form:\
\
\std::fs::TryLockError::Error(err)\ where \err.kind() == std::io::ErrorKind::Unsupported\\
\
Importantly:\
\
\- These errors do \\not\\ crash the application.\
\- Codex continues running.\
\- No obvious functionality appears broken solely due to these startup lock errors.\
\
\---\
\
\### 3) Session preference does not persist when pressing \p\\
\
When Codex prompts for permission to perform an action, it offers an option to press \p\ to auto-accept for the rest of the session.\
\
On Termux:\
\
\- Pressing \p\ triggers the same lock-related failure.\
\- The preference does not persist.\
\- Codex continues prompting instead of remembering the choice.\
\
This appears related to the unsupported lock behavior described above.\

What steps can reproduce the bug?

Authentication failure path

  1. Use Android + Termux (native Termux; no proot/chroot).
  2. Install and run Codex CLI.
  3. Attempt either:
  • "Sign in with ChatGPT"
  • "Sign in with Device Code"
  1. Observe request failure:

Stream disconnected before completion: error sending request for url (...)

Optional:

  • Run strace and observe resolver-related calls / DNS attempts toward 127.0.0.1:53.

---

Interactive failure path (after auth workaround)

  1. Copy a valid ~/.codex/auth.json from another system into Termux.
  2. Run codex exec "hello" or start an interactive session.
  3. Observe the same request failure described above.

---

Lock persistence failure path

If you manage to work around the DNS issues - i.e. have root access and are able to make a /etc/resolv.conf:

  1. Use Android + Termux.
  2. Run Codex CLI until a permission prompt appears.
  3. Press p to auto-accept for the rest of the session.
  4. Observe lock-related error(s) and that the preference does not persist.

What is the expected behavior?

Codex CLI should function on native Termux/Android, including:

  • Successful authentication.
  • Successful request execution.
  • No lock-related errors on startup.
  • Session-level preference toggles (like “auto-accept for rest of session”) should work or degrade gracefully.

Additional information

  • I have successfully implemented changes locally that allow Codex CLI to run correctly on Termux. There were a few additional Android-specific adjustments required beyond the issues described above.
  • Since docs/contributing.md indicates external PRs are invitation-only, I’m reporting this first. I’m happy to open a PR if invited, as I've already got one drafted against my fork here https://github.com/wallentx/codex/pull/5
  • A working Termux build is available here https://github.com/wallentx/codex/actions/runs/22006539253

View original on GitHub ↗

10 Comments

wallentx · 5 months ago

@etraut-openai it doesn't seem like the issue I'm reporting is the same as https://github.com/openai/codex/issues/6757. I'm not running in proot, and I never witnessed that same error. The DNS issue I'm describing is resolved by building with a aarch64-linux-android target, and a small code change to address the locking issue

etraut-openai contributor · 5 months ago

OK, reopening.

wiilwaalka · 4 months ago

I tried the API key flow by generating an API key, then using that directly instead of the OAuth flow, which is failing. Is there any difference? Both paths provide the Codex CLI with a valid access token to communicate with the models, right?

!Image

wallentx · 4 months ago

The API key flow seemed to work, but the thing that brought this to my attention was that codex 5.3 wasn't available via API key when it first released. I'm not sure if that's still true or not.

wallentx · 2 months ago

If anyone stumbles upon this, I'm now mirroring codex releases with termux fixes applied on my fork https://github.com/wallentx/codex-termux/releases

friuns2 · 2 months ago

This does not solve native Termux compatibility by itself, but it may be useful for people who mainly want a mobile/browser UI around Codex.

codexUI supports Termux and remote/browser workflows, so it is worth comparing alongside native Termux forks and patches.

GitHub:
https://github.com/friuns2/codexui

escape0707 · 1 month ago

I tried to use PC Codex + SSH to troubleshoot this and reached a native Termux setup that works for me. Below is summarized by Codex and edited by me.

---

Native Termux setup:

pnpm global workspace config:

supportedArchitectures:
  os:
    - current
    - linux

On my Termux setup this file is:

~/.local/share/pnpm/global/v11/pnpm-workspace.yaml

Export PNPM_HOME from fish:

set --universal --export PNPM_HOME $HOME/.local/share/pnpm

Install/update function:

function update-codex --description 'Install/update Codex for native Termux'
    set -l v $argv[1]
    test -n "$v"; or set v (pnpm view @openai/codex version)

    command -q tinyproxy; or pkg install -y tinyproxy; or return

    pnpm add -g @openai/codex@$v; or return

    mkdir -p ~/.local/bin
    printf '%s\n' \
        '#!/data/data/com.termux/files/usr/bin/sh' \
        'set -eu' \
        'export HTTPS_PROXY=http://127.0.0.1:8888' \
        'export SSL_CERT_FILE=/data/data/com.termux/files/usr/etc/tls/cert.pem' \
        'tinyproxy' \
        'exec "$PNPM_HOME/bin/codex" "$@"' \
        > ~/.local/bin/codex
    chmod 700 ~/.local/bin/codex
    fish_add_path -m ~/.local/bin

    mkdir -p ~/.codex
    touch ~/.codex/config.toml
    grep -q '^sandbox_mode[[:space:]]*=' ~/.codex/config.toml
    and sed -i 's/^sandbox_mode[[:space:]]*=.*/sandbox_mode = "danger-full-access"/' ~/.codex/config.toml
    or echo 'sandbox_mode = "danger-full-access"' >> ~/.codex/config.toml

    codex --version
end

Generated wrapper:

#!/data/data/com.termux/files/usr/bin/sh
set -eu
export HTTPS_PROXY=http://127.0.0.1:8888
export SSL_CERT_FILE=/data/data/com.termux/files/usr/etc/tls/cert.pem
tinyproxy
exec "$PNPM_HOME/bin/codex" "$@"

Run:

update-codex
codex

Why these pieces are needed:

  • @openai/codex is the direct global package, so pnpm update -Lg works.
  • supportedArchitectures.os = [current, linux] makes pnpm install Codex's Linux optional dependency on native Termux.
  • The wrapper executes pnpm's Codex shim through PNPM_HOME, which avoids recursion through ~/.local/bin/codex.
  • tinyproxy makes HTTPS traffic resolve through Termux's networking path.
  • SSL_CERT_FILE=$PREFIX/etc/tls/cert.pem gives the Linux Codex binary the Termux CA bundle.
  • sandbox_mode = "danger-full-access" avoids the Linux sandbox path, which does not work in native Termux.

What does not work:

  • Installing @openai/codex-linux-arm64@npm:@openai/codex... as the direct global package breaks pnpm update -Lg; pnpm later resolves the alias name as a registry package and gets a 404.
  • Hard-coding or searching for the vendored Codex binary path ties the wrapper to pnpm's internal global layout.
  • exec codex "$@" inside ~/.local/bin/codex recurses when ~/.local/bin appears before pnpm's bin directory on PATH.
  • proot bind-mounting $PREFIX/etc/resolv.conf into /etc/resolv.conf fixes DNS, but it made live tool-call reaction latency much worse in my Termux session.
  • In a six-consecutive-date tool-call test, I saw roughly:
  • proot -> native codex: about 39s average gap;
  • tinyproxy + direct native codex: about 10s average gap;
  • a Linux reference machine: about 3s average gap.
  • libresolv-wrapper did not fix the request failure in my test.
  • proxychains-ng relies on LD_PRELOAD, which does not fit the shipped Linux/musl Codex binary running under native Termux.

Verified on my current Termux global packages:

@openai/codex 0.141.0
ctx7 0.5.3
pnpm 11.8.0

codex --version reports:

codex-cli 0.141.0
onlyoneuche · 14 days ago

wish i'd seen this sooner and not spend tokens, had the same issue and used codex cli macOS + adb to troubleshoot and fix.
workaround was to run codex through proot with a bound /etc/resolv.conf, plus CODEX_CA_CERTIFICATE=$PREFIX/etc/tls/cert.pem

escape0707 · 14 days ago

@onlyoneuche

Have you checked Codex’s response speed when calling tools while using Proot? I tried the proot workaround, but it seems to affect Codex’s receipt of notifications that external tool execution has finished. As a result, every tool call, regardless of how long it actually takes, makes Codex wait for around 40 seconds until Codex actively checks whether the tool is still running before continuing. This is very undesirable, so I used the tinyproxy method to solve the DNS resolution issue. You can see my reply above.

wallentx · 13 days ago

just to clarify, I'm automatically mirroring every codex release here with termux fixes applied. I'm doing the same with antigravity-cli, opencode, and claude-code. so if you are running termux and want these working, you can use the artifact from any of my releases, and auto update pulls from my fork.