# Automate workspace operations

Source: https://libtmux.org/en/csharp/latest/workspace/guides/automation/

> Run detached commands with explicit inputs and machine-readable results.

Give automation an explicit file, endpoint and attachment choice. Continue the
[installation walkthrough](https://libtmux.org/en/csharp/latest/workspace/guides/installation/) with this detached operation:

```console
$ tmux-workspace load \
    -S "$WORKSPACE_TMP/tmux.sock" \
    -d \
    --json \
    workspace.yaml
```

Check the process exit status, parse its JSON result, then inspect any reported
partial effects. A failed later input does not imply that earlier sessions
were removed. Keep stderr separate from the result stream.

## Follow progress

Use NDJSON when the caller needs records while a load is running:

```console
$ tmux-workspace load \
    -S "$WORKSPACE_TMP/tmux.sock" \
    -d \
    --ndjson \
    workspace.yaml
```

Parse one complete JSON value per line. Treat a closed stream or missing final
result as incomplete work. Do not infer success from an earlier creation event.

## Make retries deliberate

Use a unique session name for independent jobs. Reusing a name follows the
loader's existing-session policy; it is not a request to reset that session.
Capture IDs and retained effects from the result before deciding what to clean
up or retry. Remove only sessions the job owns.

Read [output](https://libtmux.org/en/csharp/latest/workspace/reference/output/) and [errors](https://libtmux.org/en/csharp/latest/workspace/reference/exit-codes/)
for the command's machine interface. A pane's process can outlive the CLI and
can fail after successful command delivery.

[CLI source](https://github.com/libtmux/libtmux-dotnet/blob/f77fe776ba67a04abb20ddbbc26cf4a000d63b74/src/LibTmux.Workspace.Cli/README.md).
