Run the upstream opencode CLI on Termux / Android (aarch64) by reusing its official musl-linked ARM64 binary.
This is an alternative to guysoft/opencode-termux, which cross-compiles Bun from source for Android and is pinned to opencode 1.17.9. This project avoids that build entirely.
- Why
- Install
- How it works
- Why no
libtagfix.soshim - Using with local models (Ollama)
- What's not working
- OpenCode v2 (beta)
- Requirements
- Tested on
- AMOLED themes
opencode is a Bun standalone binary. The Bun team has closed Android support as "not planned", so running opencode on Termux normally requires:
- Cross-compiling Bun v1.2.13 for Android/aarch64 (~30 min CMake build)
- Cross-compiling WebKit/JavaScriptCore (~90 min)
- Cross-compiling ICU, TinyCC, OpenTUI
- Splicing the host-built opencode module graph onto the Android Bun binary
- Patching the bionic heap-tagging ABI for JSC
That's a 6-stage CI pipeline. It works, but it's a maintenance burden and the maintainer of guysoft/opencode-termux has not published a release since opencode 1.17.9 (June 2026), even though upstream has shipped 11+ versions since then.
The much simpler approach: take upstream's opencode-linux-arm64-musl.tar.gz, supply a musl dynamic linker + musl-compiled libstdc++/libgcc_s from Alpine, patch the interpreter, done.
On Termux:
curl -fsSL https://raw.githubusercontent.com/DEAD1nsane/opencode-termux-musl/master/install.sh | shAfter it finishes, the wrapper prints the installed opencode version (whatever upstream's current release is).
Then run:
opencode --version opencode
Full guide: docs/INSTALL.md — download sizes, what the script does, manual download / offline install, verify, troubleshooting.
The upstream binary is dynamically linked. Its ELF interpreter points at /lib/ld-musl-aarch64.so.1, which Termux doesn't ship. The installer:
- Downloads the latest upstream
opencode-linux-arm64-musl.tar.gz. - Downloads Alpine's musl package (provides
ld-musl-aarch64.so.1) and musl-compiledlibstdc++/libgcc_s. - Installs them to
$PREFIX/lib. - Uses
patchelfto retarget the binary's interpreter to the installed musl loader. - Builds and installs
libresolvefix.so— an LD_PRELOAD shim that:- Redirects musl's
/etc/resolv.confreads to Termux's copy at$PREFIX/etc/resolv.conf - Forwards
getaddrinfo()to bionic's resolver (viadlopen) so DNS works through Android'snetddaemon
- Redirects musl's
- Installs a local HTTP proxy (
proxy.py) — Bun's io_uring-based networking doesn't work on Android, so all outbound traffic (API requests, webfetch, websearch, model registry, plugin installs, etc.) is routed through a Python proxy on127.0.0.1:8080 - Installs a wrapper that:
- Clears any stale
LD_PRELOADfrom the previous (guysoft) wrapper — that shim references glibc-only symbols (__register_atfork,__errno,__strlen_chk, etc.) that don't exist in musl - Loads
libresolvefix.sofor DNS resolution - Auto-starts the HTTP proxy if not running
- Sets the env vars opencode needs on Android:
TERMfor the TUI,OPENCODE_DISABLE_TUI_AUDIO=1,OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER=true, TLS cert paths - Sets
HTTP_PROXY/HTTPS_PROXYso Bun routes all connections through the proxy - Runs the binary against the musl loader in
$PREFIX/lib
- Clears any stale
Bun uses io_uring for async networking (DNS, TCP, TLS) on Linux. On Android, io_uring is either unavailable or broken — all outbound connections fail with "Unable to connect". The Python proxy works because it uses standard libc sockets (bionic's connect()/sendto()) which go through Android's normal networking stack. The proxy supports three modes:
- Fixed-target reverse proxy (for the opencode.ai API): requests to
127.0.0.1:8080are forwarded tohttps://opencode.ai<path> - Absolute-URL forward proxy: when Bun sends
GET http://...requests (becauseHTTP_PROXYis set), the proxy extracts the target URL and forwards - HTTP CONNECT tunnel: for HTTPS targets, the proxy establishes a TCP tunnel to the remote host and pipes bytes both ways
Musl's resolver reads /etc/resolv.conf then sends raw UDP DNS queries to the nameserver. On Android, /etc is read-only and raw UDP to port 53 is blocked by the firewall. The shim:
- Intercepts
open()/fopen()for/etc/resolv.confand redirects to Termux's copy - Intercepts
getaddrinfo()and forwards to bionic's implementation (loaded viadlopen("libc.so")) which uses Android'snetddaemon for proper DNS resolution
The other Termux build (guysoft/opencode-termux) ships an LD_PRELOAD shim that calls mallopt() to disable Android's bionic heap-pointer tagging. That build is Bionic-linked, so its allocator is bionic's — and bionic's allocator tags heap pointers with the top byte, which JSC's NaN-boxing clobbers, causing a Pointer tag ... was truncated abort on free().
This build is musl-linked. opencode's allocations go through musl's allocator, which does not tag pointers. The shim is therefore unnecessary here, and shipping a Bionic-targeted .so under a musl process would either fail to load (different libc resolution) or cause a libc-mismatch corruption. If you do hit a "Pointer tag" crash, the cause is different (e.g. kernel-level tagged-address enforcement on ioctl/prctl from a JSC path) and would need to be fixed in JSC's syscall wrappers upstream, not in userspace.
The stable version (v1) can work with local models from Ollama. The wrapper now sets NO_PROXY=localhost,127.0.0.1 to bypass the proxy for local connections.
-
Install and start Ollama in Termux:
pkg install ollama ollama serve & ollama pull llama3 -
Configure opencode to use Ollama (in
~/.config/opencode/config.json):{ "provider": { "ollama": { "endpoint": "http://localhost:11434", "model": "llama3" } } } -
Run opencode:
opencode
Note: v2 (beta) doesn't need the proxy and works with Ollama out of the box.
Known limitations:
- File watcher:
@parcel/watcher's native binding is x86_64-only; this build has the same issue. Disabled in the wrapper viaOPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER=true. - TUI audio: explicitly disabled in the wrapper (
OPENCODE_DISABLE_TUI_AUDIO=1) since OpenTUI's audio backend isn't useful on Android. - PTY support: depends on
librust_pty_arm64.so. The guysoft build ships this; we don't yet. PRs welcome. - Startup latency: the Python HTTP proxy adds ~100-200ms per request. Acceptable for interactive use.
OpenCode v2 is a major rewrite that replaces Bun with Node.js as the JavaScript runtime.
libresolvefix.so — it does raw UDP DNS that Android blocks. Sending messages fails with getaddrinfo ETIMEOUT. The background server also freezes without --standalone.
Solution: Run v2 in proot Ubuntu where DNS works natively.
# Install in proot Ubuntu (requires --ignore-scripts since npm doesn't support Android) proot-distro login ubuntu -- bash -c \ "npm install -g --force --ignore-scripts @opencode-ai/cli@beta && \ npm install -g --force --ignore-scripts @opencode-ai/cli-linux-arm64@beta && \ cp /usr/local/lib/node_modules/@opencode-ai/cli-linux-arm64/bin/opencode2 \ /usr/local/lib/node_modules/@opencode-ai/cli/bin/opencode2.exe && \ chmod +x /usr/local/lib/node_modules/@opencode-ai/cli/bin/opencode2.exe"
oc2-ubuntu # Launch TUI (adds --standalone automatically) oc2-ubuntu --version oc2-ubuntu update --method npm # Update inside proot
The wrapper:
- Syncs your Termux config (themes, service.json, etc.) into proot Ubuntu
- Copies the real binary from
~/.opencode/bin/opencodeto the npm symlink target (fixes the postinstall placeholder) - Runs
opencode2 --standaloneinside proot Ubuntu
After oc2-ubuntu update, the wrapper automatically copies the real binary back so you can launch immediately.
oc2-ubuntu update --method npm
This runs opencode2 update inside proot Ubuntu. After it completes, the wrapper copies the real binary back. Then run oc2-ubuntu to launch.
Note: The opencode2 update command uses npm internally and may install to @opencode/cli (without -ai). The wrapper handles this by copying the binary to both possible locations.
| v1 (stable) | v2 (beta via proot) | |
|---|---|---|
| Runtime | Bun | Node.js |
| Works on Termux | Yes (native) | No (needs proot Ubuntu) |
| Install method | install.sh |
npm install in proot |
| Run command | opencode |
oc2-ubuntu |
| Update | install.sh (re-run) |
oc2-ubuntu update --method npm |
| Proxy needed | Yes (io_uring broken on Android) | No |
Status: v1 is stable and production-ready. v2 works via proot Ubuntu. This project remains the stable solution for v1.
scripts/check-update.sh compares your installed version against the latest upstream release. By default it only checks and sends a Termux notification — it never downloads anything. Pass --yes to apply the update via install.sh:
./scripts/check-update.sh # check only ./scripts/check-update.sh --yes # update now if behind
Daily unattended check (needs the Termux:API app — Wi-Fi only, survives reboot):
termux-job-scheduler --job-id 7801 --period-ms 86400000 \
--network unmetered --persisted true \
-s /path/to/opencode-termux-musl/scripts/check-update.shFor unattended updates, schedule scripts/auto-update.sh instead. It runs the check with --yes and invokes install.sh only when a newer upstream release is available:
termux-job-scheduler --job-id 7801 --period-ms 86400000 \
--network unmetered --persisted true \
-s /path/to/opencode-termux-musl/scripts/auto-update.shProof it works — real auto-update notifications on Android:
![]()
- Termux (Android 7.0+ / API 24+, aarch64)
curl,tar,patchelf,clang(installer will installpatchelfandclangautomatically if missing)python3(for the HTTP proxy — v1 only)- Internet access to
github.com,dl-cdn.alpinelinux.org, andopencode.ai
- Pixel 10 (Android 17, Termux 0.119, aarch64) — installer completes, wrapper prints upstream's version string, TUI launches and connects to API through the proxy.
- v2 (
opencode2 v0.0.0-beta-19425) runs in proot Ubuntu usingoc2-ubuntu.
Screenshots (click to expand)
| Step | Screenshot |
|---|---|
| Clean terminal | ![]() |
| Install opencode | ![]() |
| Version check | ![]() |
| Installed files | ![]() |
| ELF interpreter | ![]() |
| opencode TUI | ![]() |
Eight true-black (#000000) themes in themes/ — copy any *.json to ~/.config/opencode/themes/ and select it with /theme or tui.json. Previews rendered from theme-showcase.md:
Side note: the seven accent themes are deliberately restrained next to the stock built-in themes — each one leans on a single accent color, especially for syntax highlighting, trading rainbow code for contrast on pure black.
8-rainbowis the exception: white chrome, red links, full neon syntax.
Theme previews (click to expand)
![]() 1-rbw-amoled |
![]() 2-obw-amoled |
![]() 3-ybw-amoled |
![]() 4-gbw-amoled |
![]() 5-bbw-amoled |
![]() 6-vbw-amoled |
![]() 7-pbw-amoled |
![]() 8-rainbow-amoled |
- opencode by Anomaly — the AI coding CLI this project wraps
- guysoft/opencode-termux — the original Android port and Bionic compatibility shims that informed this work
- Alpine Linux — musl libc + libstdc++/libgcc_s packages
MIT














