# LibTmux\New-TmuxSession

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

```
New-TmuxSession
    [-Server] <LibTmux.Server>
    [-Name <System.String>]
    [-WindowName <System.String>]
    [-StartDirectory <System.String>]
    [-Command <System.String>]
    [-Width <System.Nullable[System.Int32]>]
    [-Height <System.Nullable[System.Int32]>]
    [-Environment <System.Collections.IDictionary>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]
```

[`Create`](/en/csharp/latest/reference/libtmux-tmuxcommand-create/) a detached session on an explicit server.

[`Create`](/en/csharp/latest/reference/libtmux-tmuxcommand-create/) a session and its initial window and pane, then return the captured
native [`LibTmux.Session`](/en/csharp/latest/reference/libtmux-session/). The [`Server`](/en/csharp/latest/reference/libtmux-server/) parameter accepts a native endpoint handle
directly or through the pipeline. The core can start the daemon when that
endpoint has no server. Existing session names remain errors; the command does
not replace or attach to an existing session.

### Notes

[`WhatIf`](/en/powershell/latest/reference/libtmux-new-tmuxsession/#LibTmux%5CNew-TmuxSession.parameter.WhatIf) reports the intended endpoint without discovery, daemon startup or
dispatch, and returns no created object. Confirmation precedes the core
operation. Success does not transfer ownership of the daemon to the module or
arrange automatic cleanup. Cancellation can occur after a session was created;
it is not rollback and the module does not retry. Per-owner errors use
[`Tmux.SessionCreateFailed`](https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/docs/reference/LibTmux/New-TmuxSession.md#notes) and retain the core exception and failed server.
[`ErrorAction`](/en/powershell/latest/reference/libtmux-new-tmuxsession/#LibTmux%5CNew-TmuxSession.parameter.ErrorAction) Continue allows later owners to run.

## 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.Server`: Native pipeline type for this command.
- **Outputs:** `LibTmux.Session`

Related APIs:

- [Task guide](https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/docs/create.md)

## Examples

Example 1

Create a detached session on the server identified by the absolute $SocketPath.
Choose an endpoint you control; the created session remains running until you
remove it.

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

```powershell
$options = @{
    Name = 'help-session'
    WindowName = 'work'
    Command = 'exec /bin/sh'
}
LibTmux\New-TmuxServer -SocketPath $SocketPath |
    LibTmux\New-TmuxSession @options
```

## Parameters

- `Server` (`LibTmux.Server`): Native server endpoint in which to create the session. This is the only
pipeline-bound parameter; binding by an object's Server property is not
supported.
  Required. Position 0. Accepts pipeline input by value. [`ValidateNotNull()`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatenotnullattribute?view=powershellsdk-7.4.0).
- `Name` (`System.String`): Session name. Omit it to let tmux choose. An existing name remains an error;
tmux's name and format rules apply.
  Optional. Named parameter. Does not accept pipeline input. [`ValidateNotNullOrEmpty()`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatenotnulloremptyattribute?view=powershellsdk-7.4.0).
- `WindowName` (`System.String`): Name of the initial window. Omit it to retain tmux's default naming behavior.
  Optional. Named parameter. Does not accept pipeline input. [`ValidateNotNullOrEmpty()`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatenotnulloremptyattribute?view=powershellsdk-7.4.0).
- `StartDirectory` (`System.String`): Working directory for the new pane. Use an absolute filesystem path for
predictable behavior. The core expands ~ and ~/; this cmdlet does not resolve
PowerShell provider paths or change the host's current directory.
  Optional. Named parameter. Does not accept pipeline input. [`ValidateNotNullOrEmpty()`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatenotnulloremptyattribute?view=powershellsdk-7.4.0).
- `Command` (`System.String`): One shell-command string for the new pane. tmux interprets shell syntax in this
string; it is not an argument array. Omit it to use the configured default
command or shell.
  Optional. Named parameter. Does not accept pipeline input. [`ValidateNotNullOrEmpty()`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatenotnulloremptyattribute?view=powershellsdk-7.4.0).
- `Width` (`System.Nullable[System.Int32]`): Initial width in terminal cells, at least 1. Omit it to use tmux's default
dimensions.
  Optional. Named parameter. Does not accept pipeline input. [`ValidateRange(1, 2147483647)`](https://learn.microsoft.com/dotnet/api/system.management.automation.validaterangeattribute?view=powershellsdk-7.4.0).
- `Height` (`System.Nullable[System.Int32]`): Initial height in terminal cells, at least 1. Omit it to use tmux's default
dimensions.
  Optional. Named parameter. Does not accept pipeline input. [`ValidateRange(1, 2147483647)`](https://learn.microsoft.com/dotnet/api/system.management.automation.validaterangeattribute?view=powershellsdk-7.4.0).
- `Environment` (`System.Collections.IDictionary`): A dictionary with string names and string values. Names must be nonempty and
contain neither '=' nor NUL (U+0000). Values may be empty but must not contain
NUL. Null or non-string entries are rejected before confirmation or dispatch.
Entries are copied for this invocation and do not change the PowerShell host
environment.
  Optional. Named parameter. Does not accept pipeline input. [`ValidateNotNull()`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatenotnullattribute?view=powershellsdk-7.4.0).
- `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`): Runs the command in a mode that only reports what would happen without performing the actions.
  Optional. Named parameter. Switch parameter. Does not accept pipeline input. Aliases: `wi`.
- `Confirm` (`System.Management.Automation.SwitchParameter`): Prompts you for confirmation before running the cmdlet.
  Optional. Named parameter. Switch parameter. Does not accept pipeline input. Aliases: `cf`.

## Returns

`LibTmux.Session`: Captured native object for the created resource.
