Skip to content

Coding agents

Long-running sessions with tmux

Keep coding agents running in a flockvm VM after you disconnect: tmux basics, logging, headless runs, and what survives a pause and resume.

An agent started straight from your SSH session dies when the connection drops. Start it inside tmux instead: the session lives in the VM, and you attach and detach as you like. tmux is already installed in every flockvm VM, on both images. The commands below log in as user, the login of the Agent image; on a Minimal VM, use the user you run your agent as (see Run Claude Code in a VM).

tmux in one minute

You want to Run or press
Start a named session tmux new -s claude
Start one in the background, running a command tmux new -d -s task 'npm test'
Detach, leaving it running Ctrl-b then d
List sessions tmux ls
Attach again tmux attach -t claude
Open a new window in the session Ctrl-b then c
Switch window Ctrl-b then the window number, or Ctrl-b w for a list
Scroll back Ctrl-b then [, arrows or PgUp, q to leave
End a session tmux kill-session -t task

Claude Code also uses Ctrl-b: inside tmux, press it twice to send it to Claude Code.

Survive a dropped connection

  1. SSH in and start a session

    ssh -p 22001 user@HOST
    tmux new -s claude
  2. Start the agent inside it

    cd ~/your-repo
    claude --dangerously-skip-permissions
  3. Detach and leave

    Press Ctrl-b then d, and close your terminal, or let Wi-Fi drop. The agent keeps working in the VM.

  4. Come back

    Attach straight from your laptop in one command:

    ssh -t -p 22001 user@HOST tmux attach -t claude

    -t gives tmux the terminal it needs. tmux new -A -s claude attaches to the session if it exists and creates it otherwise.

To keep idle SSH connections from being closed by routers along the way, add keepalives to your SSH config:

~/.ssh/config
Host HOST
  ServerAliveInterval 30
  ServerAliveCountMax 4

mosh does not work

Each VM accepts only one inbound port from the Internet: its SSH port, which forwards to the VM's port 22. mosh needs inbound UDP, which never reaches the VM. Use SSH with tmux and keepalives instead.

Log what the agent does

tmux keeps a scrollback, not a file. To keep a full record, write one.

Pipe the command through tee when you start it. Works best for non-interactive runs:

tmux new -d -s task 'cd ~/your-repo && npm test 2>&1 | tee ~/test.log'
tail -f ~/test.log

Copy logs back to your laptop with scp -P 22001 user@HOST:claude-session.log ..

Run Claude Code headless

claude -p runs one prompt without the interactive UI, prints the result and exits. It skips the folder trust dialog, so it works from a script:

As user, inside the VM
cd ~/your-repo
tmux new -d -s nightly 'claude -p --dangerously-skip-permissions "Update the dependencies, fix what breaks, run the tests, and commit" 2>&1 | tee ~/nightly.log'

Check whether it is still running:

tmux has-session -t nightly 2>/dev/null && echo running || echo done

When the command ends, its tmux session closes; the log stays. To keep the window open after the command ends, so you can read the end of it in tmux, append ; exec bash to the command. The Codex equivalent is codex exec: see Run Codex CLI in a VM.

Several agents in one VM

One VM can hold several tmux windows, one agent per window, each in its own git worktree:

As user, inside the VM
cd ~/your-repo
git worktree add -b task-a ../task-a
git worktree add -b task-b ../task-b
tmux new -d -s agents -n a -c ~/task-a
tmux new-window -t agents -n b -c ~/task-b
tmux send-keys -t agents:a 'claude --dangerously-skip-permissions' Enter
tmux send-keys -t agents:b 'claude --dangerously-skip-permissions' Enter
tmux attach -t agents

Each new worktree asks once whether you trust the folder: attach and answer in each window. The agents still share the VM's CPU, RAM, ports and database. When they start servers or run migrations, use one VM per agent. The tmux settings for Shift+Enter, notifications and spotting a waiting agent are in Claude Code with tmux.

What happens on pause and resume

Pausing a VM is the cheap way to leave an agent session overnight.

Action Your tmux sessions and agents Disk Billing
Pause Frozen: memory and processes are written to disk Kept Stops
Resume Back where they were: same processes, same PIDs Kept Starts again
Stop Gone: the VM shuts down cleanly Kept Stops
Start A fresh boot: start your sessions again Kept Starts again
Delete Gone Deleted Stops

On Resume, tmux and everything in it continue where they were. Open TCP connections survive the pause, so an SSH session attached at the moment of the pause can come back as well. The VM's clock is set to the current time on resume.

What can still fail: services outside the VM did not pause. A request your agent had in flight to a model API or a Git host may have timed out on the other side, and the agent sees an error. Pause between tasks, when the agent is idle or waiting for you, rather than in the middle of a long request.

Pause keeps memory and processes. Stop keeps only the disk.

Before you stop a VM

Stop ends every process, tmux included. If you want the session back as it was, Pause instead. Paused and stopped VMs are not billed for now.

See a dev server from your laptop

Only the SSH port is open, so reach a server the agent started inside the VM through an SSH tunnel:

On your laptop
ssh -N -L 3000:localhost:3000 -p 22001 user@HOST

Then open http://localhost:3000 in your browser. Stop the tunnel with Ctrl-c.

Next steps