Skip to main content
Glama

List tmux Sessions

tmux_list_sessions
Read-onlyIdempotent

List active tmux sessions with details like name, window count, creation time, and attachment status to manage terminal sessions.

Instructions

List all active tmux sessions.

Returns information about each session including:

  • Session name

  • Number of windows

  • Creation time

  • Whether the session is currently attached

Use this tool to discover available sessions before operating on them.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function that lists all tmux sessions by executing 'tmux list-sessions' with a custom format, parsing the output into a structured array of sessions (name, windows, created time, attached status), and returning JSON-formatted text content with structured data.
      async () => {
        try {
          const output = await runTmux('list-sessions -F "#{session_name}|#{session_windows}|#{session_created}|#{session_attached}"');
          
          if (!output) {
            return {
              content: [{ type: "text", text: "No tmux sessions found." }],
            };
          }
    
          const sessions: TmuxSession[] = output.split("\n").map((line) => {
            const [name, windows, created, attached] = line.split("|");
            return {
              name,
              windows: parseInt(windows, 10),
              created: new Date(parseInt(created, 10) * 1000).toISOString(),
              attached: attached === "1",
            };
          });
    
          const result = {
            count: sessions.length,
            sessions,
          };
    
          return {
            content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
            structuredContent: result,
          };
        } catch (error) {
          return {
            content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
            isError: true,
          };
        }
      }
    );
  • The tool schema defining title, multi-line description, empty input schema (no parameters required), and annotations indicating it is read-only, non-destructive, idempotent, and not open-world.
      {
        title: "List tmux Sessions",
        description: `List all active tmux sessions.
    
    Returns information about each session including:
    - Session name
    - Number of windows
    - Creation time
    - Whether the session is currently attached
    
    Use this tool to discover available sessions before operating on them.`,
        inputSchema: z.object({}).strict(),
        annotations: {
          readOnlyHint: true,
          destructiveHint: false,
          idempotentHint: true,
          openWorldHint: false,
        },
      },
  • src/index.ts:104-161 (registration)
    The server.registerTool call that registers the 'tmux_list_sessions' tool with its schema and inline handler function.
    server.registerTool(
      "tmux_list_sessions",
      {
        title: "List tmux Sessions",
        description: `List all active tmux sessions.
    
    Returns information about each session including:
    - Session name
    - Number of windows
    - Creation time
    - Whether the session is currently attached
    
    Use this tool to discover available sessions before operating on them.`,
        inputSchema: z.object({}).strict(),
        annotations: {
          readOnlyHint: true,
          destructiveHint: false,
          idempotentHint: true,
          openWorldHint: false,
        },
      },
      async () => {
        try {
          const output = await runTmux('list-sessions -F "#{session_name}|#{session_windows}|#{session_created}|#{session_attached}"');
          
          if (!output) {
            return {
              content: [{ type: "text", text: "No tmux sessions found." }],
            };
          }
    
          const sessions: TmuxSession[] = output.split("\n").map((line) => {
            const [name, windows, created, attached] = line.split("|");
            return {
              name,
              windows: parseInt(windows, 10),
              created: new Date(parseInt(created, 10) * 1000).toISOString(),
              attached: attached === "1",
            };
          });
    
          const result = {
            count: sessions.length,
            sessions,
          };
    
          return {
            content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
            structuredContent: result,
          };
        } catch (error) {
          return {
            content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
            isError: true,
          };
        }
      }
    );
  • Utility function to execute tmux commands via child_process.exec, handles common tmux errors like no server or session not found, and returns trimmed stdout.
    async function runTmux(args: string): Promise<string> {
      try {
        const { stdout } = await execAsync(`tmux ${args}`);
        return stdout.trim();
      } catch (error: unknown) {
        if (error instanceof Error && "stderr" in error) {
          const stderr = (error as { stderr: string }).stderr;
          if (stderr.includes("no server running")) {
            throw new Error("tmux server is not running. Start a session first with tmux_create_session.");
          }
          if (stderr.includes("session not found")) {
            throw new Error("Session not found. Use tmux_list_sessions to see available sessions.");
          }
          if (stderr.includes("window not found")) {
            throw new Error("Window not found. Use tmux_list_windows to see available windows.");
          }
          if (stderr.includes("can't find pane")) {
            throw new Error("Pane not found. Use tmux_list_panes to see available panes.");
          }
          throw new Error(`tmux error: ${stderr}`);
        }
        throw error;
      }
    }
  • TypeScript interface defining the structure of a tmux session object used in the tool's output.
    interface TmuxSession {
      name: string;
      windows: number;
      created: string;
      attached: boolean;
    }
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already provide readOnlyHint=true, destructiveHint=false, idempotentHint=true, and openWorldHint=false, covering safety and idempotency. The description adds valuable context about what information is returned (session name, windows count, creation time, attachment status) and the tool's role in session discovery workflow, which goes beyond annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is perfectly front-loaded with the core purpose in the first sentence, followed by specific return details in a bulleted list, and ends with clear usage guidance. Every sentence earns its place with no wasted words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a zero-parameter read-only tool with comprehensive annotations, the description provides exactly what's needed: clear purpose, output details (compensating for lack of output schema), and explicit usage context. It's complete without being verbose.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0 parameters and 100% schema description coverage, the baseline is 4. The description appropriately doesn't discuss parameters since none exist, and instead focuses on the tool's output semantics, which is helpful given no output schema is provided.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('List all active tmux sessions') and distinguishes it from siblings by focusing on session discovery rather than creation, manipulation, or window/pane operations. It explicitly names the resource (tmux sessions) and verb (list).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit guidance on when to use this tool: 'Use this tool to discover available sessions before operating on them.' This directly contrasts with sibling tools like tmux_create_session, tmux_kill_session, or tmux_rename_session, which are for operating on sessions after discovery.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/audibleblink/tmux-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server