# LibTmux.new_session

- **Module:** LibTmux
- **Package:** LibTmux
- **Language:** Julia
- **Kind:** function
- **Source:** https://github.com/libtmux/libtmux-julia/blob/f3da513be1225d36d5854cd8db5972c01857578e/src/operations.jl#L152
- **Page:** https://libtmux.org/en/julia/latest/reference/libtmux-new_session/

```
new_session(
    connection::LibTmux.ControlConnection;
    name,
    command,
    shell_command,
    start_directory,
    environment,
    kwargs...
)

new_session(
    server::LibTmux.Server;
    name,
    command,
    shell_command,
    start_directory,
    environment,
    kwargs...
)
```

## Methods

### `new_session` (overload 1)

```julia
new_session(
    connection::LibTmux.ControlConnection;
    name,
    command,
    shell_command,
    start_directory,
    environment,
    kwargs...
)
```

[Source](https://github.com/libtmux/libtmux-julia/blob/f3da513be1225d36d5854cd8db5972c01857578e/src/control_topology.jl#L26).

Create a detached session on the connected daemon and return its `SessionRef`. Command, directory and environment options follow the subprocess method. Names must be valid UTF-8 without control bytes; tmux's name normalization still applies. The connection pins daemon identity and the prefixed reply verifies that identity. Cancellation after submission may leave a created session; no retry or automatic destruction occurs. The returned session is caller-owned.

```julia
new_session(connection::ControlConnection; name, kwargs...)
```

### `new_session` (overload 2)

```julia
new_session(
    server::LibTmux.Server;
    name,
    command,
    shell_command,
    start_directory,
    environment,
    kwargs...
)
```

[Source](https://github.com/libtmux/libtmux-julia/blob/f3da513be1225d36d5854cd8db5972c01857578e/src/operations.jl#L169).

Create a detached session and return its generation-bound `SessionRef`. `command` is an argv vector; `shell_command` explicitly runs `/bin/sh -c`. An executable name beginning with `-` requires `./-name` or an absolute path; arguments after the executable may begin with `-`. Omitting both uses tmux's configured default command. Creation can start a daemon at this endpoint. The returned reference does not own automatic cleanup. `environment` is a mapping or pairs of portable names to literal string values, passed at creation without format expansion. Duplicate names are rejected.

```julia
new_session(server; name, command=nothing, shell_command=nothing,
            start_directory=nothing, environment=(), timeout=5.0, cancel=nothing, strict=false)
```



Subprocess identity checks are best effort. `strict=true` refuses execution; there is no silent downgrade or replay after uncertain failure. An invalid creation reply raises `CreationResponseError` with command evidence.

## Parameters

- `connection` (`LibTmux.ControlConnection`) (for `new_session(connection, name, command, shell_command, start_directory, environment, kwargs)`)
- `name` (`AbstractString`)
- `command`
  Default: `nothing`.
- `shell_command`
  Default: `nothing`.
- `start_directory`
  Default: `nothing`.
- `environment`
  Default: `()`.
- `kwargs`
- `server` (`LibTmux.Server`) (for `new_session(server, name, command, shell_command, start_directory, environment, kwargs)`)
