Server.newSession
Creates a detached session and returns that exact session.
Source and package
- Qualified name
-
io.github .libtmux .kotlin .Server. new Session - Package
- io.github.libtmux.kotlin
- Declared in
Server- Distribution
- io.github.libtmux:libtmux-kotlin
- Source
- libtmux-kotlin/build/generated/sources/operations/kotlin/io/github/libtmux/kotlin/ServerOperations.kt
- public
Kotlin suspending functionsAllows a function to call suspending operations and pause without blocking a thread. It does not start a coroutine by itself. fun Server.newSession(name: String): SessionpublicKotlin suspending functionsAllows a function to call suspending operations and pause without blocking a thread. It does not start a coroutine by itself. fun Server.newSession( spec: SessionSpec ): SessionpublicKotlin suspending functionsAllows a function to call suspending operations and pause without blocking a thread. It does not start a coroutine by itself. fun Server.newSession( configure: SessionBuilder .() -> Unit ): Session -
- Parameters
-
-
spec(SessionSpec ) fornewSession(spec) -
configure(SessionBuilder .() -> Unit) fornewSession(configure)
- Errors
-
-
Illegal
Argument – if the session and its first window block both set a directory, or both set a command: tmux has one of each for that window forException newSession(configure)
-
Examples
Create a session running cat. Use JDK 25, Gradle 9 or newer, and tmux 3.3a or newer on Linux, with
/bin/catand/bin/shavailable. In an empty directory, save this consumer setup assettings.gradle.kts:rootProject.name = "api-example"Save this consumer setup as
build.gradle.kts. It depends on the 0.1.2 release from Maven Central:plugins {kotlin("jvm") version "2.4.10"application}repositories { mavenCentral() }dependencies {implementation("io.github.libtmux:libtmux-kotlin:0.1.2")}java { toolchain { languageVersion.set(JavaLanguageVersion.of(25)) } }kotlin { jvmToolchain(25) }application { mainClass.set(providers.gradleProperty("exampleMain")) }Save this consumer setup as
gradle.properties: View sourcegradle.properties org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=768m -Dfile.encoding=UTF-8kotlin.daemon.jvmargs=-Xmx2gorg.gradle.workers.max=2Save this complete program as
src/main/kotlin/NewSession.kt. It starts a private tmux server of its own and stops it when the program closes it. View sourcesrc/main/kotlin/NewSession.ktComplete program package io.github.libtmux.examples.api.kotlinimport io.github.libtmux.SessionSpecimport io.github.libtmux.kotlin.*import kotlin.system.exitProcessimport kotlinx.coroutines.runBlocking/** Create a session running cat. */fun main() {try {runBlocking {withPrivateServer { server ->val session = server.newSession(SessionSpec.builder().named("api-session").running("/bin/cat").build())println("created=${session.name}")}}} catch (error: Exception) {if (error is InterruptedException) Thread.currentThread().interrupt()System.err.println("Example failed: ${error.message}")exitProcess(1)}}Build the minimal consumer with Gradle and run the saved program. An operation or cleanup error makes the command exit unsuccessfully:
Terminal window $ gradle --console=plain --quiet installDist -PexampleMain=io.github.libtmux.examples.api.kotlin.NewSessionKt && \build/install/api-example/bin/api-exampleExpected output:
created=api-session
Recorded calls
source callsThe Kotlin reference records declarations, not calls, so this page shows no callers or callees. That is a limit of the extracted data, not a statement that nothing calls io.github.libtmux.kotlin.Server.newSession.
tmux command
task materialThe tmux commands behind newSession.
tmux C API
task materialThe C declarations in tmux that implement these commands.
Each path starts at a function a command runs, which is degree 1. The degree counts steps from there along the path, and each step is a call or a reference: degree 2 is reached from that function, degree 3 from the next, and so on.
Create a session and its first pane
- 1
cmd_new_session_exec - calls → 2
spawn_window - calls → 3
spawn_pane - calls → 4
window_add_pane - calls → 5
window_pane_create
Guides
task materialPages that discuss newSession.
In other ports
task equivalence 16 other ports mappedSource-verified mappings for Create a session. A mapping says these APIs perform the same task. It does not say they share defaults, errors or completion: check each page.
| Port | API | Differs from Kotlin |
|---|---|---|
| Kotlin | io Creates a detached session and returns that exact session. | This page |
| Python | libtmux Create new session, returns new Session. | None recorded in the model |
| Ruby | Lib Behavior: Creation. | None recorded in the model |
| Lua | libtmux | None recorded in the model |
| Erlang | tmux Create a detached session by default and explicitly observe the returned row. Options include name, window_name, dimensions, cwd, env and launch. Performs I/O; an observation failure after successful creation retains mutation = completed and the original command result. Existing names are not adopted. | free function |
| TypeScript | server Create a detached session and resolve it as a handle. | None recorded in the model |
| Rust | server Create a detached session and return it. | None recorded in the model |
| Go | tmux NewSession creates a detached session, then returns a newly materialized Session. It never changes client focus. KillExisting is not rolled back; transport and context failures may be delivery-ambiguous. | None recorded in the model |
| Java | io Creates a detached session and returns that exact session. | None recorded in the model |
| Clojure | libtmux Creates a detached session and returns a fresh captured session map. | free function |
| Scala | io Creates a detached session and returns that exact session. | None recorded in the model |
| C# | Lib Creates a session. | None recorded in the model |
| C++ | libtmux:: Created detached, and returned, because tmux prints what it made. | readonly |
| Swift | Server Creates a detached session. | None recorded in the model |
| OCaml | Libtmux Create a detached session on the bound daemon. Name collisions fail. | free function |
| Perl | Lib new_session(name => string, command => arrayref?, shell_command => string?, width => integer?, height => integer?, cwd => bytes?, environment => hashref?). | Explicit Server operation. Captured entities remain local observations; use a new snapshot to observe changes. |
| Raku | Lib Create a detached session and return its value-only, identity-scoped reference. | None recorded in the model |
No public Haskell equivalent is implemented; the current modules expose scalar values and version parsing.
No equivalent is recorded in PowerShell, Julia, Elixir, Common Lisp or F#.