list_sessions
List all tmux sessions with window count, timestamps, and attached status; returns empty list if no server is running.
Instructions
List all tmux sessions on the current user's tmux server. Returns name, window count, created/activity timestamps (ISO 8601), and attached status. Returns an empty list when no tmux server is running.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- server.js:77-99 (handler)The main handler function for the list_sessions tool. Runs 'tmux list-sessions' with a custom format, parses the output (name, windows, created_at, last_activity_at, attached), and returns a list of sessions. Returns an empty list when no tmux server is running.
async function listSessions() { const missing = requireTmux(); if (missing) return errorResult(missing); const fmt = '#{session_name}|#{session_windows}|#{session_created}|#{session_attached}|#{session_activity}'; const r = await run(BIN.tmux, ['list-sessions', '-F', fmt]); // "no server running" is the normal empty-state response, not an error. if (r.code !== 0) { if (/no server running/i.test(r.stderr)) return textResult({ sessions: [] }); return errorResult(`tmux list-sessions failed: ${r.stderr || r.stdout}`); } const sessions = r.stdout.split('\n').filter(Boolean).map((line) => { const [name, windows, created, attached, activity] = line.split('|'); return { name, windows: parseInt(windows, 10), created_at: Number(created) ? new Date(Number(created) * 1000).toISOString() : null, last_activity_at: Number(activity) ? new Date(Number(activity) * 1000).toISOString() : null, attached: attached === '1', }; }); return textResult({ count: sessions.length, sessions }); } - server.js:235-240 (schema)The tool registration schema for list_sessions. Defines the tool name, description, annotations (read-only, non-destructive), and input schema (empty object, no parameters).
{ name: 'list_sessions', description: 'List all tmux sessions on the current user\'s tmux server. Returns name, window count, created/activity timestamps (ISO 8601), and attached status. Returns an empty list when no tmux server is running.', annotations: { title: 'List tmux sessions', readOnlyHint: true, destructiveHint: false, openWorldHint: false }, inputSchema: { type: 'object', properties: {}, additionalProperties: false }, }, - server.js:327-327 (registration)The handler registration mapping, binding 'list_sessions' to the listSessions function.
list_sessions: listSessions,