Skip to content

Session Persistence

Session persistence keeps your terminal context available across VS Code restarts. Secondary Terminal can automatically save and restore scrollback, preserve ANSI color output, enforce storage limits, and give you manual commands for saving, restoring, or clearing saved state.

What Gets Preserved

Preserved dataDetails
Terminal outputScrollback is stored and restored into the terminal view.
ANSI formattingColor and formatting sequences are preserved instead of flattened into plain text.
Terminal stateSession metadata is restored so the layout feels continuous.
Recent historyConfigurable scrollback limits prevent runaway storage usage.

The extension focuses on output persistence, not process persistence. Long-running shells and commands do not keep running through a full VS Code restart, but the visible terminal history is still there when you come back.

Core Settings

SettingDefaultDescription
secondaryTerminal.enablePersistentSessionstrueEnables session save and restore.
secondaryTerminal.persistentSessionScrollback1000Number of lines restored from history.
secondaryTerminal.persistentSessionReviveProcess"onExitAndWindowClose"Controls when sessions are saved.
secondaryTerminal.persistentSessionStorageLimit20Maximum storage size in MB.
secondaryTerminal.persistentSessionRetentionDays7Retains saved sessions for one week by default.
secondaryTerminal.persistentSessionStorageWarningThreshold80Warning threshold before optimization is needed.

Scrollback Storage Controls

Older compatibility settings are also available for scrollback-specific behavior:

SettingDefaultDescription
secondaryTerminal.restoreScrollbacktrueRestores terminal history buffer.
secondaryTerminal.scrollbackLines2000Maximum lines restored from saved history.
secondaryTerminal.scrollbackCompressiontrueCompresses saved scrollback to reduce storage use.
secondaryTerminal.scrollbackProgressiveLoadfalseLoads large histories progressively instead of all at once.
secondaryTerminal.scrollbackMaxStorageSize20971520Maximum raw storage in bytes, about 20MB.
secondaryTerminal.features.enhancedScrollbackPersistencetrueUses the more VS Code-like persistence path.
secondaryTerminal.features.scrollbackLineLimit1000Caps enhanced persisted output.
secondaryTerminal.features.fullANSISupporttruePreserves ANSI colors and formatting during restore.
json
{
  "secondaryTerminal.enablePersistentSessions": true,
  "secondaryTerminal.persistentSessionScrollback": 1500,
  "secondaryTerminal.persistentSessionStorageLimit": 20,
  "secondaryTerminal.persistentSessionRetentionDays": 7,
  "secondaryTerminal.scrollbackCompression": true
}

Manual Session Commands

If you want tighter control than auto-save, use the built-in commands.

CommandPurpose
secondaryTerminal.saveSessionSave the current terminal session explicitly.
secondaryTerminal.restoreSessionRestore a previously saved session.
secondaryTerminal.clearSessionClear the saved session for the current terminal.
secondaryTerminal.diagnoseSessionInspect session-related data when debugging restore issues.
secondaryTerminal.clearCorruptedHistoryRemove damaged scrollback data and reset the saved history.

Storage Limits and Retention

The default storage limit is 20MB, and the default retention window is 7 days. That is enough for normal terminal workflows, including ANSI-rich command output, without letting the extension accumulate large stale histories over time.

If your project produces extremely large output, lower the restored scrollback lines or enable progressive loading. If you want longer history retention, increase the limits carefully because more history means more startup work and larger extension storage.

Good Use Cases

ScenarioWhy persistence helps
Review-heavy workflowsKeep test output and diffs visible after restart.
AI-assisted sessionsRestore prior prompts and model responses.
Long setup commandsAvoid rerunning setup just to see what happened before.
Temporary restartsPick up your context quickly after VS Code reloads.

Released under the MIT License.