# server.Server.windows

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

```
async windows(): Promise<Selection<Window>>
```

Every window on the server, including each placement of a linked window.

Save this complete program as `windows.ts`. With Bun 1.4.2 or newer,
tmux 3.3a or newer, and `libtmux` installed, run `bun `[`run`](/en/ts/latest/reference/server-server-run/)` windows.ts`.
It creates and stops a private tmux server. A failed operation or cleanup
exits with an error; a cleanup error names the retained socket directory.

## Examples

```ts
import { strict as assert } from "node:assert";
import { mkdtemp, readdir, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { Server, MultipleMatchesError } from "libtmux";

const directory = await mkdtemp(join(tmpdir(), "ltx-example-"));
const server = new Server({
  socketPath: join(directory, "tmux.sock"),
  configFile: "/dev/null",
  timeoutMs: 5_000,
});
const failures: unknown[] = [];
try {
  const session = await server.newSession({
    name: "home",
    windowName: "editor",
    shellCommand: "cat",
  });
  const guest = await server.newSession({
    name: "guest",
    windowName: "shell",
    shellCommand: "cat",
  });
  const window = await session.newWindow({ name: "logs", shellCommand: "cat" });
  await window.link({ session: guest });
  const windows = await server.windows();
  const logs = windows.where({ name: "logs" });
  assert.equal(logs.count(), 2);
  console.log("logs placements:", logs.count());
  try {
    logs.one();
    throw new Error("Expected a linked window lookup to be ambiguous");
  } catch (error) {
    if (!(error instanceof MultipleMatchesError)) throw error;
    console.log("ambiguous:", error.code);
  }
  const placed = logs.one({ session: { is: { name: "home" } } });
  assert.equal(placed.id, window.id);
  console.log("selected placement:", placed.session?.name);
  console.log(
    "linked sessions:",
    placed.linkedSessions
      .map((item) => item.name)
      .sort()
      .join(", "),
  );
} catch (error) {
  failures.push(error);
} finally {
  try {
    if ((await readdir(directory)).includes("tmux.sock")) await server.kill();
    await rm(directory, { recursive: true });
  } catch (error) {
    failures.push(new Error(`Cleanup failed; inspect ${directory}`, { cause: error }));
  }
}
if (failures.length > 0) throw new AggregateError(failures, "Example failed");
```

## Guides

Pages that discuss `windows`.

- [Filtering and queries](/en/ts/latest/concepts/queries/)

## In other ports

List the server's windows

| Language | Equivalent |
| --- | --- |
| Python | [`libtmux.Server.windows`](/en/py/latest/reference/libtmux-server-windows/) (property) |
| Ruby | [`LibTmux::Server#list_windows`](/en/ruby/latest/reference/libtmux-server-list_windows/) (method) |
| Lua | [`libtmux.Snapshot.windows`](/en/lua/latest/reference/libtmux-snapshot-windows/) (attribute) |
| PowerShell | [`LibTmux\Get-TmuxWindow`](/en/powershell/latest/reference/libtmux-get-tmuxwindow/) (cmdlet). Use the [`-Server`](/en/powershell/latest/reference/libtmux-get-tmuxwindow/#LibTmux%5CGet-TmuxWindow.parameter.Server) parameter set to acquire window placements across all sessions. |
| Julia | [`LibTmux.windows`](/en/julia/latest/reference/libtmux-windows/) (function). `windows` with a `Snapshot` reads every captured physical window. Use `windowlinks` for session placements. |
| Elixir | [`LibTmux.Snapshot.windows/1`](/en/elixir/latest/reference/libtmux-snapshot-windows-1/) (function). Returns a `Selection` of every captured physical window. `window_links/1` lists session placements. |
| Rust | [`server.Server.windows`](/en/rs/latest/reference/server-server-windows/) (method) |
| Go | [`tmux.Server.Windows`](/en/go/latest/reference/tmux-server-windows/) (method) |
| Java | [`io.github.libtmux.Server.windows`](/en/java/latest/reference/io-github-libtmux-server-server-windows/) (method) |
| Kotlin | [`io.github.libtmux.kotlin.Server.windows`](/en/kotlin/latest/reference/io-github-libtmux-kotlin-server-windows/) (method) |
| Scala | [`io.github.libtmux.scaladsl.Server.windows`](/en/scala/latest/reference/io-github-libtmux-scaladsl-server-windows/) (method) |
| C# | [`LibTmux.Server.Windows`](/en/csharp/latest/reference/libtmux-server-windows/) (property) |
| F# | [`LibTmux.FSharp.Server.windows`](/en/fsharp/latest/reference/libtmux-fsharp-server-windows/) (function). Builds a deferred query for placements across all sessions. `Query.list` acquires the results; a linked window appears once for each session placement. |
| C++ | [`libtmux::Server::windows`](/en/cxx/latest/reference/libtmux-server-windows/) (method) |
| Swift | [`Server.windows()`](/en/swift/latest/reference/server-windows()/) (method) |
