Skip to main content
Glama

tmux_split_window

Split terminal windows into panes to run multiple commands simultaneously. Configure split direction, size, and starting directory for efficient multitasking.

Instructions

Split a window into panes.

Args:

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

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

  • horizontal (boolean, optional): Split horizontally (default: false = vertical split)

  • start_directory (string, optional): Starting directory for the new pane

  • percentage (number, optional): Size of new pane as percentage (1-99)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionYesName of the session
windowNoWindow index or name
horizontalNoSplit horizontally (default: vertical)
start_directoryNoStarting directory for the new pane
percentageNoSize of new pane as percentage

Implementation Reference

  • The handler function that implements the core logic of tmux_split_window by constructing and executing the appropriate tmux split-window command using helpers formatTarget and runTmux.
    async ({ session, window, horizontal, start_directory, percentage }) => {
      try {
        const target = formatTarget(session, window);
        let cmd = `split-window -t "${target}"`;
        if (horizontal) {
          cmd += " -h";
        }
        if (start_directory) {
          cmd += ` -c "${start_directory}"`;
        }
        if (percentage) {
          cmd += ` -p ${percentage}`;
        }
        await runTmux(cmd);
    
        return {
          content: [{ type: "text", text: `Window split ${horizontal ? "horizontally" : "vertically"} successfully.` }],
          structuredContent: { success: true, session, window, horizontal },
        };
      } catch (error) {
        return {
          content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
          isError: true,
        };
      }
    }
  • Zod input schema defining parameters for the tmux_split_window tool: session (required), window (optional), horizontal (default false), start_directory (optional), percentage (1-99 optional).
    inputSchema: z
      .object({
        session: z.string().min(1).describe("Name of the session"),
        window: z.union([z.string(), z.number()]).optional().describe("Window index or name"),
        horizontal: z.boolean().default(false).describe("Split horizontally (default: vertical)"),
        start_directory: z.string().optional().describe("Starting directory for the new pane"),
        percentage: z.number().min(1).max(99).optional().describe("Size of new pane as percentage"),
      })
      .strict(),
  • src/index.ts:472-526 (registration)
    Registration of the tmux_split_window tool with McpServer, including metadata, schema, and handler reference.
    server.registerTool(
      "tmux_split_window",
      {
        title: "Split tmux Window",
        description: `Split a window into panes.
    
    Args:
      - session (string, required): Name of the session
      - window (string or number, optional): Window index or name
      - horizontal (boolean, optional): Split horizontally (default: false = vertical split)
      - start_directory (string, optional): Starting directory for the new pane
      - percentage (number, optional): Size of new pane as percentage (1-99)`,
        inputSchema: z
          .object({
            session: z.string().min(1).describe("Name of the session"),
            window: z.union([z.string(), z.number()]).optional().describe("Window index or name"),
            horizontal: z.boolean().default(false).describe("Split horizontally (default: vertical)"),
            start_directory: z.string().optional().describe("Starting directory for the new pane"),
            percentage: z.number().min(1).max(99).optional().describe("Size of new pane as percentage"),
          })
          .strict(),
        annotations: {
          readOnlyHint: false,
          destructiveHint: false,
          idempotentHint: false,
          openWorldHint: false,
        },
      },
      async ({ session, window, horizontal, start_directory, percentage }) => {
        try {
          const target = formatTarget(session, window);
          let cmd = `split-window -t "${target}"`;
          if (horizontal) {
            cmd += " -h";
          }
          if (start_directory) {
            cmd += ` -c "${start_directory}"`;
          }
          if (percentage) {
            cmd += ` -p ${percentage}`;
          }
          await runTmux(cmd);
    
          return {
            content: [{ type: "text", text: `Window split ${horizontal ? "horizontally" : "vertically"} successfully.` }],
            structuredContent: { success: true, session, window, horizontal },
          };
        } catch (error) {
          return {
            content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
            isError: true,
          };
        }
      }
    );
  • Helper function used by the handler to construct the tmux target string (e.g., session:window.pane).
    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;
    }
  • Core utility function used by all tmux tools, including tmux_split_window, to execute tmux commands asynchronously with custom error messages.
    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;
      }
    }

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