# LibTmux::Session#new_window

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

tmux command: [`new-window`](/en/tmux/latest/manual/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 4.0.7, Bundler, Git and tmux 3.2a or newer on Unix, with /bin/cat and /bin/sh available. In an empty directory, fetch the documented library revision:

```console
$ git clone https://github.com/libtmux/libtmux-ruby.git libtmux-source && \
  git -C libtmux-source checkout dcc9f8b5a6970144a9e7d80cd5f381d8f6198372
```

Save this dependency file as Gemfile:

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

gem "libtmux", path: "libtmux-source/gems/libtmux"
```

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/dcc9f8b5a6970144a9e7d80cd5f381d8f6198372/examples/api/new_window.rb).

```ruby
# frozen_string_literal: true

require "libtmux"

begin
  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
rescue StandardError => error
  warn "#{error.class}: #{error.message}"
  exit 1
end
```

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

```console
$ bundle config set --local path vendor/bundle && \
  bundle install --jobs 2 && \
  bundle exec ruby new_window.rb
```

Expected output:

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

## In other ports

### Create a window

- 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.Session.newWindow`](/en/java/latest/reference/io-github-libtmux-session-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:)`](/en/swift/latest/reference/server-newwindow(in-named-startdirectory-)/) (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)
