Skip to content

Export CMUX_SOCKET alongside CMUX_SOCKET_PATH in terminal env - #1991

Merged
lawrencecchen merged 2 commits into
manaflow-ai:mainfrom
anthhub:fix/export-cmux-socket-env
Mar 25, 2026
Merged

lawrencecchen merged 2 commits into
manaflow-ai:mainfrom
anthhub:fix/export-cmux-socket-env

Conversation

@anthhub

@anthhub anthhub commented Mar 23, 2026 •

Copy link
Copy Markdown

Summary

  • The app only exported CMUX_SOCKET_PATH when setting up terminal environment variables, but some hooks (e.g. claude-hook stop) look for CMUX_SOCKET
  • The CLI launcher code already exports both (cmux.swift:9288-9289), but the app-side terminal setup in GhosttyTerminalView.swift was missing the CMUX_SOCKET alias
  • Now both CMUX_SOCKET_PATH and CMUX_SOCKET are set in the terminal environment, consistent with the CLI launcher

Test plan

  • Build with ./scripts/reload.sh --tag fix-socket-env
  • Open a terminal in cmux, run echo $CMUX_SOCKET — should show the socket path (was empty before)
  • Run echo $CMUX_SOCKET_PATH — should still show the same socket path
  • Start a Claude Code session, end it — cmux claude-hook stop should no longer report 'TabManager not available'

Fixes #1905

🤖 Generated with Claude Code


Summary by cubic

Exports CMUX_SOCKET alongside CMUX_SOCKET_PATH in app-launched terminals and caches the socket path to avoid redundant lookups; this matches the CLI and restores compatibility with scripts expecting CMUX_SOCKET (e.g., cmux claude-hook stop). Fixes #1905.

  • Bug Fixes
    • Sets CMUX_SOCKET_PATH and its alias CMUX_SOCKET from a cached SocketControlSettings.socketPath() in GhosttyTerminalView.swift.
    • Preserves both env vars for backward compatibility.

Written for commit cdb7ea4. Summary will update on new commits.

Summary by CodeRabbit

  • Bug Fixes
    • Improved compatibility with legacy scripts and third-party integrations by supplying a backward-compatible environment variable alias for the socket path at startup.
    • Made startup behavior more consistent by computing and applying the socket path once, reducing the chance of mismatched or missing socket references.

The app only exported CMUX_SOCKET_PATH when setting up the terminal
environment, but some scripts and hooks (e.g. claude-hook) expect
CMUX_SOCKET. The CLI launcher code already exports both (cmux.swift
lines 9288-9289), but the app-side terminal setup was missing the
alias. This caused claude-hook stop to fail with 'TabManager not
available' when CMUX_SOCKET was empty.

Fixes manaflow-ai#1905

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Mar 23, 2026

Copy link
Copy Markdown

@anthhub is attempting to deploy a commit to the Manaflow Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Mar 23, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3e59df7b-7256-48ed-938a-3ec991a9a357

📥 Commits

Reviewing files that changed from the base of the PR and between 497bf1e and cdb7ea4.

📒 Files selected for processing (1)
  • Sources/GhosttyTerminalView.swift
🚧 Files skipped from review as they are similar to previous changes (1)
  • Sources/GhosttyTerminalView.swift

📝 Walkthrough

Walkthrough

TerminalSurface's managed startup environment now computes the socket path once and sets both CMUX_SOCKET_PATH and a backward-compatible CMUX_SOCKET environment variable to that value during injection.

Changes

Cohort / File(s) Summary
Environment Variable Injection
Sources/GhosttyTerminalView.swift
Compute SocketControlSettings.socketPath() into a local socketPath and inject it as both CMUX_SOCKET_PATH (existing) and CMUX_SOCKET (new alias) in the managed startup environment. No other keys or control flow changed.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I found a path beneath the log,
I nudged a name to match the tag,
Two names now share one little bog,
Hooks hum softly, no more snag. 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and accurately describes the main change: exporting CMUX_SOCKET alongside CMUX_SOCKET_PATH in terminal environment variables.
Description check ✅ Passed The description covers the core requirements (what changed, why) and includes a test plan, but lacks some optional template sections like demo video and bot review requests.
Linked Issues check ✅ Passed The PR directly addresses issue #1905 by adding CMUX_SOCKET to the terminal environment, enabling hooks like cmux claude-hook stop to contact TabManager without encountering unavailability errors.
Out of Scope Changes check ✅ Passed All changes are scoped to the linked objective: computing socketPath once and setting both CMUX_SOCKET_PATH and CMUX_SOCKET environment variables in GhosttyTerminalView.swift.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 1 file

@greptile-apps

