# server.Server.hasSession

- **Module:** server
- **Package:** libtmux
- **Language:** TypeScript
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-ts/blob/073b9d7dedad900bff6f5ec0ea47794e40225870/packages/libtmux/src/server.ts#L1367
- **Page:** https://libtmux.org/en/ts/latest/reference/server-server-hassession/

```
hasSession(name: string): Promise<boolean>
```

Whether a session with this name exists.

The name is matched exactly, including one holding "." or ":". tmux
normally accepts a unique prefix as a session target, which would make
checking `work` answer yes for `workspace`; this method does not, and it
lists every session and compares in JavaScript rather than asking tmux
to resolve a target, since no target spelling is both exact and correct
for a name holding a target separator. No server running on the socket
answers `false`; any other failure to list sessions raises rather than
being read as "no such session".

## Examples

```ts
if (!(await server.hasSession("work"))) {
  await server.newSession({ name: "work" });
}
```

## Parameters

- `name` (`string`)

## tmux command

The tmux commands behind `hasSession`.

- [`list-sessions`](/en/tmux/latest/manual/list-sessions/)

## tmux C API

The C declarations in tmux that implement these commands.

- [`cmd_list_sessions_entry`](/en/tmux/latest/reference/c-variable-cmd_list_sessions_entry/) (attribute)
- [`cmd_list_sessions_exec`](/en/tmux/latest/reference/c-function-cmd-list-sessions-c-cmd_list_sessions_exec/) (function)

## In other ports

Whether a session with this name exists

| Language | Equivalent |
| --- | --- |
| Python | [`libtmux.Server.has_session`](/en/py/latest/reference/libtmux-server-has_session/) (method) |
| Rust | [`server.Server.has_session`](/en/rs/latest/reference/server-server-has_session/) (method) |
| Go | [`tmux.Server.HasSession`](/en/go/latest/reference/tmux-server-hassession/) (method) |
| Java | [`io.github.libtmux.Server.hasSession`](/en/java/latest/reference/io-github-libtmux-server-server-hassession/) (method) |
| C# | [`LibTmux.Server.HasSessionAsync`](/en/csharp/latest/reference/libtmux-server-hassessionasync/) (method) |
| C++ | no equivalent on `Server` |
| Swift | [`Server.hasSession(_:)`](/en/swift/latest/reference/server-hassession(_-)/) (method) |

No equivalent is recorded in Ruby, Lua, PowerShell, Julia, Elixir, Kotlin, Scala or F#.
