Skip to content

Focus the exact cmux surface for Claude sessions - #11

Merged
fdussert merged 3 commits into
fdussert:mainfrom
FlorianBruniaux:codex/cmux-session-focus
Oct 15, 2026
Merged

fdussert merged 3 commits into
fdussert:mainfrom
FlorianBruniaux:codex/cmux-session-focus

Conversation

@FlorianBruniaux

@FlorianBruniaux FlorianBruniaux commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Touching a Claude session in cmux used to activate the application without selecting its panel. Fremkit now reads validated workspace and surface IDs from the live process and asks the bundled cmux CLI to focus that panel. If socket policy denies the command or the panel is gone, it activates cmux. A session launched in VS Code, iTerm2 or Terminal from a cmux shell follows its actual TERM_PROGRAM instead of inherited cmux IDs.

The helper runs outside cmux. I verified that cmux ping from this environment is denied under the current socket policy, so exact panel selection requires a socket mode allowing external clients. The documentation explains the restriction and its security tradeoff. The hook itself does not send cmux IDs; the server reads them from the live process.

Related fork issue: FlorianBruniaux#19

Checks

  • pnpm typecheck, pnpm test (1,366 server and 385 UI tests) and pnpm build pass after rebase.
  • Tests cover validated IDs, application fallback and inherited cmux variables from other terminal clients.
  • The socket denial was reproduced locally. Exact-panel behavior under an externally permissive socket mode was not exercised on the XENEON.

@fdussert fdussert mentioned this pull request Oct 15, 2026
5 tasks done

@fdussert fdussert left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this — landing on the exact cmux surface instead of just fronting the app is a nice touch, and the UUID validation before anything reaches an argument list is exactly right.

A few things before it can go in:

  1. Which cmux version handles cmux://workspace/<id>/surface/<id>? The cmux 0.62.2 bundle I checked only declares http/https in CFBundleURLTypes, and I couldn't find a cmux:// handler in the binary. Could you point to the cmux docs for this scheme, or confirm you tested it by hand? Otherwise cmux ships an AppleScript dictionary (focus on a terminal by id); passed through on run argv, that would match the Terminal/iTerm2 path in this file. The bundled CLI (cmux focus-panel --panel <id> --workspace <id>) would work too.

  2. If open fails here (server/src/claude/focus.ts, around line 200), the exception reaches the outer catch and the card says failed. The Orca and tty paths fall back to fronting the application instead. Could this branch do the same (catch → focusApp(CMUX_BUNDLE, runner)), and only report how: 'pane' when the surface was actually selected?

  3. For a session with no hook-reported bundle id, the cmux check now runs before the Orca handle and the process-tree walk. A process that inherited CMUX_* (VS Code launched with code . from a cmux shell, for instance) will be sent to cmux. Could the cmux route require TERM_PROGRAM/__CFBundleIdentifier to agree, or at least yield to ORCA_TERMINAL_HANDLE? Reusing the first clientOfProcess result would also save the second pair of ps calls.

  4. Please add a cmux row to the client table in docs/claude-code.md, and move the CHANGELOG line under ### Added/### Changed (or fold it into the existing "go to the session" entry). #10, #12 and #13 add a loose bullet at the same spot, so expect a small rebase.

@fdussert

Copy link
Copy Markdown
Owner

Thanks for the quick turnaround, Florian! The bundled CLI is a much better route: fixed argument list, validated UUIDs, a fallback to fronting cmux, and Orca now wins over an inherited handle. Points 1, 2 and 4 are done.

Three small things left:

  1. cmux's socket control setting (cmuxOnly / allowAll / password / …) only lets processes started inside cmux talk to the socket in cmuxOnly mode. The Fremkit server is spawned by the helper, not by cmux, so if that is the default, focus-panel is refused and we always land on the app fallback. Did you test it with cmux's default settings? If a setting has to change, please say so in docs/claude-code.md next to the cmux row.
  2. __CFBundleIdentifier is inherited the same way CMUX_* is: VS Code started with code . from a cmux shell passes both to its integrated terminal, so the case from the first review still goes to cmux. Could the cmux route also yield when TERM_PROGRAM names another known client (vscode, iTerm.app, Apple_Terminal)? A test with that environment would pin it.
  3. docs/claude-code.md says the hook reports cmux workspace and surface ids, but scripts/claude-hook.sh doesn't send them, so client.cmux is never filled by a hook. Either add them to the hook or drop that sentence (and please rewrap the line). The PR description still mentions the URL, too.

Thanks again!

@FlorianBruniaux
FlorianBruniaux force-pushed the codex/cmux-session-focus branch from a062d1a to 1e2eb34 Compare October 15, 2026 15:30
@fdussert

Copy link
Copy Markdown
Owner

Thanks for the quick turnaround, Florian! All three points are covered, and the socket-mode note in the docs is exactly what users need. The only thing left is a rebase on main: CHANGELOG.md conflicts with lines that landed today (#17 and others) under ### Added. Once that's in, this is good to merge.

@FlorianBruniaux
FlorianBruniaux force-pushed the codex/cmux-session-focus branch from 1e2eb34 to 07d5184 Compare October 15, 2026 16:01

@fdussert fdussert left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Florian — rebased cleanly, and the socket-access wording in the changelog is a nice touch. Merging (squash).

@fdussert

Copy link
Copy Markdown
Owner

Sorry Florian — #13 and #16 landed just before this one and the CHANGELOG.md lines under ### Added collide again. It's approved; one more rebase on main and I'll merge it right away.

FlorianBruniaux and others added 3 commits October 15, 2026 18:15
Read validated workspace and surface IDs from the live Claude process before opening cmux, so touching a session selects its panel instead of merely activating the app.

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Use known TERM_PROGRAM values before selecting a cmux panel. Document the socket access limitation and the application fallback.

Co-Authored-By: Claude <noreply@anthropic.com>
@FlorianBruniaux
FlorianBruniaux force-pushed the codex/cmux-session-focus branch from 07d5184 to b4dbca0 Compare October 15, 2026 16:16
@fdussert
fdussert merged commit 3cc18db into fdussert:main Oct 15, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants