fix(compat): take the basename of the whole ps comm path - #771
Open
cattyneo wants to merge 1 commit into
Open
Conversation
`ps -o comm=` prints the full executable path on macOS. Piping it through `xargs basename` word-splits that path, so `basename` receives the part before the first space as NAME and the rest as SUFFIX. The Claude Code desktop app always installs its CLI under `~/Library/Application Support/Claude/claude-code/<ver>/...`, so `compat_get_comm` returned `Application` there. `agmsg_pid_is_agent` then never matched, `agmsg_agent_pid` walked past the agent up to launchd and failed, the instance id degraded to a bare session id, `cc-instance.<pid>` was never written, and every actas lock was GC'd as stale on the next `session-start.sh` — silently, while the watcher stayed alive and kept delivering. Take the basename of the whole string instead. Paths without spaces behave as before; paths that `xargs` would have choked on (quotes) now work too, and an unknown pid returns non-zero rather than an empty string. Scope: the POSIX branch only. The msys branch has the same `xargs basename` shape at compat.sh:96, which `C:\Program Files\...` would hit, but that is untested here. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
cattyneo
force-pushed
the
fix/macos-comm-path-with-spaces
branch
from
August 13, 2026 13:08
444cd71 to
3118ea5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #770.
What
compat_get_comm's POSIX branch pipedps -o comm=throughxargs basename. On macOSps -o comm=prints the full executable path, andxargssplits it on whitespace — sobasenamegot the part before the first space asNAMEand the remainder asSUFFIX:The Claude Code desktop app always installs its CLI under
~/Library/Application Support/Claude/claude-code/<ver>/claude.app/Contents/MacOS/claude, so every desktop-app session resolved its agent toApplication.agmsg_pid_is_agentnever matched,agmsg_agent_pidwalked straight past the agent to launchd and returned 1, the instance id degraded to a bare session id,cc-instance.<pid>was never written, andactas_lock_gc_stalethen removed the lock on the nextsession-start.shfrom any other session — with the watcher still alive and still delivering, so nothing surfaced.Full analysis, the consequence chain with line numbers, and a same-machine control (space-free installs on the same host resolve correctly) are in #770.
How
Take the basename of the whole string:
Behaviour changes only where the old form was already wrong:
/usr/local/bin/claudeclaudeclaude(unchanged)/Users/u/Library/Application Support/.../claudeApplicationclaude/opt/it's here/claudeclaude--guards a path starting with-.Scope
POSIX branch only.
compat.sh:96(msys,/proc/<pid>/cmdline) has the samexargs basenameshape andC:\Program Files\...would hit it, but I have no Windows environment to test on, so I left it alone rather than ship an untested change. Happy to extend the PR if you want it. (:109readsawk '{print $NF}', which is already whitespace-split, so it is unaffected.)agmsg_pid_is_agent'sawk '{print $1}'onps -o args=has the same weakness, but withcommfixed it is a fallback that is not normally reached — also left alone.Tests
tests/test_compat_posix.bats, 5 tests, skipped on MSYS (the msys branch stays covered bytest_compat.bats).Four stubbed-
pstests are deterministic on any POSIX host: space in the path, quote in the path, no-space regression guard, and unknown pid. A fifth test does not use the stub — it symlinks the realsleepunder a directory with a space, runs it, and checks the realpsagainstcompat_get_comm, so the stub's premise is verified against the platform rather than assumed. Wherepsreports a bare comm instead of a path (Linux) that test skips with a message, because the splitting path is unreachable there.(A copy of
/bin/sleeprather than a symlink does not work for that test on macOS: the copy is SIGKILLed for an invalid code signature andpsthen reports nothing, which made the test skip for the wrong reason.)Break-test contrast on macOS 15.5:
bats tests/full suite on macOS 15.5: 912 tests, 0 failures, 12 skipped (exit 0).