# tmux.Window.NewWindow

- **Module:** tmux.Window
- **Package:** github.com/libtmux/libtmux-go/tmux
- **Language:** Go
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-go/blob/52968a3181c1c9e6d1b26c565d4b170968ae61c0/tmux/window_lifecycle.go#L108
- **Page:** https://libtmux.org/en/go/latest/reference/tmux-window-newwindow/

```
tmux.Window.NewWindow(ctx: context.Context, request: NewWindowRequest) -> (Window, error)
```

NewWindow creates a window relative to the receiver's exact winlink. Set Direction to [NewWindowDirectionAfter] or [NewWindowDirectionBefore] for non-destructive relative creation. With the zero Direction, tmux targets the receiver's occupied index and normally returns a command error; KillExisting can destroy and replace that target. Attach changes the current window only in that target session. Index is rejected before execution because the receiver already supplies the target position. On tmux 3.8 and later, SelectExisting's -S also matches the receiver's own exact target (extended there to match -t as well as a window's name), so it always selects the receiver itself and prints nothing; the identity is already known without a probe. Earlier tmux only matched -S by name here, and always printed a created WindowID because the exact-target form never carries a bare name to match against.

If tmux reports an ID before a transport or refresh failure, the partial result
contains it and the receiver SessionID with Index -1. Other failures return
zero; creation is not rolled back.
