LibTmux.FSharp 0.1.1

Prefix Reserved
dotnet add package LibTmux.FSharp --version 0.1.1
                    
NuGet\Install-Package LibTmux.FSharp -Version 0.1.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LibTmux.FSharp" Version="0.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LibTmux.FSharp" Version="0.1.1" />
                    
Directory.Packages.props
<PackageReference Include="LibTmux.FSharp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add LibTmux.FSharp --version 0.1.1
                    
#r "nuget: LibTmux.FSharp, 0.1.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package LibTmux.FSharp@0.1.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=LibTmux.FSharp&version=0.1.1
                    
Install as a Cake Addin
#tool nuget:?package=LibTmux.FSharp&version=0.1.1
                    
Install as a Cake Tool

LibTmux.FSharp

LibTmux.FSharp libtmux.org

Drive tmux from F#: list and filter sessions, windows, panes and clients with typed filters, type and wait for what a pane prints, and run a command to its exit status. Every function works on the LibTmux core objects.

build tmux matrix license

Add it to an F# project:

$ dotnet add package LibTmux.FSharp

Releases. Releases are numbered 0.1.N, and each release increments N. The API is not settled: any release may change or remove exported identifiers, and the changelog marks each break. Pin an exact version to avoid one.

Contents — Quick start · Find · Type and wait · Run · Choose a call · Existing tmux · Leaves out · Support

Quick start

Start a server of its own, type a command, wait for its output, run another command to its exit status, and list sessions with a filter. This is the whole program:

open System
open System.Threading
open LibTmux
open LibTmux.FSharp

let runAsync () =
    task {
        use deadline = new CancellationTokenSource(TimeSpan.FromSeconds 30.)
        let token = deadline.Token

        // A server of its own on a private socket, without user configuration.
        let options =
            ServerConnectionOptions(
                SocketName = "fsharp-" + Guid.NewGuid().ToString("N"),
                ConfigurationFile = "/dev/null"
            )

        use! owned = options |> Server.createOwned token

        // One session whose window runs a plain shell, whatever the user's login shell is.
        let! session =
            owned.Value |> Server.newSession token (SessionSpec.running "build" "/bin/sh")

        let! pane = session |> Session.activePane token

        // Type a command and wait for what it prints, not for its echo.
        let! started =
            pane
            |> Pane.sendAndWait token (TimeSpan.FromSeconds 10.) "echo build started" "build started"

        printfn "wait found: %b" started.Found

        // Run a command to its exit status and read what it printed.
        let! result =
            pane |> Pane.run token (TimeSpan.FromSeconds 10.) "printf 'ok\\n'; exit 3"

        match result with
        | PaneRun.Exited status -> printfn "run: exit %d, output %A" status (List.ofSeq result.Output)
        | PaneRun.Ended -> printfn "run: the shell exited first"
        | PaneRun.NotStarted -> printfn "run: the shell was not at a prompt"
        | PaneRun.TimedOut -> printfn "run: still running"

        // List and filter: tmux narrows the listing, then every row is rechecked.
        let! found =
            owned.Value
            |> Server.sessions
            |> Query.where (SessionFields.name |> Filter.startsWith "bu")
            |> Query.list token

        printfn "sessions: %s" (String.Join(", ", [ for listed in found -> listed.Name ]))
    }

runAsync().GetAwaiter().GetResult()

To run it, make an F# console project and replace Program.fs with the program, with tmux on PATH:

$ dotnet new console --language F# --framework net8.0 --output tmux-demo && \
    cd tmux-demo && \
    dotnet add package LibTmux.FSharp && \
    dotnet run

It prints:

wait found: true
run: exit 3, output ["ok"]
sessions: build
  • Server.createOwned starts a server on a unique socket with the tmux on PATH; set ServerConnectionOptions.TmuxBinaryPath to use another. use! stops it when the task ends.
  • The wait succeeds whether the line appeared before or after it began.
  • The run's exit status comes from the shell, so it does not depend on reading the screen.
  • The listing reaches tmux as a filter, so tmux returns only the sessions that match.

The program is published from a checkout: dotnet run --project examples/LibTmux.FSharp.Quickstart runs it against the source.

CI restores LibTmux.FSharp from freshly packed artifacts, runs it against real tmux on both target frameworks, and compares what it prints with the block above.

Find sessions, windows, and panes

Query.list: the panes that match a filter

Describe the listing with Server.panes and Query.where, then read it. Building a query reads nothing; tmux narrows the listing where it can, and every row it returns is rechecked:

open System.Threading
open LibTmux
open LibTmux.FSharp

let shellPanesAsync (cancellationToken: CancellationToken) (server: Server) =
    server
    |> Server.panes
    |> Query.where (PaneFields.currentCommand |> Filter.oneOf [ "bash"; "sh"; "zsh" ])
    |> Query.list cancellationToken

