capture-pane
Extract text content from tmux terminal panes with configurable line counts and optional color formatting for AI-assisted terminal session analysis.
Instructions
Capture content from a tmux pane with configurable lines count and optional color preservation
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| paneId | Yes | ID of the tmux pane | |
| lines | No | Number of lines to capture | |
| colors | No | Include color/escape sequences for text and background attributes in output |
Implementation Reference
- src/index.ts:137-167 (handler)Primary handler and registration for the 'capture-pane' MCP tool. Defines the tool name, description, input schema, and execution logic which parses inputs and delegates to tmux.capturePaneContent helper.server.tool( "capture-pane", "Capture content from a tmux pane with configurable lines count and optional color preservation", { paneId: z.string().describe("ID of the tmux pane"), lines: z.string().optional().describe("Number of lines to capture"), colors: z.boolean().optional().describe("Include color/escape sequences for text and background attributes in output") }, async ({ paneId, lines, colors }) => { try { // Parse lines parameter if provided const linesCount = lines ? parseInt(lines, 10) : undefined; const includeColors = colors || false; const content = await tmux.capturePaneContent(paneId, linesCount, includeColors); return { content: [{ type: "text", text: content || "No content captured" }] }; } catch (error) { return { content: [{ type: "text", text: `Error capturing pane content: ${error}` }], isError: true }; } } );
- src/index.ts:140-144 (schema)Zod input schema for capture-pane tool: paneId (string, required), lines (optional string for number of lines), colors (optional boolean for including color sequences).{ paneId: z.string().describe("ID of the tmux pane"), lines: z.string().optional().describe("Number of lines to capture"), colors: z.boolean().optional().describe("Include color/escape sequences for text and background attributes in output") },
- src/tmux.ts:154-157 (helper)Core helper function implementing the tmux capture-pane command execution. Supports custom line count (default 200) and optional color inclusion via -e flag.export async function capturePaneContent(paneId: string, lines: number = 200, includeColors: boolean = false): Promise<string> { const colorFlag = includeColors ? '-e' : ''; return executeTmux(`capture-pane -p ${colorFlag} -t '${paneId}' -S -${lines} -E -`); }