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
# With interactive TUI (optional)
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
Interactive TUI
rec includes an optional terminal user interface for visual session management:
# Install with TUI support
# Launch the TUI
Features:
- Browse and filter sessions with keyboard navigation
- View session details and command history
- Interactive replay with output display
- Export wizard with format selection
- Delete sessions with confirmation modal
Keybindings:
| Key | Action |
|---|---|
j/k or ^/v |
Navigate up/down |
Enter |
Select / Confirm |
e |
Export selected session |
r |
Replay selected session |
d |
Delete selected session |
/ |
Filter sessions |
? |
Toggle help panel |
q |
Quit / Back |
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
Troubleshooting
Commands not being recorded
Symptom: rec stop shows "0 commands" even though you ran commands.
Cause: Shell hooks are not loaded or REC_RECORDING environment variable is not set.
Solution:
- Make sure you've added the init line to your shell rc file:
# ~/.bashrc, ~/.zshrc, or ~/.config/fish/config.fish - Restart your shell or run
source ~/.bashrc(or equivalent) - Verify hooks are loaded: the
reccommand should be a shell function, not just the binary
Recording indicator not showing
Symptom: No red ● indicator in prompt during recording.
Solution: The prompt indicator requires the shell hooks to be loaded. If you're using a custom prompt theme (oh-my-zsh, starship, etc.), it may override the prompt modification. You can:
- Manually add
$(__rec_prompt_indicator)to your prompt - Or set
REC_NO_PROMPT=1to disable the indicator
Permission denied errors
Symptom: Errors about unable to write to session files.
Solution: Check permissions on the storage directory:
# Should be owned by your user with write permissions
Shell hooks interfering with other tools
Symptom: Conflicts with other preexec/precmd hooks or shell plugins.
Solution: Load rec init after other shell plugins in your rc file. The hooks are designed to coexist with other tools, but load order can matter.
Run diagnostics
When in doubt, run the built-in diagnostic tool:
This checks 9 common issues including hook installation, storage permissions, and configuration validity.
License
Licensed under the MIT License.