This guide shows you how to install and run OpenAI’s Codex CLI inside Termux on Android, using the DioNanos/codex-termux fork (bionic-compatible), with full support for:
- Shell tool execution
- OpenRouter models (Grok, Claude Opus, GPT-5, Gemini, etc.)
- A dynamic fzf launcher that auto-detects all
[profiles.*]in your Codex config - Clean
.env-based secret handling - Automatic model switching
Codex official binaries are compiled for glibc, but Android uses bionic, so they fail with errors like:
exec format errorCANNOT LINK EXECUTABLE- missing libc symbols
- broken shell tool support
The Termux-specific fork below compiles Codex correctly against bionic and makes everything “just work”.
👉 Termux Codex Fork:
https://github.com/DioNanos/codex-termux
Open Termux and run:
pkg update && pkg upgrade -y
pkg install -y fzf(Installing fzf is optional but recommended.)
🛠️ 2. Install the Codex Termux Fork
See here
This places the codex binary into your Termux environment with all required patches. To test:
codex --version🔐 3. Create Your .env for API Keys Codex uses OpenRouter (recommended) or direct provider keys. Create:
mkdir -p ~/.codex
nano ~/.codex/.envInside:
export OPENROUTER_API_KEY="sk-or-your-real-key-here"Protect it:
chmod 600 ~/.codex/.env⚙️ 4. Create Your Codex Config (~/.codex/config.toml) This config enables:
- OpenRouter provider
- Responses API wire format
- Folder-level trust
- Multiple models (Grok, Claude, GPT-5, MiniMax, Gemini…)
###############################################
# GLOBAL CONFIGURATION
###############################################
model_provider = "openrouter"
profile = "grok-fast"
model = "x-ai/grok-code-fast-1"
sandbox_mode = "workspace-write"
approval_policy = "untrusted"
model_reasoning_effort = "medium"
model_verbosity = "medium"
###############################################
# CONTEXT FILE DISCOVERY
###############################################
project_doc_fallback_filenames = [
"README.md",
"CONTEXT.md",
"AGENTS.md"
]
global_context_files = [
"~/.codex/AGENTS.md"
]
###############################################
# OPENROUTER PROVIDER
###############################################
[model_providers.openrouter]
name = "OpenRouter"
base_url = "https://openrouter.ai/api/v1"
env_key = "OPENROUTER_API_KEY"
wire_api = "responses"
###############################################
# MODEL PROFILES
###############################################
[profiles.grok-fast]
model = "x-ai/grok-code-fast-1"
[profiles.claude-opus]
model = "anthropic/claude-opus-4.5"
model_reasoning_effort = "low"
[profiles.minimax-m2]
model = "minimax/minimax-m2"
[profiles.gemini-flash3]
model = "google/gemini-3-flash-preview"
model_reasoning_effort = "low"
[profiles.gpt5-standard]
model = "openai/gpt-5"
[profiles.gpt5-codex]
model = "openai/gpt-5-codex"
###############################################
# TRUST SETTINGS (Termux)
###############################################
[projects."/data/data/com.termux/files/home"]
trust_level = "untrusted"🎛️ 5. Install the Dynamic Profile Launcher
Auto-detects profiles from config.toml and provides an fzf picker. Create: ~/bin/codex-launcher
mkdir -p ~/bin
nano ~/bin/codex-launcherPaste:
#!/usr/bin/env bash
ENV_FILE="$HOME/.codex/.env"
CONFIG_FILE="$HOME/.codex/config.toml"
# Colors
BOLD="\033[1m"
RESET="\033[0m"
CYAN="\033[96m"
GREEN="\033[92m"
YELLOW="\033[93m"
# Load env
[ -f "$ENV_FILE" ] && source "$ENV_FILE"
# Extract profiles
mapfile -t PROFILES < <(grep -oP '(?<=^profiles\.).*(?=)' "$CONFIG_FILE")
PROFILE_LABELS=()
for p in "${PROFILES[@]}"; do
model=$(awk -v p="$p" '
$0 ~ "\profiles\\."p"\" {f=1;next}
f && /^model *=/ {gsub(/"/,"",$3);print $3;exit}
' "$CONFIG_FILE")
PROFILE_LABELS+=("$p ($model)")
done
# If user passed profile directly
if [[ -n "$1" && "$1" != -* ]]; then
exec codex --profile "$1" "${@:2}"
fi
choose_profile() {
echo -e "${CYAN}${BOLD}Choose Codex Profile:${RESET}"
if command -v fzf >/dev/null; then
local s
s=$(printf '%s\n' "${PROFILE_LABELS[@]}" | fzf) || exit 1
echo "${s%% *}"
else
local i
for i in "${!PROFILE_LABELS[@]}"; do
printf "%d) %s\n" "$((i+1))" "${PROFILE_LABELS[$i]}"
done
read -p "Choice: " c
echo "${PROFILES[$((c-1))]}"
fi
}
PROFILE=$(choose_profile)
echo -e "${GREEN}→ Using profile:${RESET} $PROFILE"
exec codex --profile "$PROFILE" "$@"Make it executable:
chmod +x ~/bin/codex-launcherEnsure ~/bin is in PATH:
echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc🧪 6. Test Codex + OpenRouter
codex-launcher