Run it with a server from Server.createOwned; it returns the panes whose command is one of the three shells.

Query.exactlyOne returns a Result for the case where exactly one match is expected, and Query.atMostOne returns an option and raises on several matches. Query.tryExactlyOne is the form to use under NativeAOT.

Type into a pane and wait

Pane.sendAndWait: type a line, wait for its answer

It types the line, then waits for a later line to contain the text. The screen before it and the line's own echo do not count.

From tmux 3.7 it sleeps on the pane's output; earlier releases poll. It ends early if the program exits while it waits. This example finds a shell, types into it, and waits:

open System
open System.Threading
open LibTmux
open LibTmux.FSharp

let runInShellAsync (cancellationToken: CancellationToken) (server: Server) =
    task {
        // List and filter: tmux narrows the listing, then every row is rechecked.
        let! shells =
            server
            |> Server.panes
            |> Query.where (PaneFields.currentCommand |> Filter.oneOf [ "bash"; "sh"; "zsh" ])
            |> Query.list cancellationToken

        match shells |> Seq.tryHead with
        | None -> return None
        | Some pane ->
            // Type a command and wait for what it prints, not for its echo.
            let! ready =
                pane
                |> Pane.sendAndWait cancellationToken (TimeSpan.FromSeconds 10.) "echo ready" "ready"

            // Run a command to its exit status and read what it printed.
            let! listing = pane |> Pane.run cancellationToken (TimeSpan.FromSeconds 30.) "ls /"

            match listing with
            | PaneRun.Exited status -> return Some(ready.Found, status, listing.Output)
            | PaneRun.Ended
            | PaneRun.NotStarted
            | PaneRun.TimedOut -> return None
    }

It returns Some (true, 0, lines) for the ls / listing, or None when no shell pane exists or the shell was not at a prompt.

  • Pane.waitFor waits for output you did not type, and Pane.sendAndWaitFor takes keys and patterns.
  • Every wait ends early when the program exits, and raises TmuxPaneException if it already had. Which wait compares them.
  • The sample types into the first shell it finds. On a tmux that is already running, that may be the terminal you are reading.

Run a command and read its status

Pane.run: the exit status and what it printed

It returns the lines the command printed, and the PaneRun case says how it ended: the command exited with a status, its shell exited first, it never started, or it ran out of time:

open System
open System.Threading
open LibTmux
open LibTmux.FSharp

let exitStatusAsync (cancellationToken: CancellationToken) (pane: Pane) =
    task {
        // Run a command to its exit status and read what it printed.
        let! run =
            pane
            |> Pane.run cancellationToken (TimeSpan.FromSeconds 10.) "printf 'ok\\n'; exit 3"

        match run with
        | PaneRun.Exited status -> return Some(status, List.ofSeq run.Output)
        | PaneRun.Ended
        | PaneRun.NotStarted
        | PaneRun.TimedOut -> return None
    }

Against the quick-start server it returns Some (3, ["ok"]).

Pane.run needs a POSIX shell prompt and refuses fish, PowerShell, and a REPL.

Choose a call

Connect

Need F# call Returns
Start a server you own options \|> Server.createOwned ct OwnedServerScope to use!
Attach to a running server options \|> Server.connect ct Server
Bound every command's time Server.within timeout server Server

Find

Need F# call Returns
List and filter Server.panes server \|> Query.where filter \|> Query.list ct IReadOnlyList<Pane>
One session's or window's panes Session.panes session \|> Query.list ct; Window.panes alike IReadOnlyList<Pane>
Panes showing some text Server.panes server \|> Query.showing search \|> Query.list ct IReadOnlyList<Pane>
Exactly one match Query.exactlyOne ct query; Query.tryExactlyOne under NativeAOT Result<'T, CardinalityError>; 'T option
Find, or create when absent Query.atMostOne ct query 'T option; several raise
One object by ID Server.tryFindPane ct id server Pane option
The pane a session or window shows Session.activePane ct session, Window.activePane ct window Pane

Type, wait and run

Need F# call Returns
Type a line, or press a key Pane.sendLine ct line pane; Pane.pressKey ct "C-c" pane Task
Type a line, wait for its output Pane.sendAndWait ct timeout line text pane; Pane.sendAndWaitFor for keys and patterns PaneWaitResult; .Found, or match PaneWait
Wait for output you did not type Pane.waitForText ct timeout text pane; Pane.waitFor for patterns PaneWaitResult
Wait for a screen condition Pane.waitUntil ct timeout condition pane PaneWaitResult
Many waits on one session use! _ = Session.holdWaitClient ct session IAsyncDisposable; each wait skips attaching a client, about 5 ms
Run a command to its exit status Pane.run ct timeout command pane PaneRunResult; match PaneRun
Read the screen Pane.capture ct request pane IReadOnlyList<string>
What a pane printed since last time Pane.readSince ct position pane PaneOutputSince; pass its Position next time
Find text on one screen Pane.findOnScreen ct search pane row int option

