has_session
Check existence of a named tmux session to confirm it can be targeted by capture_pane, send_keys, or kill_session.
Instructions
Check whether a named tmux session exists. Cheap precondition for capture_pane, send_keys, or kill_session.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Session name. Cannot contain ".", ":", "|", or whitespace. |
Implementation Reference
- server.js:102-110 (handler)The main handler function for the 'has_session' tool. It validates tmux availability, validates the session name, runs 'tmux has-session -t =<name>' and returns whether the session exists based on the exit code.
async function hasSession(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, ['has-session', '-t', `=${args.name}`]); // `=name` asks tmux for an exact match. Exit 0 = exists, 1 = no such session. return textResult({ name: args.name, exists: r.code === 0 }); } - server.js:241-253 (schema)The tool registration metadata including name, description, annotations, and inputSchema (requires a 'name' string property).
{ name: 'has_session', description: 'Check whether a named tmux session exists. Cheap precondition for capture_pane, send_keys, or kill_session.', annotations: { title: 'Check session exists', readOnlyHint: true, destructiveHint: false, openWorldHint: false }, inputSchema: { type: 'object', properties: { name: { type: 'string', description: 'Session name. Cannot contain ".", ":", "|", or whitespace.' }, }, required: ['name'], additionalProperties: false, }, }, - server.js:326-334 (registration)The HANDLERS map that registers the 'has_session' function to be called when the tool 'has_session' is invoked.
const HANDLERS = { list_sessions: listSessions, has_session: hasSession, list_windows: listWindows, capture_pane: capturePane, new_session: newSession, send_keys: sendKeys, kill_session: killSession, };