Tutorial Details Running Terminal AI Agents on Android via Termux
A 少数派 tutorial explains how to run terminal AI agents such as Hermes and Pi on an Android phone using Termux, covering installation, background survival, and mobile integrations.
The tutorial says terminal AI agents differ from web chat interfaces by running inside a local shell and file environment, allowing them to execute scripts, modify code, and troubleshoot automatically. On a phone, ordinary AI chat tools often output Python code without a runtime, while an agent in Termux can run scripts in the background and save formatted Markdown, JSON, or processed files directly to local directories. It can also unpack and filter large archives, logs, or open-source test sets locally with unzip, tar, or grep, sending only the relevant fragments to the model instead of uploading the entire file from the phone.
The article highlights termux-api integration: an agent can call termux-notification to alert the user when a long batch task finishes, and it can read from and write to the system clipboard so content copied in another app can be processed in the terminal and pasted back. The author recommends installing Termux only from GitHub Releases rather than app stores. The Google Play version is no longer maintained, and the F-Droid version uses a different signing key, which can cause signature conflicts when installing add-ons such as Termux:API and Termux:Boot. The recommended packages include termux-app, termux-api, and termux-boot.
After installation, the tutorial suggests granting storage permission, switching to a domestic mirror with termux-change-repo, and upgrading base system components. It then recommends installing Hermes Agent, an open-source CLI agent from Nous Research that supports terminal execution, task planning, and file read/write, with a Termux-specific pip install path. The first run enters an interactive setup for choosing a model provider, entering an API key, and selecting a model; the author chose DeepSeek. Settings can later be changed with /config or /model. The user can also ask Hermes to install a development toolchain including nodejs, rust, uv, git, jq, ripgrep, yazi, tmux, neovim, openssh, termux-services, and termux-api.
The article provides a 2026 compatibility overview for major CLI AI tools on Termux. Hermes Agent and Pi CLI are natively supported. OpenCode and Codex CLI require community versions that patch Android compatibility issues. Grok Build can be compiled from source with Rust. Cursor CLI requires a Linux container installed through proot-distro. Claude Code has no stable solution because it is deeply tied to Node desktop build chains, and its mobile dependencies often break.
For background survival, the tutorial says Android process killing can freeze Termux after the screen turns off, causing SSH disconnections and interrupted scripts. It recommends three layers of configuration: set the battery policy to unrestricted, disable lock-screen memory cleanup, and enable “Disable child process restrictions” in developer options to turn off the Phantom Process Killer. If problems remain, it suggests using Android's background exemption for media audio apps by looping a one-minute silent WAV file generated with ffmpeg to gain audio focus. The article warns that silent looping can seize the A2DP Bluetooth channel when a Bluetooth headset is connected, causing audio dropouts or device switching. It recommends detecting Bluetooth status and pausing playback when a headset is connected, then resuming after disconnection. The tutorial then begins to describe a keepalive script at ~/.termux/scripts/keepalive.sh.