pty

A minimal, dependency-free Go library for opening and managing Unix pseudo-terminals.

Library
Go
vv1.1.24
2,082stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
54/100Fair
Development Activity20
Maintenance24
Community72
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
69/100Good
Architecture78
Code Quality84
Innovation58
Learning Curve55

pty gives Go programs direct access to Unix pseudo-terminals, letting a process spawn a child command — a shell, an interactive CLI, anything — attached to a real tty rather than a plain pipe. This matters whenever code needs to observe or drive a program that changes behavior based on whether it thinks it’s talking to a terminal: colored output, progress bars, password prompts, or full-screen TUIs like vim and top.

The package wraps the platform-specific ioctl calls needed to open a ptmx/pts pair, start a command attached to it via os/exec, and keep the terminal window size in sync via SIGWINCH forwarding. It has zero external dependencies and ships native implementations for Linux, Darwin, the BSDs, Solaris, and z/OS, falling back to a clear ErrUnsupported on Windows and other unsupported platforms.

What You Get

  • A single Open() call that returns matching pty/tty *os.File pairs on Linux, Darwin, the BSDs, Solaris, and z/OS.
  • Start / StartWithSize / StartWithAttrs helpers that wire an *exec.Cmd’s stdin/stdout/stderr to the tty side and set session/controlling-terminal flags for you.
  • Window-size helpers (Getsize, GetsizeFull, Setsize, InheritSize) for keeping a pty’s dimensions in sync with a real terminal via SIGWINCH.
  • Zero third-party dependencies — only Go’s standard library and direct syscalls.

Common Use Cases

  • Terminal multiplexers and session managers — tools like tmux-style wrappers or SSH session proxies use pty to give a shell a real controlling terminal so job control and signals work.
  • Recording and replaying terminal sessions — CLI recording tools attach a pty to a child process to capture exactly what would have appeared on a real terminal, including cursor codes.
  • Testing CLI tools that behave differently under a tty — test harnesses spawn the binary under test through pty.Start so it takes the interactive code path instead of falling back to plain-pipe behavior.
  • Web-based terminal emulators — servers that expose a shell over a websocket use pty to run the shell process and pipe pty output to/from the browser terminal.

Under The Hood

Architecture pty is organized around a single narrow contract: each supported platform implements an unexported open() (pty, tty *os.File, err error) function behind a Go build tag, and the public API in doc.go (Open()) and start.go/run.go (Start, StartWithSize, StartWithAttrs) is entirely platform-agnostic on top of it. Platform files (pty_linux.go, pty_darwin.go, pty_freebsd.go, pty_dragonfly.go, pty_netbsd.go, pty_openbsd.go, pty_solaris.go, pty_zos.go, pty_unsupported.go) each implement the ptmx-open/grantpt/unlockpt/ptsname sequence using the OS’s own ioctls, while shared cross-cutting concerns — starting an *exec.Cmd on the tty side, propagating window size via Setsize/Getsize/InheritSize, and issuing raw ioctls through a SyscallConn-based, deadline-aware wrapper in ioctl.go — live in OS-independent files. There’s no dependency injection or interface layer because none is needed at this scope: it is a leaf utility with no internal state to swap, and changing the shared open() contract would require updating every platform file in lockstep, which is the expected cost of an OS-abstraction library this size.

Tech Stack The module (go.mod) declares zero external dependencies and only requires Go 1.18, doing everything through the standard library’s os, os/exec, and syscall packages plus raw ioctl numbers defined per platform — there is no reliance on golang.org/x/sys or any third-party wrapper. A small amount of platform-specific Assembly (asm_solaris_amd64.s) backs Solaris support, and a Dockerfile.golang plus test_crosscompile.sh exist purely to verify the package builds across every supported GOOS/GOARCH combination. Linting is unusually thorough for a package this size: .golangci.yml runs an extensive, explicitly curated set of golangci-lint checks, with targeted //nolint annotations documenting each deliberate suppression rather than disabling rules wholesale.

