Inject login-shell PATH into spawned subprocesses#18
Merged
nickdirienzo merged 1 commit intomainfrom Apr 28, 2026
Merged
Conversation
GUI-launched Flight (Sparkle/Finder) inherits launchd's stripped PATH (`/usr/bin:/bin:/usr/sbin:/sbin`), so `/usr/bin/env claude` silently exits 127 every turn and `.flight/worktree-setup` can't find `pnpm`. The user-visible symptom was "messages die"; the actual error sat in an undrained stderr pipe. Capture the user's interactive login-shell PATH via `zsh -ilc` once at app launch (interactive — `~/.local/bin` and language-version managers typically live in `.zshrc`, not `.zprofile`), apply it to every `Process.environment`. Drain stderr from `claude` into the per-worktree log so future failures are visible. On clean non-zero exits, fire a metadata-only Sentry capture (command + exit code + correlation UUID written to the local log) — stderr stays on-box since CLI tool errors can carry credentials. Tests pin the invariant that subprocesses inherit `EnvironmentService.path`, keyed off `runScriptStreaming` (uses `zsh -s`, no rc-file mutation). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
/usr/bin:/bin:/usr/sbin:/sbin).ClaudeAgentspawns/usr/bin/env claudeandWorktreeSetupServicerunspnpm installviazsh -s, neither of which loaded the user's actual PATH — soclaudesilently exited 127 every turn andpnpm installcouldn't findpnpm. Fromflight-fast-ray-9916.log: two>>> STDINwrites, zero stdout, no errors anywhere.EnvironmentServicecaptures the user's PATH viazsh -ilc 'printf %s "$PATH"'once at app launch (using-ilcnot-lcbecause~/.local/binand language-version managers typically live in.zshrc, not.zprofile). All threeShellServicespawn paths and bothClaudeAgentspawn branches now setprocess.environment = EnvironmentService.baseEnvironment(...).ClaudeAgentnow drains stderr into its per-worktree log (<<< STDERR: ...) so the next time something like this happens we see the actual error. On clean non-zero exits (reason == .exit && exitCode != 0), fires a metadata-only Sentry event via a newSentryServicebridge — sends only command + exit code + correlation UUID. Stderr stays on-box because CLI tools can include credentials in error output..uncaughtSignalexits (user-pressed-stop SIGINT, our own SIGTERM teardown) are intentionally skipped.Tests/FlightAppTests/EnvironmentInheritanceTests.swiftpins the invariant that spawned subprocesses inheritEnvironmentService.path, keyed offrunScriptStreaming(useszsh -s, no rc-file mutation, so the assertion is exact).Test plan
swift test --filter EnvironmentInheritanceTests— all 3 pass./build.sh— clean buildFlight.app, openedflight/fast-ray-9916, sent a message; log went 4 → 7 lines, claude responded with a session_id and a normal assistant replypnpm installresolves in a fresh worktree on a Sparkle-launched Flight (thefast-elm-2629reproducer)🤖 Generated with Claude Code