Skip to content

Persist terminal tabs and scrollback across restarts - #3

Merged
frenchie4111 merged 1 commit into
mainfrom
add-persistent-terminals
Apr 10, 2026
Merged

Persist terminal tabs and scrollback across restarts#3
frenchie4111 merged 1 commit into
mainfrom
add-persistent-terminals

Conversation

@frenchie4111

Copy link
Copy Markdown
Collaborator

Summary

  • Tab metadata (claude + shell only — diff tabs are transient) is now saved in config.json per worktree path and restored on app launch.
  • xterm's SerializeAddon captures each terminal's buffer; history is written to userData/terminal-history/<id>.txt on a 30s interval and synchronously via beforeunload when the window closes.
  • On mount, XTerminal loads any saved history, writes it to the fresh xterm with a ── session restored ── separator, then spawns a new pty — so users see their previous output scrolled above a fresh shell.
  • Explicitly closing a tab or deleting a worktree marks the id as closing (suppressing pending saves) and deletes its history file. Orphaned history files are pruned on startup.

Caveats

  • Scrollback is visual only. The shell process is new on each launch — env, cwd, and $? do not survive. Claude sessions still rely on claude --continue (already the default).
  • xterm's default scrollback (1000 lines) caps per-terminal history file size.

Test plan

  • Open a shell tab, type some commands, quit with Cmd-Q, reopen — tab reappears with scrollback visible above a fresh prompt.
  • Same flow but close the tab explicitly before quitting — tab does not reappear and userData/terminal-history/ has no file for that id.
  • Delete a worktree with active terminals — its history files are removed.
  • Quit with multiple tabs across multiple worktrees — all restore correctly.

🤖 Generated with Claude Code

Tab metadata (claude + shell) is saved in config.json per worktree;
xterm serialize-addon captures each terminal's buffer to
userData/terminal-history/<id>.txt on an interval and synchronously on
window beforeunload. On mount, history is written to the fresh xterm
before spawning a new pty, so users see their previous output above a
new shell. Closing a tab or deleting a worktree drops the history file.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant