# Agent hook integrations cmux uses agent hooks to show running state, Feed approvals, notifications, and to restore agent sessions after a normal app relaunch. Claude Code is handled by the cmux Claude wrapper when Claude Code integration is enabled in Settings. Other agents are installed with: ```bash cmux hooks setup cmux hooks setup cmux hooks setup --agent cmux hooks uninstall ``` Supported agent names are `codex`, `grok`, `opencode`, `pi`, `omp`, `campfire`, `amp`, `cursor`, `gemini`, `kiro`, `antigravity` (or `agy`), `rovodev` (or `rovo`), `hermes-agent`, `copilot`, `codebuddy`, `factory`, `qoder`, `kimi`, and `muse`. `cmux hooks setup` skips agents whose binary is not on `PATH` and prints a summary. ## Remote hosts In a `cmux ssh` or `cmux mosh-tmux` workspace that uses the CLI relay, Claude Code on the remote host reports running state, notifications, and its session ID for resume through the relay. The remote `claude` shim adds the hooks with `--settings`, so it also covers launchers that pick `claude` from `PATH` with their own config directory. Permission prompts stay in Claude on the remote host. Details are in [daemon/remote/README.md](../daemon/remote/README.md#claude-code-hooks). Claude sessions that did not start from a cmux shell, for example inside a tmux server that was already running before cmux attached to it, need the hooks in Claude's user settings instead. Run this once on the remote host, then restart those sessions: ```bash ~/.cmux/bin/cmux claude-hook install # writes ${CLAUDE_CONFIG_DIR:-~/.claude}/settings.json ~/.cmux/bin/cmux claude-hook uninstall # removes only the cmux entries ``` Inside tmux, these hooks report to the cmux workspace attached to the tmux session. ## Integrations | Agent | Binary checked | Installed file | Session restore | Feed bridge | | --- | --- | --- | --- | --- | | Claude Code | `claude` through wrapper | wrapper-injected settings | `claude --resume ` | PermissionRequest | | Codex | `codex` | `~/.codex/hooks.json`, `~/.codex/config.toml` | `codex resume ` | PreToolUse, PermissionRequest telemetry | | Grok | `grok` | `~/.grok/hooks/cmux-session.json` | `grok -r ` | PreToolUse | | OpenCode | `opencode` | `~/.config/opencode/plugins/cmux-session.js`, `~/.config/opencode/plugins/cmux-feed.js` | `opencode --session ` | plugin event bus | | Pi | `pi` | `~/.pi/agent/extensions/cmux-session.ts` | `pi --session ` | tool_execution_start / tool_execution_end telemetry | | OMP | `omp` | `~/.omp/agent/extensions/cmux-omp-session.ts`, or `$OMP_AGENT_DIR`/`$PI_CODING_AGENT_DIR` when set | `omp --session ` | none | | Campfire | `campfire` | `~/.campfire/agent/extensions/cmux-campfire-session.ts` or `$CAMPFIRE_CODING_AGENT_DIR/extensions/cmux-campfire-session.ts` | `campfire --session ` | none | | Amp | `amp` | `~/.config/amp/plugins/cmux-session.ts` | `amp threads continue ` | none | | Cursor CLI | `cursor-agent` | `~/.cursor/hooks.json` | `cursor-agent --resume ` | beforeShellExecution | | Gemini | `gemini` | `~/.gemini/settings.json` | `gemini --resume ` | PreToolUse | | Kiro CLI | `kiro-cli` | `~/.kiro/agents/cmux.json` or `$KIRO_HOME/agents/cmux.json`; with `--global` (Kiro CLI V3 only), `~/.kiro/hooks/cmux.json` or `$KIRO_HOME/hooks/cmux.json` | `kiro-cli chat --resume-id ` | preToolUse, postToolUse (agent config only) | | Rovo Dev | `acli` | `~/.rovodev/config.yml` | `acli rovodev run --restore ` | none | | Copilot | `copilot` | `~/.copilot/hooks/cmux.json` or `$COPILOT_HOME/hooks/cmux.json` | `copilot --resume ` | preToolUse | | CodeBuddy | `codebuddy` | `~/.codebuddy/settings.json` | `codebuddy --resume ` | PreToolUse | | Factory | `droid` | `~/.factory/settings.json` | `droid --resume ` | PreToolUse | | Qoder | `qodercli` | `~/.qoder/settings.json` | `qodercli --resume ` | PreToolUse | | Kimi Code | `kimi` | `~/.kimi-code/config.toml` or `~/.kimi/config.toml` | `kimi --resume ` | PreToolUse, PostToolUse | | Muse Code | `muse` | `~/.config/muse/settings.json` or `$XDG_CONFIG_HOME/muse/settings.json` | `muse resume ` | none | | Antigravity | `agy` | `~/.gemini/config/hooks.json` (`cmux` hook group) | `agy --conversation ` | none | Kimi Code resumes with the captured executable and working directory, preserving supported model and configuration options. Prompts, old session selectors, and noninteractive commands are omitted by the sanitizer described below. OpenCode also supports project-local Feed installation: ```bash cmux hooks opencode install --project ``` That writes `.opencode/plugins/cmux-feed.js` in the current directory. ## What the hooks record Session hooks write `~/.cmuxterm/-hook-sessions.json`. Each entry stores the agent session ID, cmux workspace ID, surface ID, cwd, process ID when available, current lifecycle (`running`, `idle`, `needsInput`, or `unknown`), and a sanitized launch command. On app relaunch, cmux rebuilds each workspace and runs the agent's native resume command with the saved session ID. The sanitizer preserves model, sandbox, config, and cwd-related flags. It drops prompts, credentials, old session selectors, and noninteractive commands so relaunch resumes the session instead of starting a new task or leaking secrets. Claude Code's `PushNotification` tool (model-initiated "notify the user now" pushes) is bridged through a `PostToolUse` hook into cmux notifications. The tool normally delivers via a raw OSC desktop notification, which cmux suppresses on surfaces running a hook-integrated agent, so the bridge is what makes those pushes visible inside cmux. It mirrors the tool's own outcome: a push the tool reports as skipped (user active, channel disabled) is not duplicated. Grok uses its `Notification` hook for user-facing completion messages. cmux records `Stop` as idle state, but leaves the visible notification text to the `Notification` payload so repeated turns keep Grok's own message instead of a generic completion fallback. ## Workspace auto-naming When the opt-in `automation.workspaceAutoNaming` setting is enabled, turn-end hooks also drive AI naming of workspaces and tabs. Supported adapters are Claude Code, Codex, Grok, OpenCode, Pi, and OMP; each adapter gates on the live setting over the socket, reuses the session store above for throttle state, summarizes with that agent's own CLI in a no-tools or isolated headless mode, and never overwrites a name the user set. Gemini, Amp, Cursor, Antigravity, Kiro, Rovo Dev, Hermes Agent, Copilot, CodeBuddy, Factory, and Qoder are skipped until they have both a verified conversation source and a safe cheap non-interactive summarizer runner. See [workspace-auto-naming.md](workspace-auto-naming.md). ## Agent Hibernation Agent Hibernation kills idle background agent processes to free their RAM and CPU, then resumes each one with its saved session when you return to its tab. Routine hibernation based on the live-terminal limit is opt-in and off by default. A separate safety path remains active under memory pressure, even when routine hibernation is off. cmux knows which process belongs to which terminal because the agent hooks associate each session ID with its surface (see the session-restore section above), so it can terminate the right process and bring back the right session. ### When a terminal hibernates For routine hibernation, a live terminal is only a candidate when all of these hold: - it has a saved restorable agent session, and the saved launch data can relaunch it the way it was started (a Claude session needs its captured launch arguments, so a `sr claude proxy` launch resumes through `sr`; a declared `agents.launchers` entry must still resolve) - the agent lifecycle is `idle` (not running, not waiting on input) - the terminal is in the background (its panel is not currently visible) - you have more live restorable agent terminals than the live-terminal limit (`maxLiveTerminals`, default `12`) - the terminal has had no output, input, or lifecycle change for at least the idle window (`idleSeconds`, default `5`) - the agent has no background work still running: no shell it started after launch is alive, and its Claude transcript shows no unfinished `run_in_background` command, Monitor, or async subagent The live-terminal limit is the first gate. Under the limit, nothing hibernates no matter how long it sits idle. Once you are over the limit, cmux frees only the oldest-idle background terminals, just enough to get back under the limit. Visible terminals are never touched. Before killing, cmux watches the terminal tail. It samples the last lines of output and a fingerprint of the process, and waits a short confirmation window (`confirmationSeconds`, ~60s) during which the output and process must stay unchanged. Any new output, input, lifecycle change, or PID change cancels the pending hibernation. This is why a small `idleSeconds` is safe: a freshly idle agent that resumes work on its own is never killed mid-task. So with the defaults, routine hibernation only affects power users running more than 12 agents at once, and even then only ~1 minute after an agent has gone quiet off-screen. ### Memory pressure Under memory pressure, cmux can run the same protected teardown path independently of the `enabled` setting and live-terminal limit. It runs on critical memory pressure (macOS reports critical pressure, which cmux holds for 120 s, or the cmux app process's own footprint reaches 16 GiB), and when cmux's total memory use (the cmux process and its descendants) passes its aggregate warning threshold, 50% of physical memory (see [configuration.md](configuration.md#aggregate-memory-pressure-safety-policy)). Each pass considers every eligible background agent; the live-terminal limit does not apply. The agent must still be restorable, off-screen, explicitly idle, free of unconfirmed input, stable through the confirmation window, and backed by a transcript cmux can protect. Visible, running, needs-input, recently changed, or unprotectable agents are never selected. Before signaling anything, cmux revalidates the exact process generation and workspace/surface scope. ### What gets killed and how it comes back cmux sends `SIGTERM` to the agent's process group (scoped to that workspace and surface), then swaps the live terminal for a lightweight placeholder, releasing the terminal's memory and CPU. When you visit the tab again, cmux runs the agent's native resume command with the saved session ID, so the session continues where it left off. The placeholder also shows a Resume button as a manual fallback. ### Hibernate or wake one agent ```bash cmux agent hibernate surface:3 # or: cmux agent-hibernation hibernate surface:3 cmux agent wake surface:3 ``` `hibernate` stops one agent now, whether or not routine hibernation is on. It skips the idle delay, the live-terminal limit and the confirmation window, and keeps every other check. The agent must be off screen and idle, with no unsent input and no background work. cmux still snapshots the transcript and revalidates the process before it signals anything. When a check fails, the command exits non-zero and says why. `wake` resumes a hibernated agent in place without moving focus. Both accept a surface UUID, a ref, or an index with `--workspace`, and `--json`. Over the socket they are `agent.hibernate` and `agent.wake` with `surface_id`. After a wake, cmux checks that the agent actually came back. The wake counts as working as soon as either the agent's own hooks report in for that terminal or a live process of that agent is found running in it (cmux looks every few seconds, which covers agents without hooks). If the resume command exits before either happens, or neither happens within 90 seconds, the terminal shows a banner saying the agent didn't resume, with **Retry** (types the resume command again), **Show command** (shows the command so you can copy it) and a close button. The workspace's sidebar row shows "Agent didn't resume" until the failure is retried, dismissed, or the agent reports in, and one entry is added to the notification feed. The sidebar row is not saved with the session. ### Enable and configure Enable routine hibernation from the command palette (`⌘⇧P` -> **Enable Agent Hibernation**), from **Settings > Terminal > Agent Hibernation**, or from the CLI: ```bash cmux agent-hibernation on cmux agent-hibernation off ``` Tune the idle window and live-terminal limit from Settings, or set them in `~/.config/cmux/cmux.json`: ```json { "terminal": { "agentHibernation": { "enabled": true, "idleSeconds": 5, "maxLiveTerminals": 12 } } } ``` - `idleSeconds` (default `5`, range `5`-`604800`): how long a background idle agent terminal must be quiet before it can hibernate. Raise it to keep agents alive longer; lower it to reclaim resources sooner. The `confirmationSeconds` settle window still applies on top of this. - `maxLiveTerminals` (default `12`, range `1`-`256`): how many live restorable agent terminals to keep before cmux hibernates the oldest idle background ones. Lower it to hibernate more aggressively; raise it to keep more agents live. ## Custom surface resume commands Use `cmux surface resume set --shell ` to attach a resume command to the current terminal surface. Public CLI and socket-created commands are kept for inspection and manual restore by default. To auto-run one on restore, set it from the terminal's **Resume Commands** context menu and approve the prompt, or change its signed command prefix in **Settings > Terminal > Resume Commands**. A CLI or socket request never shows that prompt; its reply carries `approval_required: true` when the command still needs approval in cmux. Approvals are prefix-based and signed by cmux. They also bind the working directory and exact environment values when present. A process can propose a command, but it cannot make that command sticky without the user choosing Auto-Restore or Ask Each Time in cmux. Agent hooks publish their own bindings with automatic resume already granted. A later `--source agent-hook` write for the same session that omits automatic resume (for example, an older Pi extension re-publishing through `cmux surface resume set`) does not downgrade that binding: cmux keeps the trusted binding and returns it as the result. ## Disable automatic resume To restore panes without automatically restarting saved agent sessions, turn off **Settings > Terminal > Resume Agent Sessions on Reopen**. You can also set the same preference in `~/.config/cmux/cmux.json`: ```json { "terminal": { "autoResumeAgentSessions": false } } ``` When this is off, cmux still restores the saved window, workspace, pane, scrollback, and browser state. Restored agent terminals stay idle until you resume them manually. ## Codex wrapper precedence When cmux launches Codex and at least one cmux event is not already covered by a persistent cmux handler in `hooks.json`, the wrapper adds `--enable hooks`, `--dangerously-bypass-hook-trust`, and one `-c hooks.=...` value per uncovered event, for that invocation only. When `cmux hooks codex install` has already installed every cmux handler, the wrapper adds nothing, which also keeps an intentional `features.hooks = false` intact. Codex discovers hooks per configuration layer and appends them from lowest to highest precedence: the user `hooks.json` and `[hooks]` table in `config.toml` (under `~/.codex` or `$CODEX_HOME`), a trusted project's `.codex/hooks.json` and `.codex/config.toml`, and finally the session flags cmux injects. A `-c hooks.=` value only defines that session-flags layer, so user and project handlers are registered before cmux's handler and nothing in `hooks.json` or `config.toml` is replaced or rewritten. Codex dispatches an event's handlers together and orders only their results, so nothing may depend on cmux's handler running first or last. cmux deliberately does not copy user handlers into its own value: Codex would discover the copy as a second handler and run it twice. This contract was verified by hand against codex-cli 0.146.0 and 0.153.4, and `tests/test_codex_wrapper_hook_append.py` repeats the check against the installed `codex` binary with a local fake model provider. Two trade-offs apply whenever the wrapper injects. `--dangerously-bypass-hook-trust` skips Codex's hook review for the whole process, so user and project handlers run without the trust prompt. Session flags form one layer, so a `-c hooks.=` value you pass to `codex` yourself is applied after cmux's and replaces cmux's handler for that event only; use `cmux hooks codex install` when you need both. Set `CMUX_CODEX_HOOKS_DISABLED=1` for a launch to keep Codex's configuration entirely untouched. This preserves user hook behavior and Codex's own trust review, but also disables cmux's Codex lifecycle registration, Feed and notification bridge, rebinding, and hibernation integration for that process. ## Environment overrides | Agent | Config directory override | Disable cmux hooks for one process | | --- | --- | --- | | Codex | `CODEX_HOME` | `CMUX_CODEX_HOOKS_DISABLED=1` | | Grok | `GROK_HOME` | `CMUX_GROK_HOOKS_DISABLED=1` | | OpenCode | `OPENCODE_CONFIG_DIR`, then `XDG_CONFIG_HOME`; `OPENCODE_DB`, then `XDG_DATA_HOME`, for the sessions database. A restored session replays these, `OPENCODE_CONFIG` and `XDG_STATE_HOME` when they are absolute paths | `CMUX_OPENCODE_HOOKS_DISABLED=1` | | Pi | `PI_CODING_AGENT_DIR` | `CMUX_PI_HOOKS_DISABLED=1` | | OMP | `OMP_AGENT_DIR` for the full agent directory, then `PI_CODING_AGENT_DIR`; otherwise `PI_CONFIG_DIR` for the config root | `CMUX_OMP_HOOKS_DISABLED=1` | | Campfire | `CAMPFIRE_CODING_AGENT_DIR` | `CMUX_CAMPFIRE_HOOKS_DISABLED=1` | | Amp | none | `CMUX_AMP_HOOKS_DISABLED=1` | | Cursor CLI | none | `CMUX_CURSOR_HOOKS_DISABLED=1` | | Gemini | none | `CMUX_GEMINI_HOOKS_DISABLED=1` | | Kiro CLI | `KIRO_HOME` | `CMUX_KIRO_HOOKS_DISABLED=1` | | Kimi Code | `KIMI_CODE_HOME`, `KIMI_SHARE_DIR` | `CMUX_KIMI_HOOKS_DISABLED=1` | | Muse Code | `XDG_CONFIG_HOME` | `CMUX_MUSE_HOOKS_DISABLED=1` stops the `muse` wrapper from installing hooks; Muse hides cmux variables from hooks, so run `cmux hooks muse uninstall` to turn installed hooks off | | Rovo Dev | none | `CMUX_ROVODEV_HOOKS_DISABLED=1` | | Copilot | `COPILOT_HOME` | `CMUX_COPILOT_HOOKS_DISABLED=1` | | CodeBuddy | `CODEBUDDY_CONFIG_DIR` | `CMUX_CODEBUDDY_HOOKS_DISABLED=1` | | Factory | none | `CMUX_FACTORY_HOOKS_DISABLED=1` | | Qoder | `QODER_CONFIG_DIR` | `CMUX_QODER_HOOKS_DISABLED=1` | | Antigravity | none | `CMUX_ANTIGRAVITY_HOOKS_DISABLED=1` | Muse Code runs hooks through the user's login shell with a cleared environment, so the cmux `muse` wrapper installs each hook as a `#!/bin/sh` script under `~/.cmux/hooks/muse/` that carries the installing cmux CLI and socket and finds the terminal from the Muse process, like Grok. Muse sessions appear in Vault from Muse's own `session-index.db`. Pi uses Pi's extension system, not the legacy Pi hooks API. The installed extension is auto-discovered from `~/.pi/agent/extensions/` or `$PI_CODING_AGENT_DIR/extensions/`. OMP uses OMP's native extension system. OMP native extension discovery scans `${PI_CODING_AGENT_DIR:-~/${PI_CONFIG_DIR:-.omp}/agent}/extensions/`, so cmux installs OMP's extension with a distinct `cmux-omp-session.ts` filename and does not reuse Pi's `cmux-session.ts`. Campfire ships this integration natively: current campfire versions include a built-in cmux bridge, so no install step is needed (like Claude Code via the cmux wrapper) — `cmux hooks campfire install` exists for older campfire versions, and the installed extension defers to the native bridge when both are present. Campfire embeds vanilla Pi under a `.campfire` white-label, so its extension discovery scans `${CAMPFIRE_CODING_AGENT_DIR:-~/.campfire/agent}/extensions/`. The cmux extension records only the HOST role (`CAMPFIRE_SESSION_ROLE=host`); a joiner is an ephemeral view whose argv carries the invite URL — a capability token that is never persisted or replayed. The extension also subscribes to campfire's in-process observer bridge and surfaces driver-actionable collaborative moments (a joiner waiting in the lobby, a capability ask) as cmux notifications. Kiro stores hooks inside agent configuration files. The cmux installer creates or updates a `cmux` agent config with lifecycle, tool, and completion hooks; merge the generated `hooks` block into another Kiro agent config if you want the same cmux notifications on that agent. Kiro CLI V3 (`kiro-cli --v3`) also loads [global hook files](https://kiro.dev/docs/configuration/) from `~/.kiro/hooks/` for every agent. `cmux hooks setup kiro --global` writes `cmux.json` there (under `$KIRO_HOME/hooks/` when `KIRO_HOME` is set, matching the agent config) with session start, prompt submit, stop and session end hooks, plus the [agent message](agent-messages.md) hooks, so V3 sessions report to cmux and receive messages without `--agent cmux`. `cmux hooks uninstall kiro --global` removes cmux's entries and deletes the file when nothing else is in it; `cmux hooks uninstall` without `--global` leaves it in place. The global file is for V3: Kiro CLI 2.x and earlier ignore that directory, so keep the default install and `--agent cmux` there. Outside a cmux terminal it does nothing. It has no Feed permission bridge, because a global `PreToolUse` hook would gate tools for every agent; Feed approvals still need `--agent cmux`. V3 adds a [SessionStart or UserPromptSubmit hook's stdout to the model context](https://kiro.dev/docs/hooks/actions/), and a [Stop hook's stdout can keep the agent working](https://kiro.dev/docs/hooks/types/). The lifecycle hooks therefore discard their output, the message hooks print only a waiting message, and every hook exits 0. V3 [merges hooks from every scope](https://kiro.dev/docs/configuration/), so with both installs a `--agent cmux` session on V3 can report each lifecycle event twice; setup prints a note when it finds both. Kiro Feed verbosity follows **Settings > Automation > Kiro Notification Level** or `automation.kiroNotificationLevel` in `cmux.json`. `minimal` keeps actionable approval cards only, `standard` also keeps mutating tool events, and `verbose` keeps every Kiro tool event. Kimi ships under two config layouts: Kimi Code CLI reads `${KIMI_CODE_HOME:-~/.kimi-code}/config.toml`, and Kimi CLI 1.49 and earlier read `${KIMI_SHARE_DIR:-~/.kimi}/config.toml`. cmux installs into the file the installed binary reports through `kimi doctor`; when the binary cannot answer, it installs into the first of those two locations that already exists, defaulting to the Kimi Code CLI path. The other location is never emptied by setup: an existing cmux block there is refreshed in place so a second Kimi install keeps working, and a config without a cmux block is left untouched. `cmux hooks uninstall kimi` removes the block from both. Unrelated TOML and third-party hooks are preserved everywhere. Antigravity (`agy`) hooks are written as the `cmux` group of `~/.gemini/config/hooks.json`. Each hook command first uses the cmux that owns the terminal the session runs in (`CMUX_BUNDLED_CLI_PATH` and `CMUX_SOCKET_PATH` from that terminal's environment), so sessions started from different cmux builds (stable, nightly, tagged dev builds) each report to their own app and restore correctly. When `agy` runs a hook without that environment, the command falls back to the cmux build that installed it. Re-run `cmux hooks agy install --yes` from an up-to-date cmux to refresh that fallback. ## Troubleshooting Run `cmux hooks install --yes` to reinstall one integration. Run `cmux hooks uninstall --yes` before editing generated files by hand. If Feed shows nothing, confirm the terminal has `CMUX_SURFACE_ID` and the hook file contains a `cmux hooks feed --source ` command, generated extension bridge, or OpenCode feed plugin. Pi reports non-blocking tool execution telemetry through its generated extension. OMP, Campfire, and Rovo Dev currently provide lifecycle and restore hooks only, so they do not create Feed approval cards. Amp's bundled plugin reports live tab-status updates (idle / thinking / running / reading / done / error / interrupted) and lifecycle restore but does not create Feed approval cards. If relaunch does not resume an agent, first run `cmux sessions --agent --json` to inspect the saved session without a running cmux socket. If needed, check `~/.cmuxterm/-hook-sessions.json` and verify the agent's resume command still works outside cmux.