DEV Community

Andrea Debernardi
Andrea Debernardi

Posted on • Originally published at github.com

I built rewindtty: a C tool to record and replay terminal sessions as JSON logs (like a black box for your CLI)

rewindtty

Hey folks! 👋

Over the past few weeks, I’ve been working on a little tool in C called rewindtty — it's like a black box for your terminal.

The idea is simple:

rewindtty record: Launches a shell (or any program), records all your inputs and outputs to a JSON log.

rewindtty replay: Replays that session step-by-step in a terminal-like environment.

Here’s an example of what the recorded JSON looks like:

{
  "timestamp": "2024-07-28T14:01:03Z",
  "command": "ls -la",
  "output": "total 4\n-rw-r--r-- file.txt\n",
  "stderr": ""
}
Enter fullscreen mode Exit fullscreen mode

Why?

I wanted a dead-simple way to:

-Capture what really happened in a CLI session, without overengineering.
-Debug or share reproducible steps with colleagues (like "here’s exactly what I typed and what I got").

  • Build a foundation for visual or animated terminal playback (think GIFs or asciinema-style exports).
  • How it works

Under the hood:

  • Uses fork() to launch a subprocess in a pseudo-terminal.
  • Intercepts both stdin and stdout/stderr, recording them with precise timestamps.
  • Clean JSON output makes it easy to transform, diff, analyze, or visualize.

Cool ideas I’m playing with next:

  • --timing flag to replay with realistic delays
  • Export to .cast format (asciinema)
  • GIF or SVG animations using svg-term
  • Auto-record hooks for Git or critical scripts
  • Comparing two sessions for debugging

Why not use asciinema?

Great question! I love asciinema, but:

  • I wanted full control over the data format (and stderr!)
  • JSON logs are easier to post-process for my use case
  • I wanted to build it in C for fun and for low-level control

Project URL

Top comments (0)