# LibTmux::Session#new_window

- **Module:** LibTmux
- **Package:** libtmux
- **Language:** Ruby
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-ruby/blob/da7b6191b9439e3c84fa1c9eeaa9168263ee7af4/gems/libtmux/lib/libtmux/entity.rb#L103
- **Page:** https://libtmux.org/en/ruby/v0.1.1/reference/libtmux-session-new_window/

```
def new_window: (
  name: ::String,
  command: ::Array[::String],
  receipt: true,
  ?index: ::Integer?,
  ?cwd: ::String?,
  ?environment: ::Hash[::String, ::String],
  ?focus: bool,
  ?timeout: ::Numeric,
  ?cancel: untyped
) -> ::LibTmux::CreationReceipt

def new_window: (
  name: ::String,
  command: ::Array[::String],
  ?receipt: false,
  ?index: ::Integer?,
  ?cwd: ::String?,
  ?environment: ::Hash[::String, ::String],
  ?focus: bool,
  ?timeout: ::Numeric,
  ?cancel: untyped
) -> ::LibTmux::Window
```

Behavior: Creation.

Behavior contract: Creation.

## Examples

Create a named window in an existing session and read its name from a snapshot. Use Ruby 3.3 or newer with Bundler, and tmux 3.3a or newer, on Unix with `/bin/cat` and `/bin/sh` available. In an empty directory, save this `Gemfile`:

```ruby
source "https://rubygems.org"

gem "libtmux", "0.1.1"
```

Save this complete program as `new_window.rb`. Its `Server.start` block owns a private tmux server and stops it on exit, including after an error.

[Source example](https://github.com/libtmux/libtmux-ruby/blob/da7b6191b9439e3c84fa1c9eeaa9168263ee7af4/examples/api/new_window.rb).

```ruby
# frozen_string_literal: true

begin
  # docs:begin main
  require "libtmux"

  LibTmux::Server.start do |server|
    session = server.new_session(name: "work", command: ["/bin/cat"])
    window = session.new_window(name: "logs", command: ["/bin/cat"])
    puts "window: #{window.snapshot.name}"
    puts "session windows: #{session.list_windows.length}"
  end
  # docs:end main
rescue StandardError => error
  warn "#{error.class}: #{error.message}"
  exit 1
end
```

Install the gem and run the program. An operation or cleanup error makes it exit unsuccessfully:

```console
$ bundle install && \
  bundle exec ruby new_window.rb
```

Expected output:

```text
window: logs
session windows: 2
```

## Parameters

- `name` (`::String`)
- `command` (`::Array[::String]`)
- `receipt` (`true`) (for `new_window(name, command, receipt, index, cwd, environment, focus, timeout, cancel) [overload 1]`)
- `index` (`::Integer?`)
- `cwd` (`::String?`)
- `environment` (`::Hash[::String, ::String]`)
- `focus` (`bool`)
- `timeout` (`::Numeric`)
- `cancel` (`untyped`)
- `receipt` (`false`) (for `new_window(name, command, receipt, index, cwd, environment, focus, timeout, cancel) [overload 2]`)

## tmux command

The tmux commands behind `new_window`.

- [`new-window`](/en/tmux/latest/manual/new-window/)

## tmux C API

The C declarations in tmux that implement these commands.

- [`cmd_new_window_entry`](/en/tmux/latest/reference/c-variable-cmd_new_window_entry/) (attribute)
- [`cmd_new_window_exec`](/en/tmux/latest/reference/c-function-cmd-new-window-c-cmd_new_window_exec/) (function)

## Guides

Pages that discuss `new_window`.

- [Server bindings](/en/ruby/v0.1.1/guides/core/)

## In other ports

Create a window

| Language | Equivalent |
| --- | --- |
| Python | [`libtmux.Session.new_window`](/en/py/latest/reference/libtmux-session-new_window/) (method) |
| Lua | [`libtmux.Session:new_window`](/en/lua/latest/reference/libtmux-session-new_window/) (method) |
| TypeScript | [`session.Session.newWindow`](/en/ts/latest/reference/session-session-newwindow/) (method) |
| Rust | [`session.Session.new_window`](/en/rs/latest/reference/session-session-new_window/) (method) |
| Go | [`tmux.Session.NewWindow`](/en/go/latest/reference/tmux-session-newwindow/) (method) |
| Java | [`io.github.libtmux.Session.newWindow`](/en/java/latest/reference/io-github-libtmux-session-session-newwindow/) (method) |
| Kotlin | [`io.github.libtmux.kotlin.Session.newWindow`](/en/kotlin/latest/reference/io-github-libtmux-kotlin-session-newwindow/) (method) |
| Scala | [`io.github.libtmux.scaladsl.Session.newWindow`](/en/scala/latest/reference/io-github-libtmux-scaladsl-session-newwindow/) (method) |
| C# | [`LibTmux.Session.CreateWindowAsync`](/en/csharp/latest/reference/libtmux-session-createwindowasync/) (method) |
| C++ | [`libtmux::Session::new_window`](/en/cxx/latest/reference/libtmux-session-new_window/) (method) |
| Swift | [`Server.newWindow(in:named:startDirectory:at:environment:shell:)`](/en/swift/latest/reference/server-newwindow(in-named-startdirectory-)/) (method) |

No equivalent is recorded in PowerShell, Julia, Elixir or F#.
