[PR #723] [CLOSED] Add support for attaching to existing shell sessions #1212

Closed
opened 2026-03-15 11:24:42 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/asciinema/asciinema/pull/723
Author: @usman-heracles
Created: 2/7/2026
Status: Closed

Base: developHead: feature/attach-existing-pty


📝 Commits (1)

  • 7728ec7 Add support for attaching to existing shell sessions

📊 Changes

5 files changed (+309 additions, -36 deletions)

View changed files

📝 src/cli.rs (+77 -0)
📝 src/cmd/session.rs (+24 -1)
📝 src/main.rs (+4 -0)
📝 src/pty.rs (+152 -8)
📝 src/session.rs (+52 -27)

📄 Description

Summary

Adds the ability to record or stream an already-running shell session instead of always spawning a new one. This is implemented via two new CLI options:

  • --pty <PATH> - Attach directly to a PTY device (e.g., /dev/pts/5 on Linux or /dev/ttys005 on macOS)
  • --pid <PID> - Resolve a process ID to its controlling PTY and attach to it

Use Cases

  • Record a long-running shell session that was started before asciinema
  • Capture terminal output from a process you're already interacting with
  • Non-intrusively record/stream a session without changing the user's workflow

Usage Examples

# Find your shell's PTY
tty
# /dev/ttys005

# In another terminal, attach and record
asciinema rec --pty /dev/ttys005 output.cast

# Or use the PID directly
asciinema rec --pid 12345 output.cast

Implementation Details

  • When attached, asciinema captures output only (read-only mode)
  • The original shell continues running normally
  • Press Ctrl+C to stop recording; the shell is not affected
  • Works with rec, stream, and session commands

Test plan

  • Verify --pty option works with Linux PTY paths
  • Verify --pty option works with macOS PTY paths
  • Verify --pid option resolves to correct PTY on Linux
  • Verify --pid option resolves to correct PTY on macOS
  • Verify recording captures output correctly
  • Verify Ctrl+C stops recording without affecting the shell
  • Verify conflicting options (--pty with --command) are rejected

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/asciinema/asciinema/pull/723 **Author:** [@usman-heracles](https://github.com/usman-heracles) **Created:** 2/7/2026 **Status:** ❌ Closed **Base:** `develop` ← **Head:** `feature/attach-existing-pty` --- ### 📝 Commits (1) - [`7728ec7`](https://github.com/asciinema/asciinema/commit/7728ec7d71393e457304e100297f4cb826d309c2) Add support for attaching to existing shell sessions ### 📊 Changes **5 files changed** (+309 additions, -36 deletions) <details> <summary>View changed files</summary> 📝 `src/cli.rs` (+77 -0) 📝 `src/cmd/session.rs` (+24 -1) 📝 `src/main.rs` (+4 -0) 📝 `src/pty.rs` (+152 -8) 📝 `src/session.rs` (+52 -27) </details> ### 📄 Description ## Summary Adds the ability to record or stream an already-running shell session instead of always spawning a new one. This is implemented via two new CLI options: - `--pty <PATH>` - Attach directly to a PTY device (e.g., `/dev/pts/5` on Linux or `/dev/ttys005` on macOS) - `--pid <PID>` - Resolve a process ID to its controlling PTY and attach to it ## Use Cases - Record a long-running shell session that was started before asciinema - Capture terminal output from a process you're already interacting with - Non-intrusively record/stream a session without changing the user's workflow ## Usage Examples ```bash # Find your shell's PTY tty # /dev/ttys005 # In another terminal, attach and record asciinema rec --pty /dev/ttys005 output.cast # Or use the PID directly asciinema rec --pid 12345 output.cast ``` ## Implementation Details - When attached, asciinema captures output only (read-only mode) - The original shell continues running normally - Press Ctrl+C to stop recording; the shell is not affected - Works with `rec`, `stream`, and `session` commands ## Test plan - [ ] Verify `--pty` option works with Linux PTY paths - [ ] Verify `--pty` option works with macOS PTY paths - [ ] Verify `--pid` option resolves to correct PTY on Linux - [ ] Verify `--pid` option resolves to correct PTY on macOS - [ ] Verify recording captures output correctly - [ ] Verify Ctrl+C stops recording without affecting the shell - [ ] Verify conflicting options (--pty with --command) are rejected 🤖 Generated with [Claude Code](https://claude.ai/code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-15 11:24:42 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/asciinema#1212
No description provided.