Skip to main content
Glama

Send Keys to tmux Pane

tmux_send_keys

Send keyboard input or commands to tmux terminal panes for remote terminal automation and control.

Instructions

Send keys or commands to a tmux pane.

Args:

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

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

  • pane (number, optional): Pane index

  • keys (string, required): Keys or command to send

  • enter (boolean, optional): Press Enter after sending keys (default: true)

Examples:

  • Send a command: keys="ls -la", enter=true

  • Send text without executing: keys="echo hello", enter=false

  • Send special keys: keys="C-c" (Ctrl+C), keys="C-d" (Ctrl+D)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionYesName of the session
windowNoWindow index or name
paneNoPane index
keysYesKeys or command to send
enterNoPress Enter after sending keys

Implementation Reference

  • The handler function that sends the specified keys to the target tmux pane using the tmux 'send-keys' command. It handles targeting, key escaping, optional Enter press, execution via runTmux utility, and formats success/error responses.
    async ({ session, window, pane, keys, enter }) => {
      try {
        const target = formatTarget(session, window, pane);
        // Escape double quotes in keys
        const escapedKeys = keys.replace(/"/g, '\\"');
        let cmd = `send-keys -t "${target}" "${escapedKeys}"`;
        if (enter) {
          cmd += " Enter";
        }
        await runTmux(cmd);
    
        return {
          content: [{ type: "text", text: `Keys sent to ${target || "current pane"}: "${keys}"${enter ? " [Enter]" : ""}` }],
          structuredContent: { success: true, target, keys, enter },
        };
      } catch (error) {
        return {
          content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
          isError: true,
        };
      }
    }
  • Zod input schema defining the parameters for the tmux_send_keys tool: session (required string), window (optional string/number), pane (optional number), keys (required string), enter (optional boolean, default true).
    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"),
        pane: z.number().int().min(0).optional().describe("Pane index"),
        keys: z.string().min(1).describe("Keys or command to send"),
        enter: z.boolean().default(true).describe("Press Enter after sending keys"),
      })
      .strict(),
  • src/index.ts:576-631 (registration)
    The server.registerTool call that registers the tmux_send_keys tool with the MCP server, providing title, description, input schema, annotations, and the handler function.
    server.registerTool(
      "tmux_send_keys",
      {
        title: "Send Keys to tmux Pane",
        description: `Send keys or commands to a tmux pane.
    
    Args:
      - session (string, required): Name of the session
      - window (string or number, optional): Window index or name
      - pane (number, optional): Pane index
      - keys (string, required): Keys or command to send
      - enter (boolean, optional): Press Enter after sending keys (default: true)
    
    Examples:
      - Send a command: keys="ls -la", enter=true
      - Send text without executing: keys="echo hello", enter=false
      - Send special keys: keys="C-c" (Ctrl+C), keys="C-d" (Ctrl+D)`,
        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"),
            pane: z.number().int().min(0).optional().describe("Pane index"),
            keys: z.string().min(1).describe("Keys or command to send"),
            enter: z.boolean().default(true).describe("Press Enter after sending keys"),
          })
          .strict(),
        annotations: {
          readOnlyHint: false,
          destructiveHint: false,
          idempotentHint: false,
          openWorldHint: false,
        },
      },
      async ({ session, window, pane, keys, enter }) => {
        try {
          const target = formatTarget(session, window, pane);
          // Escape double quotes in keys
          const escapedKeys = keys.replace(/"/g, '\\"');
          let cmd = `send-keys -t "${target}" "${escapedKeys}"`;
          if (enter) {
            cmd += " Enter";
          }
          await runTmux(cmd);
    
          return {
            content: [{ type: "text", text: `Keys sent to ${target || "current pane"}: "${keys}"${enter ? " [Enter]" : ""}` }],
            structuredContent: { success: true, target, keys, enter },
          };
        } catch (error) {
          return {
            content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
            isError: true,
          };
        }
      }
    );
  • Utility function formatTarget used by the handler to construct the tmux target string (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;
    }
  • Utility function runTmux that executes tmux commands via child_process.exec, handles common errors with user-friendly messages, 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;
      }
    }
Behavior3/5

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

Annotations already declare this is not read-only, not open-world, not idempotent, and not destructive. The description adds useful context about the 'enter' parameter behavior (pressing Enter after sending keys) and provides examples of special key sequences like 'C-c' for Ctrl+C, which goes beyond what annotations provide.

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 well-structured with clear sections (purpose, Args, Examples) and front-loaded with the core functionality. The examples are helpful but slightly verbose. Every sentence serves a purpose, though the Args section somewhat duplicates schema information.

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

Completeness4/5

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

For a tool with 5 parameters, 100% schema coverage, and comprehensive annotations, the description provides adequate context. The examples cover common use cases, and the tool's purpose is clear. Without an output schema, the description doesn't need to explain return values, making it reasonably complete for this complexity level.

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%, so the schema already documents all parameters thoroughly. The description adds minimal value beyond the schema - it lists parameters in the Args section but doesn't provide additional semantic context. The examples illustrate parameter usage but don't add new information about parameter meaning.

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 ('Send keys or commands') and target resource ('to a tmux pane'). It distinguishes from sibling tools like tmux_capture_pane (which reads output) and tmux_kill_pane (which destroys panes) by focusing on input transmission to panes.

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

Usage Guidelines3/5

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

The description implies usage for sending input to tmux panes, but doesn't explicitly state when to use this tool versus alternatives like tmux_create_session for session creation or tmux_select_pane for navigation. The examples provide some context but no explicit guidance on tool selection.

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