# LibTmux::Attachment

- **Package:** LibTmux
- **Language:** Raku
- **Kind:** class
- **Source:** https://github.com/libtmux/libtmux-raku/blob/e76160bcce6e03976d49424da15b7c31afb2c68e/lib/LibTmux/Attachment.rakumod#L4
- **Page:** https://libtmux.org/en/raku/latest/reference/libtmux-attachment/

# Explicit interactive terminal ownership

spawn binds stdin and stdout to the supplied open terminal handle. It never
inherits the calling program's terminal implicitly. The caller owns that handle
and its terminal output; Attachment owns the child and bounded binary stderr.
close stops and reaps only that child, leaves the handle open, and does not stop
the daemon or other clients. Cancellation applies to startup, not the later
interactive lifetime. Use close to end that lifetime.

spawn proves OS process creation only. state starts as AttachmentPending;
inspect-client makes one explicit listing and records AttachmentAttached when
the owned PID is present. Child exit independently records AttachmentExited.
There is no polling loop or implicit readiness claim. An event from a separately
owned control connection may supply application-specific readiness evidence.

The initial session read checks Linux daemon identity, and the attach command
runs in a PID/start-time fence. The Engine's documented same-PID/same-second
replacement and normal builtin-dispatch assumptions also apply here. An exit
Result describes the tmux client process, not the lifetime of its session.

## Members

### Other members

- [`AttachmentState`](/en/raku/latest/reference/libtmux-attachment-attachmentstate/) (enum): State established by process completion or the most recent explicit inspection.
- [`clone`](/en/raku/latest/reference/libtmux-attachment-clone/) (method): Refuse copying an owner, which would duplicate cleanup authority over one child.
- [`close`](/en/raku/latest/reference/libtmux-attachment-close/) (method): Terminate and reap only this child. The caller's terminal handle stays open.
- [`close-async`](/en/raku/latest/reference/libtmux-attachment-close-async/) (method): Share idempotent child cleanup; failure to reap breaks the returned Promise.
- [`endpoint`](/en/raku/latest/reference/libtmux-attachment-endpoint/) (property): Socket and executable configuration used for this child and explicit inspections.
- [`incarnation`](/en/raku/latest/reference/libtmux-attachment-incarnation/) (property): Daemon identity captured before attachment; a replacement daemon is rejected.
- [`inspect-client`](/en/raku/latest/reference/libtmux-attachment-inspect-client/) (method): Perform one explicit listing. Nil means no matching attached client was observed.
- [`max-stderr-bytes`](/en/raku/latest/reference/libtmux-attachment-max-stderr-bytes/) (property): Retained stderr byte limit; exceeding it terminates the child and fails when-exited.
- [`new`](/en/raku/latest/reference/libtmux-attachment-new/) (method): Construction requires spawn so an unstarted process owner cannot escape.
- [`pid`](/en/raku/latest/reference/libtmux-attachment-pid/) (method): Owned OS child identity; a nonzero PID does not establish attachment readiness.
- [`session`](/en/raku/latest/reference/libtmux-attachment-session/) (property): Initial session ID; later interactive switching does not change this value.
- [`spawn`](/en/raku/latest/reference/libtmux-attachment-spawn/) (method): Spawn a tmux client on a supplied terminal. This does not prove attachment.
- [`state`](/en/raku/latest/reference/libtmux-attachment-state/) (method): Last explicit attachment observation, or the independently observed process exit.
- [`when-exited`](/en/raku/latest/reference/libtmux-attachment-when-exited/) (method): Resolve after the child exits and stderr is drained, preserving its exit status.
