# tmux.CommandObserver

- **Module:** tmux
- **Package:** github.com/libtmux/libtmux-go/tmux
- **Language:** Go
- **Kind:** struct
- **Source:** https://github.com/libtmux/libtmux-go/blob/52968a3181c1c9e6d1b26c565d4b170968ae61c0/tmux/observer.go#L82
- **Page:** https://libtmux.org/en/go/latest/reference/tmux-commandobserver/

CommandObserver receives one [CommandTrace] per tmux command a [Server] and the values derived from it run:

server, err := tmux.NewServer(tmux.ServerOptions{
	CommandObserver: func(trace tmux.CommandTrace) {
		slog.Info("tmux", "command", trace.Subcommand,
			"transport", trace.Transport.String(),
			"duration", trace.Duration, "exit", trace.ExitCode)
	},
})
if err != nil {
	log.Fatal(err)
}

It is called synchronously on the goroutine that ran the command, after the
command finishes and before its result is returned, so a slow observer slows
every command. Operations may invoke it concurrently; synchronize shared
state. A nil observer costs nothing, not even the clock reads.

It sees the version probes this package runs on its own behalf, and the
identity probe a daemon guard runs to decide whether a failure was a
replaced daemon, so one call can produce more than one trace.