greptile-apps Bot commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a missing environment variable in the terminal session setup by exporting CMUX_SOCKET alongside the existing CMUX_SOCKET_PATH, making the app-side terminal environment consistent with what the CLI launcher already sets.

  • The CLI launcher (cmux.swift lines 9288–9289, 9333–9334) has always exported both CMUX_SOCKET_PATH and CMUX_SOCKET; the app-side GhosttyTerminalView.swift was only exporting CMUX_SOCKET_PATH, causing hooks like claude-hook stop that read CMUX_SOCKET to silently get an empty value and fail with "TabManager not available"
  • The one-line fix correctly mirrors the existing pattern and is consistent with how the CLI already resolves the socket (reading CMUX_SOCKET_PATH first, then falling back to CMUX_SOCKET at multiple call sites)
  • Minor: SocketControlSettings.socketPath() is called twice; caching it in a local let would be cleaner

Confidence Score: 5/5

  • Safe to merge — minimal, targeted change with no logic risk and clear precedent in the CLI launcher.
  • The change is a single setManagedEnvironmentValue call that mirrors an identical pattern already present in the CLI launcher. There is no branching, no new logic, and no side-effects beyond adding an environment variable alias. The only open item is a non-blocking style suggestion to cache socketPath() in a local variable.
  • No files require special attention.

Important Files Changed

Filename Overview
Sources/GhosttyTerminalView.swift Adds CMUX_SOCKET as an alias for CMUX_SOCKET_PATH in the terminal environment setup, bringing it in line with the CLI launcher which already exports both. Only stylistic concern: SocketControlSettings.socketPath() is called twice instead of being cached in a local variable.

Sequence Diagram

sequenceDiagram
    participant App as GhosttyTerminalView
    participant Env as Terminal Environment
    participant Hook as claude-hook stop
    participant CLI as cmux CLI

    App->>Env: setManagedEnvironmentValue("CMUX_SOCKET_PATH", socketPath())
    Note over App,Env: existed before this PR
    App->>Env: setManagedEnvironmentValue("CMUX_SOCKET", socketPath())
    Note over App,Env: added by this PR

    Hook->>Env: read CMUX_SOCKET
    Env-->>Hook: socket path (was empty before fix)
    Hook->>CLI: connect to socket
    CLI-->>Hook: TabManager available ✓
Loading

Reviews (1): Last reviewed commit: "Export CMUX_SOCKET alongside CMUX_SOCKET..." | Re-trigger Greptile

Comment thread Sources/GhosttyTerminalView.swift Outdated
Comment on lines +3335 to +3337
setManagedEnvironmentValue("CMUX_SOCKET_PATH", SocketControlSettings.socketPath())
// Backward-compatible alias expected by older scripts and third-party integrations.
setManagedEnvironmentValue("CMUX_SOCKET", SocketControlSettings.socketPath())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Double call to socketPath() — consider caching the result

SocketControlSettings.socketPath() is called twice in consecutive lines. While it's deterministic and lightweight today, caching the result in a local let keeps the two assignments provably identical and avoids any future drift if the function ever becomes non-trivial.

Suggested change
setManagedEnvironmentValue("CMUX_SOCKET_PATH", SocketControlSettings.socketPath())
// Backward-compatible alias expected by older scripts and third-party integrations.
setManagedEnvironmentValue("CMUX_SOCKET", SocketControlSettings.socketPath())
let socketPath = SocketControlSettings.socketPath()
setManagedEnvironmentValue("CMUX_SOCKET_PATH", socketPath)
// Backward-compatible alias expected by older scripts and third-party integrations.
setManagedEnvironmentValue("CMUX_SOCKET", socketPath)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@lawrencecchen
lawrencecchen merged commit bc9f884 into manaflow-ai:main Mar 25, 2026
3 of 4 checks passed
@lawrencecchen

Copy link
Copy Markdown
Contributor

Thank you for the contribution!

@coderabbitai coderabbitai Bot mentioned this pull request Apr 1, 2026
5 tasks
bn-l pushed a commit to bn-l/cmux that referenced this pull request Apr 3, 2026
…ow-ai#1991)

* Export CMUX_SOCKET alongside CMUX_SOCKET_PATH in terminal environment

The app only exported CMUX_SOCKET_PATH when setting up the terminal
environment, but some scripts and hooks (e.g. claude-hook) expect
CMUX_SOCKET. The CLI launcher code already exports both (cmux.swift
lines 9288-9289), but the app-side terminal setup was missing the
alias. This caused claude-hook stop to fail with 'TabManager not
available' when CMUX_SOCKET was empty.

Fixes manaflow-ai#1905

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Cache socketPath to avoid redundant call

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

cmux claude-hook stop fails with 'TabManager not available' even when running inside cmux

2 participants