# LibTmux\Enter-TmuxSession

- **Package:** LibTmux
- **Language:** PowerShell
- **Kind:** function
- **Source:** https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/src/LibTmux.PowerShell/EnterTmuxSessionCommand.cs#L8
- **Page:** https://libtmux.org/en/powershell/latest/reference/libtmux-enter-tmuxsession/

```
Enter-TmuxSession
    [-Session] <LibTmux.Session>
    [-ReadOnly]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]
```

Attach your foreground terminal to a selected session.

Attach a foreground tmux client using the endpoint and daemon generation of
the supplied native [`Session`](/en/csharp/latest/reference/libtmux-session/). The command waits until you detach, then returns
one refreshed [`Session`](/en/csharp/latest/reference/libtmux-session/). It does not detach other clients or choose a session
from ambient tmux variables.

Run it in a foreground terminal outside tmux. Redirected stdin and a nonempty
TMUX environment variable are rejected. These checks do not establish whether
an arbitrary PowerShell host or in-process background runspace owns the terminal.
Background jobs, remoting and custom hosts are not a supported attachment workflow.

ReadOnly prevents the client from sending pane input. Detach normally with your
tmux detach key binding. Stopping the PowerShell pipeline cancels its owned
attachment client; the borrowed session, daemon and other clients remain.
Cancellation does not undo a workspace already applied.

The session's connection [`CommandTimeout`](/en/csharp/latest/reference/libtmux-serverconnectionoptions-commandtimeout/) bounds the entire attachment. Its
initial acknowledgement has a five-second ceiling, shortened by [`CommandTimeout`](/en/csharp/latest/reference/libtmux-serverconnectionoptions-commandtimeout/);
a null [`CommandTimeout`](/en/csharp/latest/reference/libtmux-serverconnectionoptions-commandtimeout/) permits an indefinite interactive lifetime afterward.
A successful detach can still report a native readback failure if the session
or daemon disappears before the refreshed handle is captured.

[`WhatIf`](/en/powershell/latest/reference/libtmux-enter-tmuxsession/#LibTmux%5CEnter-TmuxSession.parameter.WhatIf) emits no success object and performs no attachment, refresh or host
application notification. Each actual input session is entered sequentially;
prefer selecting exactly one session before invoking the command.

### Notes

Requires PowerShell 7.4 or later on Linux or macOS with native tmux and a foreground terminal.
[`Tmux.SessionAttachFailed`](https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/docs/reference/LibTmux/Enter-TmuxSession.md#notes) retains the native exception and input session. When
attachment and host restoration both fail, both causes are retained together.

## Command details

- **Command type:** [`cmdlet`](/en/powershell/latest/reference/glossary/#cmdlet)
- **Confirmation:** Supports `-WhatIf` and `-Confirm`; confirm impact: Medium.
- **Positional binding:** Enabled.
- **Pipeline inputs:** `LibTmux.Session`: A native session selected from an explicit endpoint.
- **Outputs:** `LibTmux.Session`

Related APIs:

- [`Get-TmuxSession`](/en/powershell/latest/reference/libtmux-get-tmuxsession/)
- [`Invoke-TmuxWorkspace`](/en/powershell/latest/workspace/reference/libtmux-workspace-invoke-tmuxworkspace/)

## Examples

Example 1

Preview attachment to a previously selected native session. No terminal is
required for the preview.

[Source example](https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/docs/reference/LibTmux/Enter-TmuxSession.md).

```powershell
$session | LibTmux\Enter-TmuxSession -WhatIf
```

Example 2

Observe the selected session from your foreground terminal without sending pane
input. Detach to receive the refreshed Session.

[Source example](https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/docs/reference/LibTmux/Enter-TmuxSession.md).

```powershell
$session | LibTmux\Enter-TmuxSession -ReadOnly
```

## Parameters

- `Session` (`LibTmux.Session`): The native session to enter. Its endpoint and generation are retained.
  Required. Position 0. Accepts pipeline input by value. [`ValidateNotNull()`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatenotnullattribute?view=powershellsdk-7.4.0).
- `ReadOnly` (`System.Management.Automation.SwitchParameter`): Attach without permitting pane input.
  Optional. Named parameter. Switch parameter. Does not accept pipeline input.
- `Verbose` (`System.Management.Automation.SwitchParameter`): Display verbose messages produced by this command.
  Optional. Named parameter. Switch parameter. Common parameter. Does not accept pipeline input. Aliases: `vb`.
- `Debug` (`System.Management.Automation.SwitchParameter`): Display debug messages produced by this command.
  Optional. Named parameter. Switch parameter. Common parameter. Does not accept pipeline input. Aliases: `db`.
- `ErrorAction` (`System.Management.Automation.ActionPreference`): Choose how this command responds to non-terminating errors.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `ea`.
- `WarningAction` (`System.Management.Automation.ActionPreference`): Choose how this command responds to warning messages.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `wa`.
- `InformationAction` (`System.Management.Automation.ActionPreference`): Choose how this command handles information messages.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `infa`.
- `ProgressAction` (`System.Management.Automation.ActionPreference`): Choose how this command handles progress updates.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `proga`.
- `ErrorVariable` (`System.String`): Store the command's error records in the named variable.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `ev`.
- `WarningVariable` (`System.String`): Store the command's warning records in the named variable.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `wv`.
- `InformationVariable` (`System.String`): Store the command's information records in the named variable.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `iv`.
- `OutVariable` (`System.String`): Save output in the named variable while passing it down the pipeline.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `ov`.
- `OutBuffer` (`System.Int32`): Buffer output before passing it to the next pipeline command.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `ob`.
- `PipelineVariable` (`System.String`): Make the most recent output object available through a named variable within the pipeline.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `pv`.
- `WhatIf` (`System.Management.Automation.SwitchParameter`): Describe the attachment without executing it.
  Optional. Named parameter. Switch parameter. Does not accept pipeline input. Aliases: `wi`.
- `Confirm` (`System.Management.Automation.SwitchParameter`): Prompt before attaching the terminal.
  Optional. Named parameter. Switch parameter. Does not accept pipeline input. Aliases: `cf`.

## Returns

`LibTmux.Session`: One refreshed native session after successful detach. Empty input emits nothing.
