Skip to main content
Glama

Select tmux Window

tmux_select_window
Idempotent

Switch to a specific window in a tmux session by specifying the session name and window identifier to manage terminal workflows.

Instructions

Switch to a specific window in a tmux session.

Args:

  • session (string, required): Name of the session

  • window (string or number, required): Window index or name

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionYesName of the session
windowYesWindow index or name

Implementation Reference

  • The handler function for the tmux_select_window tool. It formats the target using formatTarget, runs the tmux select-window command via runTmux, and returns success or error response.
    async ({ session, window }) => {
      try {
        const target = formatTarget(session, window);
        await runTmux(`select-window -t "${target}"`);
    
        return {
          content: [{ type: "text", text: `Switched to window '${window}' in session '${session}'.` }],
          structuredContent: { success: true, session, window },
        };
      } catch (error) {
        return {
          content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
          isError: true,
        };
      }
    }
  • Zod input schema defining required parameters: session (string) and window (string or number).
    inputSchema: z
      .object({
        session: z.string().min(1).describe("Name of the session"),
        window: z.union([z.string(), z.number()]).describe("Window index or name"),
      })
      .strict(),
  • src/index.ts:698-736 (registration)
    Registers the tmux_select_window tool with the MCP server using server.registerTool, providing name, metadata (title, description, schema, annotations), and handler function.
    server.registerTool(
      "tmux_select_window",
      {
        title: "Select tmux Window",
        description: `Switch to a specific window in a tmux session.
    
    Args:
      - session (string, required): Name of the session
      - window (string or number, required): Window index or name`,
        inputSchema: z
          .object({
            session: z.string().min(1).describe("Name of the session"),
            window: z.union([z.string(), z.number()]).describe("Window index or name"),
          })
          .strict(),
        annotations: {
          readOnlyHint: false,
          destructiveHint: false,
          idempotentHint: true,
          openWorldHint: false,
        },
      },
      async ({ session, window }) => {
        try {
          const target = formatTarget(session, window);
          await runTmux(`select-window -t "${target}"`);
    
          return {
            content: [{ type: "text", text: `Switched to window '${window}' in session '${session}'.` }],
            structuredContent: { success: true, session, window },
          };
        } catch (error) {
          return {
            content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
            isError: true,
          };
        }
      }
    );
  • Shared utility function to execute tmux commands asynchronously with execAsync and custom error messages for common tmux issues.
    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;
      }
    }
  • Shared utility function to construct tmux target strings in the format 'session:window.pane' from parameters.
    function formatTarget(session?: string, window?: number | string, pane?: number): string {
      let target = "";
      if (session) {
        target = session;
        if (window !== undefined) {
          target += `:${window}`;
          if (pane !== undefined) {
            target += `.${pane}`;
          }
        }
      }
      return target;
    }
Behavior3/5

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

Annotations already indicate this is a non-destructive, idempotent operation (destructiveHint: false, idempotentHint: true), which the description doesn't contradict. However, the description adds minimal behavioral context beyond annotations—it doesn't explain what 'switching' entails (e.g., visual focus change, no data loss) or potential errors (e.g., invalid session/window).

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

Conciseness4/5

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

The description is front-loaded with the core purpose in one clear sentence, followed by a structured Args section. It's appropriately sized with no redundant information, though the Args section could be omitted since it duplicates the schema without added value.

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

Completeness3/5

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

Given the tool's low complexity (2 parameters, no output schema) and rich annotations, the description is minimally adequate. However, it lacks context on usage scenarios, error handling, or visual effects of switching windows, which would help an agent use it correctly in a tmux workflow.

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

Parameters3/5

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

Schema description coverage is 100%, with both parameters clearly documented in the schema. The description's Args section repeats this information without adding meaningful semantics (e.g., format examples for window names vs. indices, session naming conventions). Baseline 3 is appropriate as the schema carries the full burden.

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 ('Switch to') and resource ('a specific window in a tmux session'), distinguishing it from siblings like tmux_select_pane (selects pane) or tmux_list_windows (lists windows). It precisely communicates the tool's function without ambiguity.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing an active tmux session), exclusions, or comparisons to siblings like tmux_create_window (for creating new windows) or tmux_list_windows (for viewing available windows).

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