rec
A CLI tool to record, replay, and export terminal sessions.
rec captures every command you run in a shell session, then lets you replay them with safety controls or export them to scripts, CI/CD configs, and documentation - turning your terminal workflow into reusable artifacts.
Quick Install
Pre-built binaries are available for Linux (x86_64, aarch64) and macOS (x86_64, Apple Silicon) on the releases page.
Quick Start
# 1. Set up shell hooks (add to your .bashrc, .zshrc, or config.fish)
# 2. Record a session
# 3. Replay it
# 4. Export to a reusable format
Features
Recording
rec uses native shell hooks to transparently capture every command, its working directory, exit code, and timing -- with zero overhead when not recording.
- Bash, Zsh, and Fish support with native hook integration
- Crash-safe NDJSON storage with per-command fsync
- Automatic recovery of sessions from crashed processes
- Named sessions with auto-generated names as fallback
Replay
Re-execute recorded sessions with a multi-layered safety system that prevents dangerous commands from causing harm.
Safety presets detect destructive commands across three tiers:
- Minimal --
rm -rf /,mkfs,dd, fork bombs - Moderate -- adds
chmod -R 777,DROP TABLE,docker system prune,shutdown,kill -9 - Strict -- adds
sudo,curl | sh,pip install,apt remove
Custom patterns can be added via configuration.
Export
Convert recorded sessions into 7 reusable formats:
| Format | Command | Produces |
|---|---|---|
| Bash | rec export -f bash |
Shell script with set -euo pipefail |
| Makefile | rec export -f makefile |
GNU Makefile with phony targets |
| Markdown | rec export -f markdown |
Documentation with code blocks |
| GitHub Actions | rec export -f github-action |
.github/workflows/*.yml |
| GitLab CI | rec export -f gitlab-ci |
.gitlab-ci.yml pipeline config |
| Dockerfile | rec export -f dockerfile |
Multi-step Dockerfile |
| CircleCI | rec export -f circleci |
.circleci/config.yml |
Smart Parameterization
Auto-detect environment-specific values and replace them with variables for portable output:
# Detects /home/alice -> $HOME_DIR, alice -> $USERNAME, hostname -> $HOSTNAME
# Set explicit parameter values
Use {{VAR_NAME}} placeholders directly in your commands during recording for manual parameterization.
Session Management
Import
Import existing shell history or scripts into rec sessions:
Supported formats: Bash scripts, Bash history, Zsh history (plain and extended), Fish history.
Diagnostics
Configuration
rec uses a layered TOML config at ~/.config/rec/config.toml:
[]
= "vim" # or $EDITOR
= "bash" # or $SHELL
[]
= "auto" # auto | always | never
= "unicode" # unicode | ascii
= "normal" # quiet | normal | verbose
[]
= "moderate" # strict | moderate | minimal
= ["kubectl delete", "terraform destroy"]
Environment Variables
| Variable | Description |
|---|---|
REC_VERBOSE |
Enable verbose output |
REC_QUIET |
Suppress non-essential output |
NO_COLOR |
Disable colored output (no-color.org) |
REC_EDITOR |
Override editor for rec edit and rec config --edit |
REC_SHELL |
Override detected shell |
REC_STORAGE_PATH |
Override session storage directory |
Shell Completions
# Generate at runtime
Generate completions for your shell and add to your shell configuration.
How It Works
rec init bashoutputs shell hooks that registerpreexec/precmdfunctions (Bash uses a bundled bash-preexec library; Zsh and Fish use native hooks)rec startcreates a session file and sets a recording lock with PID-based ownership- Shell hooks call
rec _hook preexec <cmd>before each command andrec _hook precmd <exit_code>after, appending NDJSON lines to the session file with fsync rec stopwrites a footer line and releases the lock- Sessions are stored as NDJSON at
~/.local/share/rec/sessions/-- one JSON object per line, crash-recoverable by design
License
Licensed under the MIT License.