Add a Stop button over terminals while an agent turn runs

Closed
TE
1mo ago
+7204-4207

Summary

First slice of #15223 (clickable agent actions). With Settings > Terminal > Agent Stop Button on (agentActions.turnControl, off by default), a small Stop pill sits in a terminal pane's bottom-trailing corner while Claude Code or Codex is running a turn in that pane. Clicking it interrupts the turn.

  • When it shows: the pane's journaled lifecycle says claude_code or codex is running, the same state the TextBox checks before it forwards Escape. Other agents get no button until their interrupt key is verified. Toggling the setting mid-turn shows or hides the pill at once; it listens for defaults changes only while an agent is running.
  • What a click does: sends one Escape through TerminalPanel.sendNamedKeyResult, the named-key path the TextBox and mobile.chat.interrupt already use. The click is re-checked against the current lifecycle first, so a late click after the turn ended sends nothing.
  • Leaving running: Claude Code runs no Stop hook when a turn is interrupted (#4389), so the pane would keep showing Running and the button would stay up. After sending Escape, cmux asks the agent journal to settle every Claude session its own fold has running on that surface: each gets a turnCompleted event (AgentJournalEventDraft.userInterrupt, native event cmux.user_interrupt) with no notification, so no "done" alert fires. Settling from the fold rather than the hook store means nested claude -p sessions and relayed sessions are handled correctly. If Claude keeps working, its next PreToolUse hook declares the pane running again. Codex is not settled this way: it journals lifecycle only at prompt submit and Stop, so a settle could leave a still-working Codex pane idle.
  • One Escape per click: Stop holds for 1.5 s after a click. A second Escape at Claude's idle prompt would open its rewind menu.
  • Known limit: a Claude background shell that outlives the interrupt is not counted as pending work, so the pane reads idle while it runs. Hibernation's process checks and idle interval still apply.
  • Where it lives: TerminalAgentTurnControlView, an AppKit overlay mounted in GhosttySurfaceScrollView beside the password-input badge and raised above the find overlay. Only the button takes clicks; the rest of the overlay passes hit-testing through to the terminal. Workspace and Dock lifecycle writes both refresh it.
  • Settings: a new agentActions section in the catalog, cmux.json ({"agentActions": {"turnControl": true}}), the schema, and settings search. Later categories from the RFC add one key each.

Testing

  • swift test --package-path Packages/macOS/CmuxAgentJournal --filter AgentJournalUserInterruptTests (local, 3 passed): turnStarted, interrupt, turnStarted gives running, idle with no notification identity, then running, for claude and codex; the fold's interrupt drafts cover only live running sessions on the surface (including a session without an id) and settle it to idle without touching another surface.
  • swift test --package-path Packages/macOS/CmuxSettings --filter SettingCatalogTests (local, passed): the key defaults off and matches its section prefix.
  • cmuxTests/TerminalAgentTurnControlTests.swift (added, runs in CI): the pill shows only while enabled and running, hides mid-turn when the setting turns off, stays hidden by default, two quick Stop clicks enqueue exactly one key event, and a click after the agent stopped enqueues none. A journal-center test checks that recordUserInterrupt journals the interrupt for the session the center has running on the surface.
  • python3 tests/test_cmux_settings_supported_paths.py (local, passed).
  • python3 scripts/verify-local.py: 15/15 selected checks passed (localization parity, xcstrings, schema, project and test wiring).
  • scripts/ui-test AgentActionPillUITests at 6c11b3e5 (run, both tests passed): with the setting on, journaling an agent.turn.started for a Claude Code session on a terminal over the socket shows the Stop pill; clicking it hides the pill, so the interrupt settled the turn. With the setting off, the same event shows no pill. The turn is journaled directly, so a live Claude process was not interrupted.

Changelog

Added: An optional Stop button over a terminal interrupts a running Claude Code or Codex turn (Settings > Terminal > Agent Stop Button).

Demo Video

Captured by cmuxUITests/AgentActionPillUITests in CI run 36425803310 at 6c11b3e5 (shell prompt blanked). Running, then after clicking Stop:

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added an optional Agent Stop Button setting. When enabled, a Stop button appears in the terminal while Claude Code or Codex is working; clicking it sends the agent’s interrupt key.
    • Added localized setting labels and configuration help across supported languages.