frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

Ask HN: How to Extract Shell Commands from Raw PTY Sessions? (Rewindtty)

2•debba•1d ago
Project URL: https://github.com/debba/rewindtty

I've been working on rewindtty, a lightweight terminal session recorder and replayer written in C. It works like script/scriptreplay, but outputs structured JSON and includes a browser-based player for replaying terminal sessions with timing, scrubbing, bookmarks, and more.

Until now, I was recording sessions command-by-command, capturing each shell command and its output separately. That made it easy to analyze sessions and index them by command.

However, I just introduced a new interactive mode, which behaves more like traditional script: it records raw terminal I/O in real-time via a PTY, capturing every character typed or displayed, including control sequences.

This is great for realism and full session fidelity (e.g. interactive tools like htop, vim, REPLs), but it makes command detection much harder — I'm no longer intercepting input at the shell level.

My question is: how can I extract actual commands from this raw PTY stream?

I'm aware it's tricky, but I'm wondering:

    Has anyone tried parsing the ANSI stream to reconstruct command boundaries?

    Is it possible to hook into the shell (bash, zsh, etc.) in real-time to intercept commands?

    Are there shell options or audit features that can be leveraged in parallel to raw capture?

    Any prior art or libraries I should look at?
I'd love to hear how others have approached this — either for recording, analyzing, or replaying shell sessions. Any insights or directions would be super helpful.

Comments

ksherlock•1d ago
For bash, you can use `trap [code] DEBUG` to run your code before the command executes. $BASH_COMMAND should be the set to the command that's going to run.

Alternatively, look at the $PROMPT_COMMAND which runs before printing the $PS1 prompt (so maybe you could check `history 1` to get the command afterwards)

debba•14h ago
I will check thanks, need to find a solution common for every shell.

Ask HN: Have you ever regretted open-sourcing something?

230•paulwilsonn•4d ago•330 comments

Tell HN: Anthropic expires paid credits after a year

259•maytc•1d ago•119 comments

Ask HN: What trick of the trade took you too long to learn?

345•unsupp0rted•1d ago•608 comments

Tell HN: I underestimated how lonely building solo can be

111•paulwilsonn•4d ago•78 comments

Ask HN: What are your eye fatigue symptoms? What has worked to heal your eyes?

3•jMyles•2h ago•4 comments

OpenAI OSS Model Policy Contains Directions on Rokos Basilisk

3•busssard•3h ago•0 comments

Peak Flow – An AI-Powered Task Planner That Aligns with Your Daily Energy Levels

2•rashempandit48•5h ago•0 comments

Ask HN: Why Did Mercurial Die?:(

28•sergiotapia•20h ago•29 comments

Ask HN: What happened to John Carmack's AGI company?

10•upupupandaway•9h ago•4 comments

Ask HN: Who wants to be hired? (August 2025)

113•whoishiring•4d ago•339 comments

Ask HN: Modular's Max Momentum

2•dcreater•11h ago•0 comments

I launched 17 side projects. Result? I'm rich in expired domains

365•cesargstn•6d ago•258 comments

Ask HN: Who is hiring? (August 2025)

230•whoishiring•4d ago•356 comments

Ask HN: Setup for Local LLM Backups?

3•andy99•14h ago•1 comments

Rethinking devtools: Escaping the Cloud and SaaS trap

3•kiselitza•5h ago•5 comments

Ask HN: What change enabled you to consistently finish your side projects?

44•pillefitz•1d ago•35 comments

Ask HN: Is AI so environmentally damaging that we shouldn't use it?

7•rrosen326•16h ago•14 comments

Ask HN: Why is it called "Vibe Coding"?

16•giantg2•1d ago•17 comments

What's the latest on NAD+ and longevity in 2025?

6•Yoonreterna•1d ago•0 comments

Ask HN: What's your biggest success–or failure–using AI?

3•zyruh•20h ago•3 comments

Ask HN: What are your best practices for Claude Code?

35•hubraumhugo•2d ago•4 comments

People can exploit your social media pictures and so I've made a tool

6•Gravyt1•1d ago•4 comments

Ask HN: Feedback on my privacy-first resume builder (no login, no tracking)

3•rashidrashi•1d ago•0 comments

Ask HN: What if I fail to make it?

9•nextweeks•1d ago•18 comments

Ask HN: If this was your last project, what would you build?

4•ff12wq111•1d ago•7 comments

Open Source and OpenAI's Return

5•ricecat•12h ago•1 comments

Ask HN: What are you working on? (July 2025)

260•david927•1w ago•860 comments

Claude Code weekly rate limits

608•thebestmoshe•1w ago•703 comments

Nova: A New Web Framework for Erlang

68•taure•5d ago•30 comments

Companies Tried to Save Money with AI Now Spending a Fortune to Fix Its Mistakes

11•laurex•1d ago•2 comments