🐚 Persistence Protocol: The "Sagar Builds" Guide to Background Stability
You’ve successfully bypassed the Bionic kernel and got OpenClaw running, but there’s a new enemy: Android’s Battery Optimizer. This guide shows you how to use tmux and WakeLock to ensure your gateway stays online even when you close the Termux app or switch to Instagram.
📺 Video Guide
Coming Soon Tomorrow 8 am
🛠️ Prerequisites
- Termux: Properly configured (F-Droid version).
- OpenClaw: Installed via
npmor running inside aprootdistro. - Battery Settings: "Unrestricted" battery usage enabled for Termux in Android Settings.
1. Install the "Safety Net"
Standard Termux sessions die the moment you swipe the app away. We use tmux (Terminal Multiplexer) to create a persistent server process that lives independently of the terminal window.
# Install tmux
pkg update && pkg upgrade -y
pkg install tmux -y
# Start a named session for OpenClaw
tmux new -s claw
2. Launching in the Background
Once inside the tmux session (you'll see a green bar at the bottom), launch your OpenClaw gateway as you normally would.
# Example: Running inside Ubuntu proot
proot-distro login ubuntu
openclaw gateway --verbose
🪄 The "Magic Trick" (Detaching)
To keep the game running while you leave the app, you must detach rather than exit.
- Press
Ctrl + Bon your keyboard. - Release and immediately press
D. - Termux will say
[detached (from session claw)]. You can now safely minimize the app.
3. The CPU WakeLock
Even with tmux, Android will "freeze" the CPU to save power if the screen is off. You must explicitly tell the kernel to stay awake.
Method A: The Notification Toggle
- Pull down your Android notification shade.
- Find the Termux entry.
- Tap "Acquire WakeLock".
Method B: The Command Line You can also trigger this directly from the terminal:
termux-wake-lock
4. Re-engaging the Gateway
When you want to check your logs or interact with the session again, simply re-attach to the background process.
# See all active sessions
tmux ls
# Re-attach to the claw session
tmux attach -t claw
[!IMPORTANT] Phantom Process Killer: If you are on Android 12 or 13 and your sessions still die, Android is likely triggering the "Phantom Process Killer." You may need to disable this via ADB using:
adb shell "/system/bin/device_config put activity_manager max_phantom_processes 2147483647"
Pro-Tips
- Battery Saver: Never enable "Power Saving Mode" while running OpenClaw. It overrides your WakeLock and will kill the process immediately.
- Auto-Resurrect: Look into the
tmux-resurrectplugin if you want your sessions to survive a phone reboot. - Visibility: If you don't see the "Acquire WakeLock" button in your notifications, make sure "Standard Notifications" are enabled for Termux in your system settings.