Build

Need F# call Returns
Split a pane Pane.split ct request pane the new Pane
Rename a session or window Window.rename ct name window a handle with the new name
Make a window or pane current Window.select ct window, Pane.select ct pane a handle with the state afterwards
Kill a session, window or pane Pane.kill ct pane Task
Arrange, resize or move a window Window.selectLayout ct layout window, Window.resize ct request window, Window.move ct request window a handle with the state afterwards
Title, resize, swap, respawn or clear a pane Pane.setTitle ct title pane, Pane.resize, Pane.swap, Pane.respawn, Pane.clearHistory the handle, or Task
Add a window to a session Session.newWindow ct request session the new Window
Create a session running one command Server.newSession ct (SessionSpec.running name command) server Session
Create a session with windows Server.newSession ct spec server Session
Several commands, one tmux call Chain.start server \|> … \|> Chain.run ct TmuxCommandResult
Read or set a typed option Options.get ct key options the key's value type

Observe

Need F# call Returns
A whole object graph Server.capture ct depth server snapshot Server
Live server state Mirror.start ct session ServerMirror
Events as they happen Control.withSession ct work server cold IAsyncEnumerable streams
One pane's output as it prints Control.watchPane pane client; Control.watchPanes for several events; match PaneWatch
An assistant on the same tmux the LibTmux.Mcp server MCP guide

Recover

Need F# call Returns
Tell failures apart TmuxFailure.NotSent, Ran, MayHaveRun active patterns
Retry only unsent work Retry.ifNotSent ct retries operation, or Retry.ifNotSentAfter ct delays operation the operation's result
Await a call in an async workflow TmuxAsync.awaitTask task, TmuxAsync.awaitUnitTask task Async; keeps what MayHaveRun matches

Caveats

Connect to a running tmux

Server.connect: a server your program did not start

options |> Server.connect ct attaches to the server already running on the socket the options name. It never starts tmux.

Default options choose no socket, so tmux picks the server; socket selection gives the order. Code running inside a tmux pane can use Server.FromEnvironment() to find that pane's server.

What it leaves out

  • Its own handle types. Captured sessions, windows, panes, and IDs are the core .NET types. A window linked into more than one session has a placement in each; filtering keeps their order and multiplicity.
  • Implicit starts. Server.connect never starts tmux; Server.createOwned does, and stops it.
  • Control-mode waits on older releases. Waits use pane output from tmux 3.7; earlier releases poll.
  • Other shells for Pane.run. It needs a POSIX shell prompt.
  • Empty answers for missing data. An uncaptured relationship raises IncompleteSnapshotException.

Support and status

  • Releases. Releases are numbered 0.1.N, and each release increments N. The API is not settled: any release may change or remove exported identifiers, and the changelog marks each break. Pin an exact version to avoid one.
  • .NET. .NET 8 and .NET 10, using the matching LibTmux package version.
  • F#. FSharp.Core 8.0.100 or newer, so an application keeps its SDK's FSharp.Core. CI builds and runs a consumer with the .NET 8 SDK's F# compiler.
  • tmux. A release runs the F# integration example against tmux 3.3a, 3.4, 3.5, 3.6, 3.7a, 3.7b, 3.7c, and 3.8 on both target frameworks, and each push runs it against 3.3a and 3.8.
  • Systems. Linux, including WSL. macOS is best effort, without CI coverage. Native Windows is unsupported: the core marks its tmux calls [UnsupportedOSPlatform("windows")].
  • NativeAOT and trimming. Portable filters bind fields without reflection. A Linux consumer publishes and runs snapshots, tmux queries, and portable filters under both, on both frameworks.
  • Under NativeAOT, Selection.exactlyOne and Query.exactlyOne cannot be published, because their Result formats through printf, which NativeAOT rejects.
  • The NativeAOT alternatives are Query.atMostOne, or Query.tryExactlyOne where none and several can be treated alike.

Documentation

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.1 108 11/1/2026
0.1.0 148 10/25/2026
0.0.0-alpha.24 69 10/25/2026
0.0.0-alpha.23 66 10/24/2026
0.0.0-alpha.22 66 10/19/2026
0.0.0-alpha.21 71 10/11/2026
0.0.0-alpha.20 66 10/5/2026
0.0.0-alpha.19 66 10/4/2026
0.0.0-alpha.18 70 10/3/2026
0.0.0-alpha.17 77 9/27/2026

LibTmux, LibTmux.FSharp, LibTmux.Testing, LibTmux.Query.Json, LibTmux.Extensions.DependencyInjection, LibTmux.Workspace, LibTmux.Workspace.Cli and LibTmux.Mcp share one version, so this release covers them together. What changed, per package and per release: https://github.com/libtmux/libtmux-dotnet/blob/master/CHANGELOG.md The public API is not settled and any release may change it; pin an exact version.