kill_session
Terminate a named tmux session, ending all processes inside with SIGHUP. Use to stop long-running jobs or cleanup unused sessions.
Instructions
Terminate a named tmux session. Any processes running inside are sent SIGHUP by tmux. Errors if the session does not exist.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Session name. |
Implementation Reference
- server.js:218-231 (handler)The kill_session tool handler: async function killSession(args) that validates tmux availability, validates the session name, runs 'tmux kill-session -t =<name>', handles 'session not found' errors, and returns a success result with killed: true.
async function killSession(args) { const missing = requireTmux(); if (missing) return errorResult(missing); const bad = validSessionName(args.name); if (bad) return errorResult(bad); const r = await run(BIN.tmux, ['kill-session', '-t', `=${args.name}`]); if (r.code !== 0) { if (/can't find session|session not found/i.test(r.stderr)) { return errorResult(`session "${args.name}" does not exist`); } return errorResult(`tmux kill-session failed: ${r.stderr || r.stdout}`); } return textResult({ session: args.name, killed: true }); } - server.js:311-323 (schema)Tool registration entry for kill_session with name, description, annotations (destructiveHint: true), and inputSchema requiring a 'name' string property.
{ name: 'kill_session', description: 'Terminate a named tmux session. Any processes running inside are sent SIGHUP by tmux. Errors if the session does not exist.', annotations: { title: 'Kill tmux session', readOnlyHint: false, destructiveHint: true, openWorldHint: false }, inputSchema: { type: 'object', properties: { name: { type: 'string', description: 'Session name.' }, }, required: ['name'], additionalProperties: false, }, }, - server.js:326-334 (registration)The HANDLERS map that wires the string 'kill_session' to the killSession function for JSON-RPC dispatch.
const HANDLERS = { list_sessions: listSessions, has_session: hasSession, list_windows: listWindows, capture_pane: capturePane, new_session: newSession, send_keys: sendKeys, kill_session: killSession, }; - server.js:69-74 (helper)validSessionName helper used to validate the session name argument before proceeding with kill-session.
function validSessionName(name) { if (typeof name !== 'string' || !name.length) return 'name is required (non-empty string)'; if (name.length > 100) return 'name too long (max 100)'; if (/[.:\s|]/.test(name)) return "name cannot contain '.', ':', '|', or whitespace"; return null; } - server.js:49-64 (helper)The run() utility that spawns a child process (used to execute tmux kill-session) and returns stdout/stderr/exit code.
function run(cmd, args, opts = {}) { return new Promise((resolve) => { const child = spawn(cmd, args, { stdio: ['pipe', 'pipe', 'pipe'], ...opts }); let out = Buffer.alloc(0); let err = Buffer.alloc(0); child.stdout.on('data', (d) => { out = Buffer.concat([out, d]); }); child.stderr.on('data', (d) => { err = Buffer.concat([err, d]); }); child.on('error', (e) => resolve({ code: -1, stdout: '', stderr: e.message })); child.stdin.end(); child.on('close', (code) => resolve({ code, stdout: out.toString('utf8'), stderr: err.toString('utf8'), })); }); }