# builder.applyWorkspace

**Workspace Manager concept example** A working example of the core library. It can change without notice.

- **Module:** builder
- **Package:** @libtmux/workspace
- **Language:** TypeScript
- **Kind:** function
- **Source:** https://github.com/libtmux/libtmux-ts/blob/46cccfef2a546de55ce8b308249b8c76339089a0/packages/workspace/src/builder.ts#L132
- **Page:** https://libtmux.org/en/ts/latest/workspace/reference/builder-applyworkspace/

```
async function applyWorkspace(
  server: Server,
  workspaceInput: WorkspaceInput,
  options: ApplyWorkspaceOptions = {},
): Promise<Session>
```

Build a workspace into a real tmux session, or reconcile one that exists.

tmux gives every new session a window and every new window a pane, so the
first window and first pane of each level are adopted rather than created.
Creating them anyway is the classic workspace-builder bug that leaves an
empty leading window behind.

What this reconciles is *topology*: which windows exist, in what order, under
what names, with how many panes, under which layout. It is safe to apply
twice and the second run does not duplicate anything. It is deliberately not
a process supervisor — see [`CommandPolicy`](/en/ts/latest/workspace/reference/operation_options-commandpolicy/) — and it does not unset
options a previous version of the file had set, because tmux cannot say which
of an option's current values this file is responsible for.

This is not the builder behind the `tmux-workspace` command. The two are
separate implementations of one idea and they answer differently: this one
converges a session that exists, while the CLI compares it against the
document and refuses when they disagree. The document language differs too —
the schema here is strict, so `environment`, `before_script`, [`window_index`](/en/tmux/latest/catalog/formats/window_index/),
`suppress_history`, `x-` keys and the CLI's other fields are rejected. A file
written for the CLI is not necessarily one this accepts.

## Parameters

- `server` (`Server`)
- `workspaceInput` (`WorkspaceInput`)
- `options` (`ApplyWorkspaceOptions`)
  Default: `{}`.

## Raises

- `ZodError`: when the workspace does not satisfy the strict config schema.
- [`TypeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError): when operation options, layouts or version replies are invalid.
- [`WorkspaceApplyError`](/en/ts/latest/workspace/reference/builder-workspaceapplyerror/): when tmux fails after applying may have started.

## Guides

Pages that discuss `applyWorkspace`.

### Concepts

- [Workspaces](/en/ts/latest/concepts/workspaces/)

### Ports

- [TypeScript workspace internals](/en/ts/latest/workspace/internals/)
- [TypeScript workspace builder examples](/en/ts/latest/workspace/internals/examples/)
- [Use the TypeScript workspace builder](/en/ts/latest/workspace/internals/guides/)
- [TypeScript workspace builder API](/en/ts/latest/workspace/reference/)

## In other ports

Build a session from a workspace description

| Language | Equivalent |
| --- | --- |
| Python | [`tmuxp.workspace.builder.ClassicWorkspaceBuilder.build`](/en/py/latest/workspace/reference/tmuxp-workspace-builder-classicworkspacebuilder-build/) (method) |
| Ruby | [`LibTmux::Workspace::Plan#apply`](/en/ruby/latest/workspace/reference/libtmux-workspace-plan-apply/) (method) |
| PowerShell | [`LibTmux.Workspace\Invoke-TmuxWorkspace`](/en/powershell/latest/workspace/reference/libtmux-workspace-invoke-tmuxworkspace/) (cmdlet). Applies the exact reviewed [`-Plan`](/en/powershell/latest/workspace/reference/libtmux-workspace-invoke-tmuxworkspace/#LibTmux.Workspace%5CInvoke-TmuxWorkspace.parameter.Plan) after PowerShell confirmation. [`-WhatIf`](/en/powershell/latest/workspace/reference/libtmux-workspace-invoke-tmuxworkspace/#LibTmux.Workspace%5CInvoke-TmuxWorkspace.parameter.WhatIf) previews without applying it; application is detached. |
| Julia | [`LibTmuxWorkspace.apply`](/en/julia/latest/workspace/reference/libtmuxworkspace-apply/) (function). Applies a prepared `WorkspacePlan` on an explicit `Server`, detached and under one deadline. Existing session names fail unless reuse is explicit. |
| Rust | [`src.WorkspaceBuilder.build`](/en/rs/latest/workspace/reference/src-workspacebuilder-build/) (method) |
| Go | [`workspace.Build`](/en/go/latest/workspace/reference/workspace-build/) (function) |
| Java | [`io.github.libtmux.workspace.WorkspaceBuilder.build`](/en/java/latest/workspace/reference/io-github-libtmux-workspace-workspacebuilder-workspacebuilder-build/) (method) |
| C# | [`LibTmux.Workspace.WorkspaceBuilder.BuildAsync`](/en/csharp/latest/workspace/reference/libtmux-workspace-workspacebuilder-buildasync/) (method) |
| C++ | [`libtmux::workspace::build`](/en/cxx/latest/workspace/reference/libtmux-workspace-build/) (function) |
| Swift | [`WorkspaceBuilder.build(_:on:)`](/en/swift/latest/workspace/reference/workspacebuilder-build(_-on-)/) (method) |

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