# tmux focus-events for Claude Code: what it does

What set -g focus-events on does in tmux, why it is in Claude Code's recommended tmux config, how to check it, and why it needs a reattach.

Source: https://hivemux.dev/guides/tmux-focus-events-claude-code/

> focus-events on makes tmux ask the terminal for focus in/out events and pass them to the programs in its panes. It is one of the four lines Anthropic's docs give for Claude Code in tmux, and Claude Code mods need it to draw images. After setting it, detach and reattach tmux; source-file alone does not reach clients already attached.

Anthropic's [terminal configuration page](https://code.claude.com/docs/en/terminal-config#configure-tmux) gives four lines to add to `~/.tmux.conf` when Claude Code runs inside tmux. Three of them are explained there. The fourth, `focus-events`, is not. This page explains what the option does in tmux, where Claude Code's docs actually rely on it, and how to confirm it is active. For the wider tmux setup, see [How to use Claude Code with tmux](/guides/claude-code-tmux/).

## What focus-events does in tmux

A terminal can report when its window gains or loses focus, for example when you switch to a browser and back. These reports are escape sequences, so tmux sits in the middle. The tmux manual describes the server option like this: when enabled, focus events are requested from the terminal if supported and passed through to applications running in tmux.

So with the option off, a program in a tmux pane never learns that you left the terminal. With it on, tmux both asks the terminal for the events and forwards them to the pane. The manual also lists the `pane-focus-in` and `pane-focus-out` hooks, which run only if `focus-events` is on.

## The recommended block for Claude Code

These are the lines from Anthropic's docs, with what each one does:

```sh
set -g allow-passthrough on
set -g focus-events on
set -s extended-keys on
set -as terminal-features 'xterm*:extkeys'
```

- `allow-passthrough on`: lets programs in a pane bypass tmux with an escape sequence. Anthropic's docs say this is what lets notifications and progress updates reach the outer terminal. Per the tmux manual, `on` allows it only for a visible pane, `all` also for hidden ones.
- `focus-events on`: tmux requests focus events from the terminal and passes them to programs in panes. Anthropic's docs list it as a requirement, alongside passthrough, for a [mod's `Image`](https://code.claude.com/docs/en/plugins/mods/gallery#draw-an-image-inside-tmux) to draw inside tmux.
- `extended-keys on`: lets the program in the pane request extended key reporting for keys pressed with Control, Meta or Shift. Anthropic's docs say the extended-keys lines let tmux tell Shift+Enter from Enter.
- `terminal-features 'xterm*:extkeys'`: tells tmux that terminals matching `xterm*` support extended keys.

What the docs do not say is that `focus-events` changes when Claude Code notifies you. Its notifications fire "when you appear to be away from the terminal", and the hooks reference times that by keystrokes: about six seconds without typing for a permission prompt, about 60 seconds for an idle prompt. If notifications are missing, the cause is usually elsewhere; [Claude Code notifications not working](/guides/claude-code-notifications-not-working/) goes through it by symptom.

## Turn it on and check it

Add the line to `~/.tmux.conf`, or set it on the running server:

```sh
tmux set -g focus-events on
```

Then check the value:

```sh
tmux show -g focus-events
```

It should print `focus-events on`. Because it is a server option, `tmux show -s focus-events` prints the same.

Now the step most people miss. The tmux manual says attached clients should be detached and attached again after changing this option, so `tmux source-file ~/.tmux.conf` alone is not enough for a terminal that is already attached:

```sh
# inside tmux: prefix d to detach, then
tmux attach
```

Anthropic's docs add, for mod images, to restart Claude Code after reattaching, and to restart it again whenever you attach tmux from a different terminal.

To see whether the terminal itself offers focus reporting, look at the features tmux recorded for your client:

```sh
tmux display -p '#{client_termfeatures}'
```

`focus` in the list means tmux sees focus reporting for that terminal.

## How hivemux uses focus

hivemux is a tmux sidebar that shows every Claude Code session — running, waiting for you, or done — and lets you jump to the one that needs you. Its tmux config sets `focus-events on` along with passthrough (`all`) and extended keys, so after `hivemux setup` you do not add it yourself.

hivemux then asks tmux which attached terminal currently has focus and uses that in three places:

- **Notifications.** When a task starts waiting or finishes, the sidebar skips the notification if that task's window is on the terminal that has focus. You are already looking at it.
- **Done becomes seen.** A finished task changes to idle only when its window is on the focused terminal, not on a screen that is merely attached, such as another Mac.
- **Window size.** When two screens show the same session, the one that got keyboard focus last decides the window size, through tmux's `client-focus-in` hook.

Install with `curl -fsSL https://hivemux.dev/install.sh | bash` or `brew install hivemux/tap/hivemux`, then run `hivemux setup`. If you use Ghostty, [Claude Code in Ghostty with tmux](/guides/claude-code-ghostty/) covers the terminal side.

## FAQ

### Does my terminal need to support focus events?

Yes. The tmux manual says focus events are requested from the terminal if supported. Run tmux display -p '#{client_termfeatures}' inside tmux; if the list contains focus, tmux sees focus reporting for that terminal. If it does not, the option is on but no events arrive.

### Do I need to restart tmux after turning on focus-events?

No full restart, but source-file is not enough. The tmux manual says attached clients should be detached and attached again after changing this option. Press prefix d, then tmux attach. Anthropic's docs also say to restart Claude Code for features that rely on it.

### Does focus-events change when Claude Code sends notifications?

Anthropic's docs do not say so. They describe notifications as firing when you appear to be away, timed by keyboard inactivity: about six seconds for a permission prompt, about 60 seconds after a finished reply. For missing notifications, check allow-passthrough first.

### Does focus-events work over ssh?

Set it on the tmux that runs Claude Code, which is the remote one when you ssh in. Focus reports are escape sequences the terminal sends on its input, the same way keystrokes travel.
