tmux_kill_session
Terminate a tmux session and all its windows/panes by specifying the session name. This action stops all processes running in the session.
Instructions
Kill (terminate) a tmux session and all its windows/panes.
Args:
name (string, required): Name of the session to kill
WARNING: This will terminate all processes running in the session.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Name of the session to kill |
Implementation Reference
- src/index.ts:235-248 (handler)The handler function for the tmux_kill_session tool. It takes a session name, runs the tmux kill-session command using the runTmux helper, and returns success or error responses.async ({ name }) => { try { await runTmux(`kill-session -t "${name}"`); return { content: [{ type: "text", text: `Session '${name}' killed successfully.` }], structuredContent: { success: true, session: name }, }; } catch (error) { return { content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }], isError: true, }; } }
- src/index.ts:223-227 (schema)Zod input schema defining the required 'name' parameter (string) for the session to be killed.inputSchema: z .object({ name: z.string().min(1).describe("Name of the session to kill"), }) .strict(),
- src/index.ts:213-249 (registration)Registration of the tmux_kill_session tool with the MCP server, specifying metadata, schema, annotations, and handler function.server.registerTool( "tmux_kill_session", { title: "Kill tmux Session", description: `Kill (terminate) a tmux session and all its windows/panes. Args: - name (string, required): Name of the session to kill WARNING: This will terminate all processes running in the session.`, inputSchema: z .object({ name: z.string().min(1).describe("Name of the session to kill"), }) .strict(), annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false, }, }, async ({ name }) => { try { await runTmux(`kill-session -t "${name}"`); return { content: [{ type: "text", text: `Session '${name}' killed successfully.` }], structuredContent: { success: true, session: name }, }; } catch (error) { return { content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }], isError: true, }; } } );
- src/index.ts:45-68 (helper)Shared utility function used by tmux_kill_session (and other tools) to run tmux commands with custom error handling for common issues like missing sessions.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; } }