My Pi Keeps Losing Power. My AI Coding Sessions Survive Anyway.
Aug 8, 2026
A Raspberry Pi on a battery dies without warning. That used to mean losing every AI coding session I had open. Now it doesn’t.
My Pi runs off an EcoFlow portable battery. When I forget to charge it, or move it, or the power dips, it dies. No warning, no shutdown sequence. Just gone.
And until recently, that meant losing every AI coding session I had open. Claude Code mid-refactor. OpenCode mid-test-fix. Sessions I’d been building context in for hours. Bringing them back was a dozen manual steps: boot, re-attach tmux, hunt down each session ID, relaunch each agent with the right flags and environment.
I got tired of it, so I built a tool. It’s called tmux-alwayson, it’s written in Go, and its whole job is to survive whatever the power does to my Pi.
What tmux-alwayson install sets up, in one command
- TPM (the tmux plugin manager) with tmux-resurrect and tmux-continuum, so sessions are saved and restored across reboots
- Bash hooks that detect which agent is running in each pane and capture its session ID (from the companion tmux-assistant-resurrect hooks repo)
- A boot-safe systemd unit that starts tmux with a placeholder session so resurrect has a target to restore into
- A systemd timer that runs a guarded save every five minutes
- Linger enabled, so the units run even when nobody has logged in
After that, tmux-alwayson status shows you what’s installed and when the last good save happened. uninstall undoes it. That’s the whole surface.
How the session save actually works
At the core is a small guard script that wraps tmux-resurrect’s save process and runs it on a five-minute timer. It checks three things before trusting a save:
- Did the save actually finish? The built-in autosave runs in the background and isn’t guaranteed to complete, so my timer runs the save directly instead — it either finishes cleanly or it doesn’t, with no silent partial saves.
- Is the save actually empty? If a save captured zero panes, that’s a crash artifact, not a real save, so the guard throws it out and keeps the last good one instead of overwriting it with junk.
- Are the session IDs still real? Sometimes a session gets recorded before the agent has actually written it to disk, leaving a reference to something that doesn’t exist — this is the bug that bit me most. So the guard double-checks every saved session ID and swaps in a valid one, or drops it entirely, rather than handing you a restore command that’s guaranteed to fail.
Each AI agent plugs into the same small set of rules: how to detect it’s running, how to check if a session is still valid, and how to resume it. That consistency is what let me support nine different tools without writing nine different systems.
Adding support for a new agent means implementing that one set of rules — no rewrite needed. The registry now covers nine agents, including Claude Code, OpenCode, Codex CLI, and Gemini CLI, with six fully wired up and three more ready to go. Resumes also preserve each session’s original flags and environment, so you don’t come back to a confusing half-restored state.
Limitations
- Sudden power loss (not a clean sudo reboot) can still lose up to one save interval — five minutes, by design. Any interval-based save has that gap; the guard makes sure the save is never corrupted or silently empty, but it can’t conjure a save that never happened.
- Claude Code’s one-time “trust this folder” prompt still needs a keypress. That’s on Anthropic, not on me.
Now when my machine comes back, my agents come back with it. One command instead of a dozen manual steps. A power cut is a non-event.
That’s the whole story. If you want it for your own setup:
go install github.com/nahidspace/tmux-alwayson/cmd/tmux-alwayson@latest
tmux-alwayson install
The full source is on GitHub at github.com/nahidspace/tmux-alwayson. If it’s useful to you, a star helps others find it — and it’s open to contributions: new agent implementations, bug reports, whatever you’ve got.