Closing a terminal workspace should not mean reconstructing it from memory the next morning. Which project was open? Which directories were expanded? Was the terminal maximized? Where did the build fail?

But restoring a workspace is not the same thing as restoring a running process. In Forge, that distinction shapes the entire recovery design.

Engineering note based on Forge’s workspace recovery implementation and recovery tests. Prepared with AI assistance.

Restore the working context, not the execution

Consider two shell tabs in a Rust project: one for running tests, another for inspecting a different directory. After restarting Forge, the useful context is the tabs, their working directories, retained output, file navigation, and whether the terminal panel was visible, maximized or in its normal split layout.

A saved command line is a different kind of state. Replaying it could start a second server, run a migration twice, or execute a destructive command. Forge instead creates fresh shells using the available configured profiles and recovered directories. It does not serialize arbitrary commands, shell environments or live process memory.

This is workspace recovery, not process checkpointing or persistent PTY attachment. A build, SSH session or interactive coding agent that has stopped cannot be resurrected from its displayed output.

Give each kind of state its own owner

Forge keeps layout state, file navigation and terminal sessions in their existing owners. The persistence layer consumes snapshots from those owners, rather than making every component depend on a storage service.

LayoutState -------- layout snapshot ----+
FilesState --------- navigation snapshot +--> Workspace store
TerminalSessions --- restorable groups --+         |
                                                    v
                                      ~/.forge/workspaces/<key>/
                                        workspace.json
                                        terminals.json
                                        writer.lock

The two JSON records have separate responsibilities. The workspace record stores the project identity, layout and file navigation. The terminal record stores restorable tabs, their labels, profile identifiers, directory metadata, optional display history and panel visibility/maximization.

A project is identified by the SHA-256 hash of its canonical root path, not its directory name. The record also includes a schema version and the root itself for validation. Two repositories named app in different locations therefore do not accidentally share a workspace. Moving a project does not automatically migrate its saved state.

The default user directory is ~/.forge; FORGE_HOME can override it. See workspace_storage.rs and terminal_sessions.rs.

Working directory is not project navigation

A shell can move outside the project without changing which project the user is browsing. Automatically following every cd would make the file tree, preview and focus move unexpectedly, especially with several tabs.

Forge treats the shell directory as per-tab metadata. The saved descriptor prefers an available process working directory, then a validated local OSC 7 directory report, then the initial launch directory. The availability of current-directory information depends on the platform and shell.

Project navigation remains explicit. Opening a terminal at a selected directory or clicking a verified file link is an intentional action; ordinary shell output is not a navigation event. Recovered file selections and expanded directories are validated against the current project. An old preview is not automatically reopened by a terminal directory change.

History is display data, not a command stream

Saving a raw PTY byte stream would preserve escape sequences as well as text. Those bytes can contain requests affecting clipboard state, terminal titles and other behavior. Replaying them through the normal input/output pipeline is unnecessary for showing a previous build log.

Forge captures bounded styled rows from the terminal emulator’s screen instead. On import, it validates the snapshot and constructs printable text, line breaks and permitted styling sequences for its local parser. Saved history is not sent to the new shell or dispatched through terminal protocol callbacks.

The retained-history format has explicit limits: at most 2,000 rows, 512 columns, one million cells, and a 768 KiB capture budget per snapshot. The terminal group accepts up to eight saved tabs. Workspace JSON and terminal JSON have separate size limits of 1 MiB and 8 MiB respectively.

These are limits, not typical storage usage or guarantees that all scrollback will be preserved. Old output can be truncated. Displayed text can still contain secrets or personal information; disable terminal history persistence if that is unsuitable for your workflow.

See retained_history.rs.

Recovery is a policy, not an unconditional side effect

Forge exposes three terminal recovery modes:

  • Auto: automatically restore eligible saved shells when the recovery policy is applied.
  • Ask: present the saved terminals for explicit selection.
  • Manual: leave saved descriptors dormant until the user requests recovery.

Auto is the current default. Ask and Manual provide more control for users who do not want new shells to launch automatically. Terminal history persistence is separately configurable and enabled by default.

A new shell may execute its normal profile or startup configuration. That is different from replaying arbitrary commands captured from a previous session.

The terminal’s panel state is retained: a normal split, a maximized terminal, or a hidden panel. Recovering these visual choices should not require resurrecting the original process.

Make persistence boring and bounded

Workspace persistence runs at lifecycle boundaries, including project navigation and normal application exit, rather than on each terminal byte, keystroke or render frame. The existing PTY parser and rendering path do not write snapshots for every update.

At a save boundary, Forge serializes a size-checked record, writes it to a temporary file in the same directory, synchronizes the file, and persists it over the previous record. A nonblocking per-project OS lock prevents a second Forge instance from overwriting the first instance’s recovery state. An instance denied write ownership remains read-only for that project, even if the original writer exits later.

Unknown versions, invalid identities and unreadable records are treated as errors rather than silently overwritten. The two records are handled independently; this is not a transactional checkpoint across both files.

The design avoids continuous persistence overhead, but saving and restoring large histories still costs CPU, memory and disk I/O at the boundaries. An abrupt termination may lose changes made since the last successful save. This is not a zero-overhead or crash-proof guarantee.

Test the restart boundary

A serialization round trip alone cannot verify that the real application restores a visible panel without stealing focus or reopening a hidden terminal. Forge has dedicated restart smoke tests alongside Rust unit tests.

From the repository root:

cargo test -p forge-app workspace_storage
cargo build
python3 scripts/smoke-workspace-restore.py
python3 scripts/smoke-terminal-panel-restore.py
python3 scripts/smoke-recovery-edges.py

The smoke scripts use tmux as a test harness for real terminal interaction; this does not make tmux a dependency of Forge’s workspace recovery. They isolate saved state using a temporary FORGE_HOME. The tests cover project identity, panel recovery, recovery policy and edge cases. These commands are provided for reproduction, not as new benchmark results.

A workspace should remember without taking control

The aim is not to turn a file and Git TUI into a process supervisor. It is to preserve the context that lets a developer return to work: the project, its navigation, the terminal layout and useful recent output.

The essential design rule is simple: persist the state that belongs to the workspace, reconstruct only what can be safely reconstructed, and keep navigation and execution under the user’s control.

Explore Forge on GitHub, the user guide or our engineering note on bounded filesystem events.