# Terminal Sessions

_How Treq runs shell and agent processes inside a workspace._

Each Treq workspace can run multiple terminal sessions. Every live session has its own pseudoterminal process and starts from the workspace directory.

## Architecture

The frontend renders output with xterm.js. It supports copy and paste, clickable links, and terminal codes for color and cursor control.

The Rust backend creates pseudoterminals with `portable-pty`. Input flows from xterm.js to the process, and process output streams back to xterm.js. The frontend keeps up to 5,000 lines of scrollback for each mounted terminal.

## Session Management

Sessions run independently. Switching tabs keeps mounted sessions alive, so commands continue to run while another terminal is visible.

Creating a terminal starts a PTY and registers it with the in-memory session manager. Closing the terminal terminates the process and releases its resources.

## Session Persistence

Treq stores agent session metadata such as the session name and model in the repository's local database. The live process and terminal scrollback stay in memory. Closing Treq ends the process, and reopening the app does not restore its terminal output.

## Learn More

- [Creating Terminal Sessions Guide](/docs/tutorials/creating-terminal-sessions)
- [Keyboard Shortcuts](/docs/reference/keyboard-shortcuts)
