Skip to main content
Glama

tmux_kill_window

Terminate a specific tmux window and its running processes by specifying the session name and window identifier.

Instructions

Kill (close) a window in a tmux session.

Args:

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

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

WARNING: This will terminate all processes running in the window.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionYesName of the session
windowYesWindow index or name

Implementation Reference

  • The core handler function for the tmux_kill_window tool. It constructs the tmux target from session and window identifiers, executes the 'tmux kill-window' command using the runTmux helper, and returns success/error responses.
    async ({ session, window }) => {
      try {
        const target = formatTarget(session, window);
        await runTmux(`kill-window -t "${target}"`);
    
        return {
          content: [{ type: "text", text: `Window '${window}' in session '${session}' killed successfully.` }],
          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 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:362-402 (registration)
    Full registration of the tmux_kill_window tool with McpServer, including name, metadata, schema, annotations, and handler reference.
    server.registerTool(
      "tmux_kill_window",
      {
        title: "Kill tmux Window",
        description: `Kill (close) a window in a tmux session.
    
    Args:
      - session (string, required): Name of the session
      - window (string or number, required): Window index or name
    
    WARNING: This will terminate all processes running in the window.`,
        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: true,
          idempotentHint: true,
          openWorldHint: false,
        },
      },
      async ({ session, window }) => {
        try {
          const target = formatTarget(session, window);
          await runTmux(`kill-window -t "${target}"`);
    
          return {
            content: [{ type: "text", text: `Window '${window}' in session '${session}' killed successfully.` }],
            structuredContent: { success: true, session, window },
          };
        } catch (error) {
          return {
            content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
            isError: true,
          };
        }
      }
    );
  • Helper function used by the handler to format 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 helper utility to execute tmux commands asynchronously, with custom error messages for common tmux failures.
    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