send_keys
Send key combos or literal text to a tmux session's active pane, useful for interrupts, end-of-input, or typing commands. Enter appended by default; set enter=false for raw combos.
Instructions
Send key combos or text to the session's active pane. Use for interrupts (C-c), end-of-input (C-d), or typing a command. Text is sent literally. Enter is appended by default; set enter=false for raw key combos.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Session name. | |
| keys | Yes | Key combo (e.g. "C-c", "C-d", "Escape") or literal text to type. | |
| enter | No | Append an Enter keypress after the keys. Default true. |
Implementation Reference
- server.js:197-215 (handler)The sendKeys function implements the 'send_keys' tool logic. It validates inputs (tmux availability, session name, keys), constructs a tmux send-keys command targeting the session's active pane, optionally appends an Enter keypress (default true), executes it via spawn, and returns success/failure.
// ─── Tool: send_keys ────────────────────────────────────────────────────── async function sendKeys(args) { const missing = requireTmux(); if (missing) return errorResult(missing); const bad = validSessionName(args.name); if (bad) return errorResult(bad); if (typeof args.keys !== 'string' || !args.keys.length) { return errorResult('keys is required (non-empty string)'); } // When `enter` is true (default for text input), append an Enter keypress. // For raw key combos like 'C-c' you usually want enter=false. const appendEnter = args.enter !== false; // `=NAME:` targets the session's active pane with exact name match. const cmd = ['send-keys', '-t', `=${args.name}:`, args.keys]; if (appendEnter) cmd.push('Enter'); const r = await run(BIN.tmux, cmd); if (r.code !== 0) return errorResult(`tmux send-keys failed: ${r.stderr || r.stdout}`); return textResult({ session: args.name, keys: args.keys, enter: appendEnter }); } - server.js:296-310 (schema)The input schema for 'send_keys' tool registration. Defines the expected parameters: name (string, required), keys (string, required), and enter (boolean, optional, default true). Includes description, annotations, and additionalProperties: false.
{ name: 'send_keys', description: 'Send key combos or text to the session\'s active pane. Use for interrupts (C-c), end-of-input (C-d), or typing a command. Text is sent literally. Enter is appended by default; set enter=false for raw key combos.', annotations: { title: 'Send keys to session', readOnlyHint: false, destructiveHint: true, openWorldHint: true }, inputSchema: { type: 'object', properties: { name: { type: 'string', description: 'Session name.' }, keys: { type: 'string', description: 'Key combo (e.g. "C-c", "C-d", "Escape") or literal text to type.' }, enter: { type: 'boolean', description: 'Append an Enter keypress after the keys. Default true.' }, }, required: ['name', 'keys'], additionalProperties: false, }, }, - server.js:326-333 (registration)The HANDLERS map that registers the sendKeys function under the key 'send_keys'. This is used by the tools/call dispatcher to route incoming requests.
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:49-64 (helper)The run function is a helper that spawns a child process and returns stdout/stderr/exit code. Used by sendKeys to execute 'tmux send-keys ...' via spawn.
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'), })); }); }