Freebuff — a free AI coding assistant (the free tier of Codebuff), adapted for Android Termux.
# 1. Install dependencies
apt install -y glibc-repo && apt update && apt install -y glibc openssl-glibc patchelf
pkg install proot gcc nodejs
# 2. Install freebuff (patches npm package + binary + C wrapper)
bash scripts/install.sh
# 3. Run — no shell rc configuration needed
freebuff --versionThe first run of install.sh automatically downloads about 129MB of binary from GitHub Releases. If your connection is slow, just wait.
Configure the source (one line):
curl -fsSL https://hope2333.github.io/repo/install.sh | shConfigure + install in one line:
curl -fsSL https://hope2333.github.io/repo/install.sh | sh -s -- --install freebuffUpgrade later:
pacman -Syu # pacman client
apt update && apt upgrade # apt client (mirrorlist package updates via the [hope2333-meta] source)Terminal freebuff-termux
│
├── /usr/bin/freebuff
│ └─ C wrapper (Bionic-compiled, native Termux ELF, ~5KB)
│ ├─ unsetenv(LD_LIBRARY_PATH) etc.
│ ├─ creates fake /proc/stat (bypasses Android 11+ kernel restriction)
│ └─ execvp(proot -b /tmp/fake_stat:/proc/stat, binary)
│ │
│ ├─ [proot] ptrace-level path redirection
│ │ └─ /proc/stat reads → fake_stat content
│ │
│ └─ ~/.config/manicode/freebuff
│ └─ original binary (patchelf'd interpreter)
│ └─ glibc ld.so (auto-loads libc.so.6 etc.)
│
└── fallback (when proot is unavailable)
└─ direct execve(binary)
└─ os.cpus() crashes (/proc/stat unreadable)
Key design decisions:
- C wrapper is compiled as a native Bionic ELF (no glibc dependency). It clears all
LD_*environment variables to prevent contaminating glibc ld.so. /proc/statfix: Android 11+ kernels block reading/proc/stat. The C wrapper automatically creates a fake stat file and maps it via proot bind mount, allowing libuv'suv_cpu_info()to work normally.- Binary interpreter is changed to glibc's ld.so via
patchelf. - glibc
.solinker scripts are converted to symlinks (libc.so -> libc.so.6etc.) to preventdlopen("libc.so")from loading ASCII text instead of an ELF.
| Step | Status | Notes |
|---|---|---|
| npm install (patched os field) | ✅ Pass | npm install -g freebuff succeeds |
android-arm64 platform mapping |
✅ Pass | JS wrapper downloads the correct linux-arm64 binary |
| Binary download | ✅ Pass | GitHub Releases ~124MB |
| glibc compatibility | ✅ Pass | patchelf changes interpreter, binary runs directly |
dlopen compatibility |
✅ Pass | Fixed .so linker scripts to symlinks |
| Environment variable isolation | ✅ Pass | C wrapper clears LD_* |
/proc/stat (os.cpus()) |
✅ Pass | proot bind mount of fake stat file |
| TUI file browser | ✅ Pass | Directory listing, splash, login page all work |
| Auto-update | C wrapper doesn't handle update logic yet | |
Non-/data/ path |
✅ Pass | Works under /data/data/ as well |
package.json lists os: ["darwin", "linux", "win32"], but Termux reports process.platform = "android".
Solution: Add "android" to the os list (patches/0001-add-android-os-support.patch).
index.js's PLATFORM_TARGETS has no android-arm64 entry.
Solution: Add the mapping android-arm64 -> freebuff-linux-arm64.tar.gz (patches/0002-add-android-platform-mapping.patch).
The downloaded binary is glibc-linked (compiled by Bun), but Termux uses Bionic libc.
Solution: Use patchelf --set-interpreter to change the interpreter to glibc's ld.so:
patchelf --set-interpreter /data/data/com.termux/files/usr/glibc/lib/ld-linux-aarch64.so.1 \
~/.config/manicode/freebuffThe kernel automatically invokes glibc's ld.so when the binary runs. No --library-path argument is needed.
In the Termux glibc package, libc.so, libm.so, and others are GNU ld scripts (ASCII text) instead of symlinks. When the Bun binary calls dlopen("libc.so") internally, it loads the non-ELF file and gets invalid ELF header.
Solution:
- Convert all
*.solinker scripts to symlinks pointing tolibc.so.N(versioned ELF files). - The C wrapper clears
LD_LIBRARY_PATHto prevent accidental leaks.
If the parent shell has LD_LIBRARY_PATH set, it leaks to glibc's ld.so and causes incorrect library loading.
Solution: The C wrapper calls unsetenv("LD_LIBRARY_PATH") and does not depend on any shell rc files.
Android 11+ kernels block unprivileged processes from reading /proc/stat, /proc/loadavg, and similar files. Bun's libuv calls uv_cpu_info(), which reads /proc/stat, gets EACCES, and fails with Failed to get CPU information (ERR_SYSTEM_ERROR).
Solution: Use proot to intercept the openat syscall for /proc/stat at the ptrace level, redirecting it to a hand-crafted fake file:
# Fake /proc/stat content (libuv only needs the stat fields to exist)
echo "cpu 0 0 0 0 0 0 0 0 0 0
cpu0 0 0 0 0 0 0 0 0 0 0
..." > /tmp/fake_stat
# proot bind mount
proot -b /tmp/fake_stat:/proc/stat freebuffThe C wrapper automatically detects whether proot is available and performs the steps above. Without proot, it falls back to direct execution (and os.cpus() will crash).
Android's SELinux policy restricts unprivileged processes from reading the contents of /data/ directories. Some Bun versions may trigger CouldntReadCurrentDirectory when scanning parent directories at startup.
Solution: This issue has limited impact on specific freebuff versions. The C wrapper may mitigate it through proot.
freebuff-termux/
├── scripts/
│ ├── install.sh # Fully automated install script
│ └── freebuff-wrapper.c # C wrapper source code (75 lines)
├── patches/
│ ├── 0001-add-android-os-support.patch
│ └── 0002-add-android-platform-mapping.patch
├── Makefile
└── README.md
The fully automated install script does the following:
- Queries the npm registry for the latest version
- Downloads the freebuff package with
npm pack - Patches
package.jsonto addandroidto the os field - Patches
index.jsto add theandroid-arm64platform mapping - Runs
termux-fix-shebangto fix shebang lines - Increases the download timeout (20s to 120s)
- Repacks and installs globally
- Triggers the binary download (GitHub Releases ~129MB)
- Runs
patchelfto set the interpreter to glibc's ld.so - Fixes glibc library linker scripts (
.soto symlinks) - Compiles the C wrapper and installs it as
/usr/bin/freebuff
A Bionic-compiled C wrapper (~5KB) with this logic:
- Calls
unsetenv()to clearLD_LIBRARY_PATH,LD_PRELOAD, and similar variables - Detects whether proot is available, creates a fake
/proc/stat, and runsproot -bbind mount - Calls
execvp()to launch the binary - Does not depend on bash, zsh, node, or any rc files
- Falls back to direct execve when proot is unavailable
| Package | Required | Install |
|---|---|---|
nodejs |
✅ Required | pkg install nodejs |
glibc |
✅ Required | apt install -y glibc-repo && apt update && apt install -y glibc |
openssl-glibc |
✅ Required | apt install -y openssl-glibc |
patchelf |
✅ Required | pkg install patchelf |
gcc |
✅ Required (compiles C wrapper) | pkg install gcc |
proot |
✅ Strongly recommended | pkg install proot (without it, os.cpus() crashes) |
- Auto-update: Freebuff's auto-update needs the JS wrapper's spawn path. The C wrapper doesn't handle updates yet, so manual reinstall is required.
- proot dependency: Without proot, the CLI crashes due to
os.cpus()(though--versionworks fine). - glibc dependency: Requires additional installation of glibc and openssl-glibc.
- Network requirement: First download is ~124MB.
- proot performance overhead: ptrace mode introduces slight I/O latency (imperceptible during interactive TUI use).