pty-architecture

Implement PTY-based multi-session terminal architecture with node-pty and NDJSON stream parsing.

11|2|Updated Feb 5, 2026
One-click install
npx skills add https://github.com/recca0120/code-quest --skill pty-architecture
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pty-architecture
Source: https://github.com/recca0120/code-quest/tree/main/.claude/skills/pty-architecture
Command: npx skills add https://github.com/recca0120/code-quest --skill pty-architecture

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill solves the challenge of implementing stable, multi-session terminal experiences that correctly render streamed ANSI output and keep sessions isolated from one another.

Core Features & Use Cases

  • Three-layer PTY terminal design: Connects a browser UI (xterm.js) to the server event/routing layer and then to a dedicated PTY-backed CLI layer for each session.
  • Production-ready PTY spawn configuration: Specifies TERM/ENV settings, terminal size, and working directory wiring to ensure correct colors, resizing behavior, and consistent runtime behavior.
  • Session robustness controls: Covers circular output buffering to prevent memory leaks, graceful shutdown to avoid zombies, and worktree isolation to prevent concurrent session conflicts.

Quick Start

Use the pty-architecture Skill to generate an implementation plan for a PTY-backed multi-session terminal that uses node-pty, stream parsing, and isolated per-session working directories.

Frequently Asked Questions about pty-architecture

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I build a PTY-based multi-session terminal architecture for web clients?

Build a PTY-based multi-session terminal by defining a three-layer browser-to-server-to-CLI pipeline. This separates the xterm.js UI, the server event routing layer, and a dedicated node-pty backed CLI layer for each session.

How does node-pty stream parsing work with NDJSON for terminal rendering?

NDJSON stream parsing works by delimiting each terminal output chunk as a separate JSON line. This allows the server to parse node-pty data streams incrementally and forward structured events to the browser for real-time terminal rendering.

What is the best way to prevent memory leaks when managing multiple PTY sessions?

Prevent memory leaks in multiple PTY sessions by implementing bounded circular output buffering. This caps the retained output size per session, preventing unbounded memory growth during heavy or long-running terminal operations.

How do I isolate working directories across concurrent terminal sessions using worktrees?

Isolate working directories by configuring per-session cwd and worktree isolation during PTY spawn. This ensures each concurrent terminal session operates within its own git worktree, preventing file conflicts.

Why does my node-pty spawned CLI lose ANSI colors and resizing behavior in the browser?

node-pty loses ANSI colors and resizing behavior when PTY spawn configuration omits correct TERM and ENV settings. Specifying terminal capabilities and dimensions during spawn ensures proper rendering and resize events.

Do I need graceful shutdown logic to avoid zombie processes with node-pty?

You need graceful shutdown logic to avoid zombie processes with node-pty. Implementing proper session termination ensures underlying CLI processes are killed cleanly when a browser disconnects or a session closes.