Add terminal.claudeResumeMode to auto-answer Claude Code's resume prompt

RU
2mo ago
+743-3

Summary

What? Adds a terminal.claudeResumeMode setting (ask | full | summary, default ask) that lets cmux answer Claude Code's compacted-session resume prompt for you when it auto-resumes an agent.

Why? When cmux auto-resumes a compacted Claude Code session (claude --resume <id>), Claude shows an interactive menu:

Resuming the full session will consume a substantial portion of your usage limits. We recommend resuming from a summary.
❯ 1. Resume from summary (recommended)
  2. Resume full session as-is
  3. Don't ask me again

There is no Claude Code CLI flag or config to skip this (verified against the current Claude Code release), so today you have to hand-pick an option every time cmux restores your panes. This adds a cmux-side setting to drive that menu — the natural home, since cmux owns the pane and already auto-resumes the session.

Behavior

  • ask (default) — unchanged: the prompt is left for you. This is a complete no-op; nothing is armed.
  • full — cmux selects Resume full session as-is.
  • summary — cmux selects Resume from summary.

How it works:

  • Armed only from Workspace.createPanel when a Claude agent is being auto-resumed (restorableAgent.kind == .claude and a resume command/input will run) and the mode isn't .ask.
  • A short, hibernation-style poll (ClaudeResumeAutoResponderController, modeled on AgentHibernationController) reads the pane's rendered text via the existing TerminalSurface.readText and, when the menu appears, sends the keys via the existing TerminalSurface.sendNamedKey (so libghostty encodes the right sequence for the pane's cursor mode).
  • One-shot and bounded: it fires at most once per resume, then disarms; if the menu never appears (session wasn't compacted) it gives up after a short watch window.

Design

  • Pure logic, unit-tested: ClaudeResumeMode (SettingCodable enum, mirrors WorkspaceGroupNewPlacement) and ClaudeResumePrompt (detection + keystroke planning) live in CmuxSettings with no AppKit/ghostty deps. Detection is label-based; selection is option-order independent (it finds the target row and the currently-highlighted row by pointer glyph, then moves to it), so it keeps working if the menu is reordered, and falls back to "first row highlighted" when no glyph is rendered.
  • Thin integration: the controller + the one-line arm in createPanel are the only app-side glue.
  • Fail-safe: detection requires Claude's specific option labels, so if a future Claude release changes that wording the responder simply never fires and the prompt stays interactive — no wrong key is sent. Default ask means zero behavior change unless opted in.

Wired through the usual surfaces: Settings → Terminal Picker (CmuxSettingsUI), settings search index + curated entry, cmux.json schema + template + JSON-path support, and the file-store parser.

Testing

  • Added CmuxSettingsTests/ClaudeResumeModeTests.swift covering: tolerant raw-string parsing + UserDefaults/JSON round-trips; prompt detection (present/absent); keystroke planning for the default menu, a reordered menu, and a no-pointer menu; and the one-shot responder (waits for the menu, fires once, never double-fires, inert in ask).
  • The detection/keystroke logic was exercised directly and all assertions pass.

Checklist

  • Added tests for the behavior change (CmuxSettingsTests)
  • Default (ask) preserves existing behavior
  • Swift file-length budget updated for the touched files
  • Demo video — N/A (a setting + a menu responder; covered by unit tests)

View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.


Summary by cubic

Adds terminal.claudeResumeMode (ask | full | summary) to auto-answer Claude Code’s compacted-session resume menu when cmux auto-resumes a Claude agent. Default is ask; the responder is one‑shot, retries until keys are accepted, and ignores stale menu text.

  • New Features

    • Terminal setting/picker for terminal.claudeResumeMode; searchable and localized; added to schema (with descriptionKey), template, JSON‑path, and file‑store parsing. Strict enum parsing (ask/full/summary only); non‑string or invalid values are logged.
    • Auto-responder for Claude auto-resumes (restorable snapshots and agent‑hook resume bindings): detection requires all three option labels; uses the latest contiguous menu block and ignores stale blocks; pointer-aware and option‑order independent. Bounded round‑robin polling with capped reads; pending responders are bounded until a pane goes live, then watched briefly; retries until keystrokes are accepted, then disarms; one‑shot; safe no‑op if the menu never appears. Wired into Workspace.createPanel.
    • Unit tests cover strict parsing, prompt detection (all labels, stale‑block handling), keystroke planning (default, reordered, no‑pointer), and one‑shot with delivery confirmation.
  • Migration

    • No action needed; default is ask.
    • To auto-select, set terminal.claudeResumeMode to full or summary in Settings → Terminal or in cmux.json.

Summary by CodeRabbit

  • New Features
    • Added a new “Claude Resume Prompt” Terminal setting to control how cmux handles Claude Code’s compacted-session resume prompt during restore/auto-resume.
    • Includes modes: Ask, Full, and Summary.
  • UI / Configuration
    • Exposed in settings with searchable indexing, persisted as terminal.claudeResumeMode, and included in the default template and configuration schema.
  • Automation
    • When set to Full or Summary, cmux can automatically select the appropriate resume option once.
  • Tests
    • Added tests for mode parsing, prompt detection/keystroke selection, and one-shot responder behavior.