Code Quality Test coverage is real and platform-aware: doc_test.go and io_test.go exercise Open/Start round-trips, name resolution, window-size get/set, read deadlines, and the trickier case of Close() interrupting an in-flight Read() — using t.Parallel() and small custom assert/noError helpers rather than a heavyweight test framework. CI (.github/workflows/test.yml) runs the suite across ubuntu-latest and macos-latest against both the current and previous stable Go release, plus a deliberate sanity check on Go 1.6, and a separate crosscompile workflow builds the package for every supported target OS/architecture on every push. Error handling is explicit throughout — every syscall/ioctl result is checked and wrapped, and defer-based cleanup is annotated “Best effort” where errors are intentionally swallowed rather than silently ignored.

API Design pty doesn’t introduce a novel technique — pty allocation via ptmx/grantpt/unlockpt is the standard Unix mechanism, and the package’s value is in packaging that mechanism behind a minimal, dependency-free, cross-platform Go API rather than any new algorithm. The developer experience is deliberately small: Open() and Start() cover the common case in one call each, StartWithAttrs exists only for the rare case that needs to override SysProcAttr directly, and InheritSize is a two-line building block meant to be called from a SIGWINCH handler rather than a batteries-included resize manager. That minimalism, combined with zero dependencies and broad platform coverage, is why it has become a de facto pty implementation many higher-level Go terminal tools import rather than reimplement.

Used by 16 apps in this directory

Go
72%
GPL 3.0

1Panel

Devops · Hosting Control Panel · Monitoring

36,721

The only open-source VPS control panel with native AI agent runtime — deploy websites, Docker stacks, and local LLMs from one web interface.

View details
90
Repo Health
76
Technical
68
Dependency
Built with
Go72%
Vue28%
Updated 2 days ago
Go
85%
Apache 2.0

Argo Workflows

Devops · Data Engineering

16,943

The most popular Kubernetes-native workflow engine for orchestrating containerized DAGs, ML pipelines, CI/CD, and parallel batch jobs at scale.

View details
95
Repo Health
90
Technical
68
Dependency
Built with
Go85%
TypeScript11%
Updated yesterday
Swift
64%
GPL 3.0

cmux

Developer Tools · AI Development

26,594

A native, Ghostty-based macOS terminal with vertical tabs, agent-aware notifications, and a scriptable browser built for running many parallel AI coding agent sessions instead of juggling tmux panes.

View details
84
Repo Health
81
Technical
72
Dependency
Built with
Swift64%
Rust15%
Updated today
Go
75%
AGPL 3.0

Coder

Devops · Developer Tools · Code Editors

14,299

Self-hosted cloud development environments and AI coding agents — defined in Terraform, connected via WireGuard, automatically shut down when idle.

View details
93
Repo Health
90
Technical
69
Dependency
Built with
Go75%
TypeScript23%
Updated today
Go
59%
Apache 2.0

Cog

AI Development · Devops · Developer Tools

9,464

An open-source CLI that packages machine learning models into standard, production-ready Docker containers — no Dockerfile wrangling, no CUDA version hell.

View details
90
Repo Health
88
Technical
69
Dependency
Built with
Go59%
Rust17%
HTML13%
Updated 4 days ago
Go
49%
Other

Cosmos-Server

Security · Authentication

6,134

All-in-one self-hosted home server with SmartShield anti-DDoS, Nebula mesh VPN, automatic HTTPS, and a 250-app marketplace — all secured behind a unified auth layer.

View details
86
Repo Health
59
Technical
65
Dependency
Built with
Go49%
JavaScript48%
Updated yesterday
Go
97%
Apache 2.0

Docker (Moby)

Devops · Developer Tools

72,014

The open-source container engine at the heart of Docker — a modular toolkit of runtime, build, and networking components for assembling container-based systems.

View details
98
Repo Health
86
Technical
68
Dependency
Built with
Go97%
Updated yesterday
Go
51%
AGPL 3.0

Filestash

File Storage

14,560

A self-hosted file management platform that unifies access to S3, SFTP, SMB, FTP, WebDAV, NFS, Git, SharePoint, and 20+ other storage backends through a single extensible web interface.

View details
79
Repo Health
67
Technical
66
Dependency
Built with
Go51%
JavaScript35%
Updated 3 days ago
Go
58%
MIT

hoop

Security · Monitoring

805

A wire-protocol gateway that enforces data masking, command blocking, approval workflows, and full session recording for engineers and AI agents accessing production infrastructure.

View details
85
Repo Health
80
Technical
65
Dependency
Built with
Go58%
Clojure19%
JavaScript14%
Updated 2 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search