# Remove sessions, windows and panes

Source: https://libtmux.org/en/powershell/latest/guides/remove/

> Remove sessions, windows and panes: LibTmux documentation.

[`Remove-TmuxSession`](<https://libtmux.org/en/powershell/latest/reference/libtmux-remove-tmuxsession/>), [`Remove-TmuxWindow`](<https://libtmux.org/en/powershell/latest/reference/libtmux-remove-tmuxwindow/>) and [`Remove-TmuxPane`](<https://libtmux.org/en/powershell/latest/reference/libtmux-remove-tmuxpane/>) accept native
core handles directly or through the pipeline. Each removes its target and
emits no success output. Select the target using the
[explicit endpoint and read commands](https://libtmux.org/en/powershell/latest/guides/read/).

These commands have high confirmation impact. The default PowerShell
confirmation preference prompts before removal. Review the endpoint and ID
in that prompt; use `-Confirm:$false` when an unattended caller has already
chosen the target. `-WhatIf` describes the removal without contacting tmux:

<!-- example: remove.preview -->
```powershell
$session | Remove-TmuxSession -WhatIf
```

Remove an owned session after its work finishes:

<!-- example: remove.session -->
```powershell
$session | Remove-TmuxSession -Confirm:$false
```

An empty pipeline does nothing. A pipeline with several targets processes
them in input order. A successful removal emits no handles, Boolean values
or task objects, so `@($pane | Remove-TmuxPane -Confirm:$false)` is empty.
Captured fields on an old handle remain an observation of the removed
object; removal does not rewrite that snapshot.

## Linked windows and cascading removal

**Removing a window destroys the physical window, every pane in it, and all
its links in every session.** It does not merely unlink the placement through
which the window was selected. Repeated placements of that physical window
are removed together:

<!-- example: remove.window -->
```powershell
$window | Remove-TmuxWindow -Confirm:$false
```

To remove one session placement while preserving other links, use
[Remove-TmuxWindowLink](https://libtmux.org/en/powershell/latest/guides/placement/).

Removing a session destroys windows that are no longer linked elsewhere. A
window still linked to another session survives with its panes.

Removing the last pane destroys its window. Removing the last window from a
session also removes that session; tmux may exit when no sessions remain.
These commands do not give the module ownership of the daemon or arrange
cleanup for other resources.

<!-- example: remove.pane -->
```powershell
$pane | Remove-TmuxPane -Confirm:$false
```

## Errors and cancellation

Failures retain the native owner and original core exception in the PowerShell
error record. The stable error IDs are
[`Tmux.SessionRemoveFailed`][removetmuxsessioncommand],
[`Tmux.WindowRemoveFailed`][removetmuxwindowcommand] and
[`Tmux.PaneRemoveFailed`][removetmuxpanecommand]. Core exceptions retain their
available dispatch metadata. A missing target remains an error;
`-ErrorAction Continue` permits later pipeline targets to run, while
`-ErrorAction Stop` stops before the next target.

Handles belong to a specific endpoint and daemon generation. The core
rejects an old-generation handle after daemon replacement instead of resolving
the same numeric ID against the replacement. Removal is never retried.
Stopping the pipeline cancels the active client operation; a removal already
accepted by tmux is not rolled back.

The [installed removal test](https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/tests/Remove.Tests.ps1) checks previews,
zero-output pipelines, per-owner errors, linked-window destruction, session
sharing, last-pane cascades, isolated endpoints and real daemon replacement
on owned tmux servers.

[removetmuxsessioncommand]: https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/src/LibTmux.PowerShell/RemoveTmuxSessionCommand.cs
[removetmuxwindowcommand]: https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/src/LibTmux.PowerShell/RemoveTmuxWindowCommand.cs
[removetmuxpanecommand]: https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/src/LibTmux.PowerShell/RemoveTmuxPaneCommand.cs
