Skip to content
flow

WorkspacePersistent sessions and shell history

Persistent sessions and shell history

Keep shells running across Flow restarts and updates, how panes reattach, per-pane zsh history, the gh and git shell aliases, and agent shell capture.

View as Markdown
On this page

With Persist sessions on (the default), the shell in each pane runs inside a small holder process, flow-session, that keeps going when Flow quits. Relaunch or update Flow and every pane reattaches to its own shell, with its recent output replayed, so a long build or an agent mid-turn carries on. Your sessions, labels and layouts are restored on every launch either way; this setting decides whether the shells themselves survive.

Turn it on or off

SettingKeyTypeDefault
Settings › General › Sessions › Persist sessionsterminal.persistbooltrue
  • On: shells keep running when Flow quits, and panes reattach to them on relaunch.
  • Off: every pane is a plain shell that ends with Flow. On the next launch the same layout comes back with fresh shells.

Sharing a session with a paired device, and starting sessions from one, need Persist sessions on. See Puddle.

What survives, and what ends a shell

EventThe shell
Quitting Flow, or Flow relaunching after an updateKeeps running; the pane reattaches on the next launch
Closing the tab, its tile or its session in FlowEnds: Flow hangs up the shell (and kills it after one second if it is still there)
The shell exiting (exit, the program ending)The pane closes. For a session's primary pane that closes the session.

Holders are independent of Flow's version: one started by an older Flow keeps running across an update, and the new Flow reattaches to it.

What reattaching looks like

On reattach the holder replays the last 1 MiB of the shell's output, then resizes the terminal so a full-screen program (an editor, htop, an agent's UI) redraws itself. Anything you type while the replay is still arriving is discarded, so a reply meant for an old prompt never reaches the shell.

If a pane cannot attach

  • If the connection to a live holder breaks, or another Flow attached to the same session, the pane stays open with a one-line notice. Press ↩ in it to reattach. It never reattaches on its own, so two copies of Flow cannot steal a session back and forth.
  • If the holder speaks a different protocol version, the pane says so instead of showing garbage.
  • If no session can be started at all, the pane runs a plain login shell and says why.
  • If the flow-session helper is missing from Flow.app, panes run plain shells with a notice that they will not survive a restart. Reinstall Flow, or turn Persist sessions off.

Inspect holders from a terminal

flow-session lives inside the app bundle; it is not linked onto your PATH.

sh
/Applications/Flow.app/Contents/MacOS/flow-session list

Each line is name, the shell's process id, and attached or detached, separated by tabs. A holder is attached while a Flow pane is connected to it.

sh
# end one session's shell, as closing its tab would
/Applications/Flow.app/Contents/MacOS/flow-session kill NAME

Holders keep their sockets and locks in ~/.flow/sessions/ (created with mode 700). Inside a persistent shell, FLOW_SESSION_NAME holds the session's name.

Per-pane shell history

In zsh, the up arrow in a Flow pane recalls that pane's own commands, not every other pane's, the way Terminal.app does. Other shells, bash included, are left alone.

How it behaves:

  • A persistent pane keeps its history in ~/.flow/history/NAME.history, named after its holder, so a pane restored after a relaunch gets its history back.
  • A new persistent pane starts with a copy of your global history (your HISTFILE) as it is at that moment; commands other panes run later do not appear in it.
  • When a shell exits, its commands are also appended to your global HISTFILE, so new shells and other terminals see them.
  • A pane without a holder (Persist sessions off) reads your global history and deletes its own file when it exits.
  • Closing a persistent pane in Flow deletes its history file. History files unused for 30 days are removed at launch.

Flow does this by pointing ZDOTDIR at a small shim directory that sources your own .zshenv, .zprofile, .zshrc and .zlogin, then sets the pane's history file. Your configuration still loads as usual.

Turn per-pane history off

Your global behaviour is kept, with no per-pane history, when any of these is true after your .zshrc runs:

  • HISTFILE is unset or empty,
  • SAVEHIST is 0,
  • the SHARE_HISTORY option is set.

Limits

  • A ZDOTDIR set in /etc/zshenv overrides the shim: no per-pane history.
  • NO_RCS set in your own .zshenv stops the later startup files and the per-pane history.
  • exec zsh starts a shell without the shim; the commands typed before it are folded in the next time the pane starts.
  • A session reopened from History is a new pane with fresh history, since closing it deleted its file.

Route gh and git through ghx and gitx

Flow can add two small, marked blocks to the end of your ~/.zshrc so that gh and git typed in your shells (and run by agents in them) go through Flow's ghx and gitx. ghx serves GitHub reads from its cache and refreshes it after writes; gitx runs the real git and tells ghx after a push.

Turn each on or off with the buttons in Settings › General › Pull requests ("Route gh through ghx", "Route git through gitx"), or the palette actions Route gh through ghx (~/.zshrc)… and Route git through gitx (~/.zshrc)…. The blocks look like this:

text
# >>> flow: route gh through ghx (managed by Flow Settings) >>>
if command -v ghx >/dev/null 2>&1; then alias gh=ghx; fi
# <<< flow: route gh through ghx <<<

# >>> flow: route git through gitx (managed by Flow Settings) >>>
if command -v gitx >/dev/null 2>&1; then alias git=gitx; if (( $+functions[compdef] )); then compdef gitx=git; fi; fi
# <<< flow: route git through gitx <<<
  • Only new shells pick them up; running shells keep the old gh and git until they re-read ~/.zshrc.
  • The tools must be on your PATH (see Installation); without them the command -v guard leaves gh and git alone, and Flow warns you.
  • Turning one off removes exactly its block. A symlinked ~/.zshrc is followed and its target edited.
  • zsh -c scripts, bash and programs that exec gh directly do not see the aliases.

More in ghx and gitx.

Agent shell capture

When Claude Code runs shell commands in a Flow pane, Flow can record each one, with its output, and show them in a Shells tab for that pane: live output, interrupt, kill, rerun and copy, and a list of runs. The tab opens by itself the first time an agent in the session runs a shell; you can also run New Shells tab or pick Shells in the New tab launcher.

SettingKeyValuesDefault
Settings › General › Agents › Shell captureshells.captureoff (Off), background (Background only), all (All shells)all

Turning capture on applies to panes opened afterwards; turning it off, or switching between Background only and All shells, applies from the next shell in panes already open. Records are kept in ~/.flow/shells/, readable only by you (commands and their output can hold secrets); the output Flow copies for one run is capped at 16 MiB.

Sources

Written from these files in the Flow app repo

  • src/bin/flow-session.rs
  • src/term.rs
  • src/shell_history.rs
  • src/shell_alias.rs
  • src/shell_store.rs
  • src/shells_ui.rs
  • src/settings_catalog.rs
  • src/updater.rs
  • src/persist.rs
  • src/pages.rs