Goal: run an OpenCode server through Termux, then chat with it in OpenCode Mobile—no PC and no root.
The app is a client, not the server. Installing the APK alone does not start an OpenCode server or create a server password. Your AI provider login/API key is also different from the server password.
Same Android phone
OpenCode Mobile → http://127.0.0.1:4096
↓
OpenCode server in Ubuntu/proot
↓
Termux
127.0.0.1 means this phone, not a laptop. This guide is specifically for a server on the same phone.
- Install Termux and
proot-distro(2.1). - Install OpenCode 2.0.27 inside Ubuntu (2.2).
- Create a private server password (2.3) and the launcher (2.4).
- Start it and verify
/api/inforeturns2.0.27(2.5). - Add the server in the app and test a real chat (section 3).
- Install the
oc-ctlhelper for background start, status and auto-start (section 4).
- Want to manage the phone from a laptop? See section 8.
- Already have a server, but cannot connect? Start with diagnosis.
- Starting from scratch, or confirmed an incompatible native server? Follow setup.
- Previously connected, now stuck reconnecting? Follow recovery.
- Want old sessions too? Read migration precautions only after the new connection works.
| OpenCode Mobile | OpenCode Server | Environment | Status | Tested |
|---|---|---|---|---|
v0.20.0 (latest) |
2.0.27 (Ubuntu/proot) |
Android 14 (ARM64) | Working | 2026-12 |
v0.17.0 |
2.0.27 (Ubuntu/proot) |
Android 14 (ARM64) | Working | 2026-11 |
v0.17.0 |
2.0.0-android-termux.2 (native) |
Android 14 (ARM64) | Incompatible (/api/info 404) |
2026-11 |
The original phone setup used Android 14, OpenCode Mobile v0.17.0 (also verified working after updating to v0.20.0), and OpenCode server 2.0.27 in Ubuntu/proot. The native build that failed was 2.0.0-android-termux.2 from guysoft/opencode-termux.
This is a known-working version pair, not a claim that all other versions fail or that the native build will never be updated. See the latest tested app release and, for example, the pinned schema version of v0.17.0. Releases newer than the tested ones may change server requirements; check the table above first. Matching endpoint counts alone does not prove compatibility: response schemas, HTTP methods, and streaming events matter too.
The revised commands below make setup explicit and keep data outside Ubuntu. They have not yet been independently retested from a clean phone install; do the checkpoints rather than assuming success. They target proot-distro versions supporting login --bind and Ubuntu on ARM64.
Run these commands in Termux, not in an Ubuntu shell. If your prompt is an Ubuntu shell, run exit first. Do not reinstall Ubuntu or delete databases while diagnosing.
If you already use native OpenCode, check:
opencode --version
opencode service statusUse the URL actually printed by your service, or the URL of your manually started server. 4096 is this guide's port; 28570 was one device's old service port, not a universal default. Native service commands do not manage the separate Ubuntu serve process created below.
Test your actual server URL:
SERVER_URL='http://127.0.0.1:4096' # change if your server uses another port
curl -sS --connect-timeout 3 --max-time 10 \
-o /dev/null -w 'HTTP %{http_code}\n' "$SERVER_URL/api/info"| Result | Meaning | Next action |
|---|---|---|
000 plus a curl error |
No HTTP response; not an HTTP status code | Check URL, port, server process, and log. Do not assume a password problem. |
401 without credentials |
A server is responding and requests authentication | Retry with your server password below. This alone does not identify its version. |
200 |
Something responded successfully | Inspect the response and confirm it is OpenCode and the expected version. |
404 |
This URL/endpoint is not available | Confirm the server, base URL, and API version, with authentication if required. |
Authenticated check (curl prompts for the password; do not paste it into an issue):
curl -sS --connect-timeout 3 --max-time 10 \
--user opencode "$SERVER_URL/api/info"- 401 with the correct username: verify the server password; it may have changed after a restart.
- 200 with version information: do not reinstall. Recheck the app's saved URL/password and test a chat.
- 404 on the intended OpenCode server: check compatibility. In our case, native
2.0.0-android-termux.2provided/api/serverbut not/api/info, which app v0.17.0 probes. This produced “Not found on the server.” An authenticated request to/api/serverhelped identify that older API.
A 404 elsewhere does not necessarily mean this exact version mismatch. A reachable /api/info does not prove that every app feature works.
Use this route if you need a new server or have confirmed the native API is incompatible. No pre-existing native OpenCode installation or AI agent is required. Proot lets the Linux server run inside Ubuntu through Termux; it does not replace Android or require root.
Already followed an earlier edition of this guide? Do not paste over an existing ~/bin/oc-app-server or boot hook. Back up those files and your existing server data first, and plan a deliberate switch with the old server stopped. This edition uses a different data directory and password file; your old sessions/password do not automatically appear there.
Install Termux from F-Droid or Termux GitHub releases. Add-ons must have a compatible signature; using the same distribution source avoids signature conflicts. Allow several GB of free space. The original installed environment occupied about 1.7 GB; download size is not the same as installed size.
In Termux:
pkg update
pkg install -y proot-distro curl procps
mkdir -p "$HOME/bin" "$HOME/.local/share/opencode-mobile"
proot-distro install ubuntuIf Ubuntu is already installed, do not remove it. Continue with the existing container after checking its contents, or use a separate container with instructions appropriate to your proot-distro version.
Enter Ubuntu from Termux:
proot-distro login ubuntuNow inside Ubuntu:
apt-get update
apt-get install -y curl ca-certificates unzip git ripgrep
set -o pipefail
curl -fsSL https://opencode.ai/v2/install | bash -s -- \
--version 2.0.27 --no-modify-path
/root/.opencode/bin/opencode --version
exitCheckpoint: the absolute binary path must report 2.0.27. If installation fails, stop here and read its error. Use the /v2/install installer for this V2 setup, not the V1 installer. Explicit paths prevent accidentally running Termux's older binary through an inherited PATH.
Back in Termux:
umask 077
PASSWORD_FILE="$HOME/.local/share/opencode-mobile/server-password"
if [ ! -s "$PASSWORD_FILE" ]; then
head -c 24 /dev/urandom | od -An -tx1 | tr -d ' \n' > "$PASSWORD_FILE"
fi
chmod 600 "$PASSWORD_FILE"This does not regenerate an existing password. Keep it private. Username for this tested server is opencode.
Paste the entire block into Termux. It creates the file; you do not need a text editor.
cat > "$HOME/bin/oc-app-server" <<'SCRIPT'
#!/data/data/com.termux/files/usr/bin/bash
set -eu
BASE="$HOME/.local/share/opencode-mobile"
mkdir -p "$BASE/data" "$BASE/config" "$BASE/state"
if [ ! -s "$BASE/server-password" ]; then
echo 'Missing server-password. Complete setup step 2.3 first.' >&2
exit 1
fi
exec proot-distro login --bind "$BASE:/oc-mobile" \
--bind "$HOME:/termux-home" ubuntu -- env -i \
HOME=/root TERM=xterm-256color \
PATH=/root/.opencode/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
XDG_DATA_HOME=/oc-mobile/data \
XDG_CONFIG_HOME=/oc-mobile/config \
XDG_STATE_HOME=/oc-mobile/state \
OPENCODE_SERVER_PASSWORD="$(cat "$BASE/server-password")" \
bash -lc 'cd /termux-home && exec /root/.opencode/bin/opencode serve --hostname 127.0.0.1 --port 4096'
SCRIPT
chmod 700 "$HOME/bin/oc-app-server"This setup deliberately uses new, separate data. It does not touch the old native database or an existing Ubuntu OpenCode database. Data/config/state live under Termux's ~/.local/share/opencode-mobile/, explicitly bound into Ubuntu as /oc-mobile. Projects in Termux home are available as /termux-home. Tools run in Linux/proot, not a native Termux shell.
In Termux:
"$HOME/bin/oc-app-server"Leave this terminal running. Expect a listening message for http://127.0.0.1:4096. If the port is occupied, inspect the existing server instead of launching another one. If --bind is rejected, check proot-distro login --help; do not bypass persistent storage silently.
Open another Termux session and verify:
curl -sS --connect-timeout 3 --max-time 10 \
--user "opencode:$(cat "$HOME/.local/share/opencode-mobile/server-password")" \
http://127.0.0.1:4096/api/infoCheckpoint: JSON containing "version":"2.0.27". If not, inspect the first terminal's output. Do not proceed until it succeeds.
If not installed yet, download the APK from the latest tested v0.20.0 release (v0.17.0 was also verified) and install it on this phone. Android may ask you to allow APK installation from your browser/file manager. Releases newer than the tested ones may have different server requirements.
Display the password privately in Termux:
cat "$HOME/.local/share/opencode-mobile/server-password"
echoIn OpenCode Mobile → add server manually, enter:
| Field | Value |
|---|---|
| Server URL | http://127.0.0.1:4096 |
| Username, if shown | opencode |
| Password | The value displayed above—not your GitHub or AI provider password |
Do not append /api/info or /api to the app URL. Use the password/manual option rather than a single-use pairing-code option. QR pairing is unnecessary for this same-phone flow.
- Save and wait for the session list. An empty list is normal for this new data directory.
- Create a session; select an available model. If authentication/billing is required, configure that provider separately. Free-model availability can change.
- Send a harmless prompt such as “Reply with OK; do not run tools.”
- Confirm that a response arrives and live updates work.
Success means a working chat, not just a Connected label. A model quota, provider login, or billing error is not automatically a server connection problem.
scripts/oc-ctl.sh manages the server with start, stop, restart, status, logs [N] and doctor. In Termux:
curl -fsSL https://raw.githubusercontent.com/baliboyish/opencode-mobile-termux-tutorial/main/scripts/oc-ctl.sh \
-o "$HOME/bin/oc-ctl"
chmod 700 "$HOME/bin/oc-ctl"
"$HOME/bin/oc-ctl" doctostopwaits until the server has really exited and releases the wake lock;restartfails loudly if the old process will not exit.server.logis rotated above about 5 MB. The password is handed to curl on stdin, so it does not show up inps.- Optional overrides (
PORT,PASSWORD_FILE,LOG_FILE,LAUNCHER) go in~/.config/oc-ctl.conf(shell syntax). Useful if your older setup uses different paths.
After the foreground test, press Ctrl+C in that server terminal to stop that foreground server. Then, in Termux:
termux-wake-lock
nohup "$HOME/bin/oc-app-server" \
>> "$HOME/.local/share/opencode-mobile/server.log" 2>&1 &Run this once, not repeatedly while waiting for startup. Verify with the authenticated curl from step 2.5; retry after a few seconds if still starting. Check the log on failure:
tail -n 40 "$HOME/.local/share/opencode-mobile/server.log"To stop only the manual server command used in this guide:
if pkill -f '[o]pencode serve --hostname 127[.]0[.]0[.]1 --port 4096'; then
echo 'Stop signal sent; check that the server is no longer reachable.'
else
echo 'No matching process found; nothing stopped.'
fiThis pattern depends on the launcher command remaining unchanged. It is not a general command to stop every OpenCode installation. Verify afterward; do not run it to troubleshoot an otherwise healthy server.
You can leave the app or Termux screen: the background server, not an open TUI, is what matters. Force-stopping Termux kills its processes. Swiping it from recents may kill them depending on the ROM. Closing an unrelated TUI is different from pressing Ctrl+C on a foreground serve process.
If you prefer not to install Termux:Boot, you can auto-start the server whenever you open Termux by appending this block to ~/.bashrc. It uses oc-ctl start, which checks whether the server is already running, so opening extra Termux tabs will not spawn duplicates.
In Termux (requires the helper installed above):
cat >> "$HOME/.bashrc" <<'EOF'
# Auto-start OpenCode Mobile server when opening Termux (if not already running)
if [[ $- == *i* ]] && [ -x "$HOME/bin/oc-ctl" ]; then
# pgrep -x sshd >/dev/null 2>&1 || sshd # uncomment if you use section 8
"$HOME/bin/oc-ctl" start >/dev/null 2>&1 || echo "[oc-ctl] auto-start failed; run: ~/bin/oc-ctl logs"
fi
EOFAfter a phone reboot, simply open Termux once and the server will start automatically.
- Set Settings → Apps → Termux → Battery → Unrestricted / allow background activity (names vary by manufacturer).
- A wake lock helps prevent sleep-related interruption; it does not guarantee Android will never kill the process and may increase battery use.
- For boot startup, install Termux:Boot from a compatible source and open it once.
In Termux:
mkdir -p "$HOME/.termux/boot"
cat > "$HOME/.termux/boot/oc-app-server" <<'SCRIPT'
#!/data/data/com.termux/files/usr/bin/sh
# pgrep -x sshd >/dev/null 2>&1 || sshd # uncomment if you use section 8
"$HOME/bin/oc-ctl" start
SCRIPT
chmod 700 "$HOME/.termux/boot/oc-app-server"Reboot, unlock the phone, wait, and check the API and a chat. Some ROMs need additional auto-launch permission or opening Termux once. Opening Termux alone is not a universal guarantee that the hook ran. If startup fails, inspect the log and use the manual background command after confirming no server is running.
| Symptom | What to check | Next step |
|---|---|---|
| “Not found on the server” | Authenticated /api/info, actual server version/base URL |
Use the intended server; use the tested version pair if the native API is incompatible. |
Timeout, refused, or curl 000 |
Actual URL/port, foreground output or server.log |
Fix the reported startup error; start once if stopped. |
401 with credentials |
Password file versus saved app password | Correct the app credentials. A 401 without credentials is expected. |
| Reconnecting; authenticated API also fails | Process, log, battery settings | Resolve server/startup failure first. |
Reconnecting; authenticated /api/info works |
Saved app credentials/version, live event connection, VPN/proxy changes | Reopen the app and retry; collect app error and server log if persistent. API reachability alone does not test SSE/WebSocket. |
container 'ubuntu' is not installed |
proot-distro list; check the container name and storage |
Container is missing/unrecognized. Investigate before reinstalling. Normal reboot should not delete it. |
| Chat fails but app stays connected | Provider/model error text | Address provider auth, availability, quota or billing—not Ubuntu reinstall. |
| No old sessions | Separate data directory or wrong server | New data is intentional. Do not overwrite its DB; see section 6. |
| Port already in use | Existing foreground/background server | Verify the existing one. Do not repeatedly start another. |
If Ubuntu really must be recreated, first back up the external data, reinstall Ubuntu/OpenCode, then reuse the launcher and password. Do not delete ~/.local/share/opencode-mobile. This storage survives container removal, but not Termux app-data clearing/uninstallation or loss of the phone; keep a separate backup too. Do not downgrade a server against a database already migrated by a newer version.
For an issue, include: app version, server version, phone/Android version, exact error, URL without secrets, authenticated HTTP status, and relevant redacted log lines. Never post password files, authorization headers, tokens, or full databases.
Get a new chat working first. Migration is not required to connect.
The old native build in our case used opencode-android-termux.db, not opencode.db. Database names/paths vary by build and channel. Confirm the actual source; never choose the first *.db automatically. Newer CLIs may support opencode debug paths db; check your installed version's help.
Before any migration:
- Identify source and destination versions and DB paths.
- Back up the source with SQLite's
.backup(online-safe) or a supported export. Do not copy only a live.dband ignore its WAL. - Check that the source exists before opening it with sqlite3: sqlite3 otherwise creates an empty file.
- Stop the destination server; back up its existing data, config, and state. Do not erase its DB/WAL files or overwrite new sessions.
- Check version-specific migration support, preferably on a disposable copy. Confirm session counts and usable chats afterward. Never assume newer DBs can be read by older binaries.
Illustrative source backup, only after verifying the path, in Termux (pkg install sqlite if needed):
SRC="$HOME/.local/share/opencode/opencode-android-termux.db"
if [ -f "$SRC" ]; then
BACKUP="$HOME/native-opencode-$(date +%Y%m%d-%H%M%S).db"
sqlite3 "$SRC" ".backup '$BACKUP'"
sqlite3 -readonly "$BACKUP" 'PRAGMA integrity_check;'
else
echo 'Source DB not found. Stop and locate the real database.'
fiThis is a backup example, not an automatic import or compatibility guarantee. A valid empty DB can pass integrity checks; also verify expected sessions using the source version's schema/export.
- Bind the phone server to 127.0.0.1, not
0.0.0.0; do not forward its port to the internet. - Loopback is not app isolation: other local apps may reach the listener. Keep authentication enabled.
- Keep the password file private. To rotate it, stop the server, deliberately replace the file with a new random secret, restart, and update the app.
- Proot is a compatibility layer, not a security sandbox. The agent can access files exposed through the binds; review tool permissions.
- AI assistance is optional. Ask it to diagnose first, explain commands, and request approval before migrating data or replacing a container. An agent prompt is not a guaranteed installer.
- If you enable SSH (section 8), use key-only authentication and keep it reachable only over Tailscale.
- PC/Windows/Tailscale setup of the OpenCode server is outside this same-phone guide. See the upstream app connection guide for remote-server workflows.
This lets you (or a tool running on your laptop) run commands in Termux remotely, for example oc-ctl status. Tailscale's built-in SSH server is not available on Android, so use Termux's OpenSSH on port 8022. Both devices must be signed in to the same tailnet.
On the phone (Termux):
pkg install -y openssh
passwd # temporary password, only needed to copy your key once
sshd # listens on port 8022On the laptop: create a key and an SSH config entry. Use the phone's Tailscale IP (tailscale status) or its MagicDNS name. Termux ignores the SSH username.
ssh-keygen -t ed25519 -f ~/.ssh/termux_ed25519# ~/.ssh/config
Host termux
HostName <phone-tailscale-ip-or-name>
Port 8022
User termux
IdentityFile ~/.ssh/termux_ed25519
ServerAliveInterval 30
Copy the public key (asks for the temporary password once):
# Windows PowerShell
type $env:USERPROFILE\.ssh\termux_ed25519.pub | ssh termux "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys"# Linux/macOS
ssh-copy-id -i ~/.ssh/termux_ed25519.pub -p 8022 termux@<phone-tailscale-ip-or-name>Test: ssh termux "uname -a; ~/bin/oc-ctl status".
Harden (turn off password login) once key login works. In Termux:
mkdir -p "$PREFIX/etc/ssh/sshd_config.d"
printf 'PasswordAuthentication no\nKbdInteractiveAuthentication no\nPubkeyAuthentication yes\n' \
> "$PREFIX/etc/ssh/sshd_config.d/10-key-only.conf"
sshd -t && { pkill -x sshd; sshd; }Open a new SSH session to confirm key login still works before closing your current one. To undo, delete that file and restart sshd.
Auto-start sshd: uncomment the sshd line in the ~/.bashrc and Termux:Boot snippets in section 4. The phone and Termux must stay awake (battery set to Unrestricted), or the connection drops.
Revoke access: remove the key's line from ~/.ssh/authorized_keys on the phone, or run pkill -x sshd.
References: OpenCode V2 troubleshooting, V2 CLI, OpenCode Mobile, proot-distro.
