# server.Server.new_session

- **Module:** server.Server
- **Package:** libtmux
- **Language:** Rust
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-rs/blob/8a648c0894dfffc9303583f753b6c8ae01f2fe76/crates/libtmux/src/server.rs#L706
- **Page:** https://libtmux.org/reference/rs/server-server-new_session/

```
server.Server.new_session(self, options: impl Into<NewSessionOptions>) -> Result<Session, Error>
```

Create a detached session and return it.

The session is always detached: attaching would take over the calling
process's terminal, which a library must not do on its own initiative.

tmux prints the new session through the same format machinery as a
listing, so this costs one round trip rather than a create followed by
a lookup.

tmux expands the name as a format before it checks it, so `#(command)`
in one runs a shell command. See [the crate documentation][crate#a-name-reaches-tmux-as-a-format]
before passing text a caller supplied.

# Errors

Returns an error when tmux refuses the command, which includes a name
that already exists, and when its output cannot be decoded.
