# Termux + tmux cheat sheet: drive the Pi from a tablet or phone

From the OpsCode resources store: https://opscode.ai/resources/pi-command-server/
Works on any Android tablet or phone. We use a Samsung Galaxy Tab S11 and a Pixel.

## One-time setup on the tablet or phone

1. **Tailscale** from the Play Store. Sign in with the same account as the Pi.
2. **Termux** from F-Droid ONLY: https://f-droid.org/en/packages/com.termux/ (the Play Store version is outdated and broken). Then inside Termux:

```bash
pkg update && pkg upgrade -y
pkg install openssh -y
```

3. **SSH key, then never type a password again:**

```bash
ssh-keygen -t ed25519          # enter through all prompts
mkdir -p ~/.ssh
printf 'Host pi\n    HostName <your-pi-tailscale-ip>\n    User <your-user>\n' >> ~/.ssh/config
ssh-copy-id pi
```

From now on the whole connection is: `ssh pi`

4. **Stop Android killing Termux:**

```bash
termux-wake-lock               # run each time you open Termux
```

Also: Android Settings → Apps → Termux → Battery → Unrestricted.

5. **Extra keys row** (Ctrl, Esc, Tab, arrows on screen): long-press the Termux screen → More → Extra Keys Row.

## Daily workflow

```bash
termux-wake-lock
ssh pi
tmux attach -t ops || tmux new -s ops
claude                          # and you're exactly where you left off
# when done: Ctrl+B then D (detach, session keeps running)
```

Split screen on the tablet: Termux on the left running Claude Code, Chrome on the right previewing whatever the Pi serves (`http://<pi-ip>:3000`).

## Volume-key combos (no keyboard attached)

| Combo | Acts as |
|---|---|
| Vol Up + E | Ctrl |
| Vol Up + T | Tab |
| Vol Up + Q | Esc |
| Vol Up + W / A / S / D | arrow keys |
| Vol Up + L | pipe |
| Vol Up + U | underscore |

## tmux essentials

Everything starts with the prefix `Ctrl+B`, then a second key.

| Action | Keys or command |
|---|---|
| List sessions | `tmux ls` |
| New named session | `tmux new -s name` |
| Attach | `tmux attach -t name` |
| Detach (keeps running) | `Ctrl+B` then `D` |
| Session picker | `Ctrl+B` then `S` |
| New window (tab) | `Ctrl+B` then `C` |
| Next / previous window | `Ctrl+B` then `N` / `P` |
| Split vertical / horizontal | `Ctrl+B` then `%` / `"` |
| Move between panes | `Ctrl+B` then arrows |
| Scroll mode | `Ctrl+B` then `[` (press `Q` to exit) |
| Kill a session | `tmux kill-session -t name` |

## Line editing (works everywhere)

| Action | Keys |
|---|---|
| Start / end of line | `Ctrl+A` / `Ctrl+E` |
| Delete word back | `Ctrl+W` |
| Delete to end / start of line | `Ctrl+K` / `Ctrl+U` |
| Search command history | `Ctrl+R` then type |
| Autocomplete | `Tab` |

## Send a screenshot to Claude Code

One-time, in a **local** Termux session (not SSH'd):

```bash
termux-setup-storage           # tap Allow

cat >> ~/.bashrc <<'EOF'
sendshot() {
    latest=$(ls -t ~/storage/dcim/Screenshots/*.{png,jpg} 2>/dev/null | head -1)
    if [ -z "$latest" ]; then echo "No screenshots found"; return 1; fi
    scp "$latest" pi:/tmp/screenshot.png
    echo "Sent: $(basename "$latest") -> pi:/tmp/screenshot.png"
}
EOF
source ~/.bashrc
```

Daily use:

1. Take a screenshot (Power + Volume Down).
2. In the local Termux session: `sendshot`
3. In your Claude Code session on the Pi: `Read /tmp/screenshot.png`

You need two Termux sessions for this (swipe from the left edge to switch): one local for `sendshot`, one SSH'd into the Pi for Claude Code.

## Copy terminal output instead of screenshotting it

```bash
tmux capture-pane -p -S -50            # last 50 lines to screen
tmux capture-pane -p -S -200 > /tmp/out.txt
```

## Phone-specific tips

- Landscape mode, pinch to zoom the font.
- One pane at a time, skip the splits.
- Great on the phone: `tmux ls`, checking session output, `git status`, restarting a service.
- Not great on the phone: long prompts, code-server.

---

Built and documented by OpsCode, Operations as Code. https://opscode.ai
