#329: Detect 'mcs sync' run from Claude home scope#330
Merged
Conversation
- Add `Environment.isInsideClaudeHome` — triggers on cwd/path inside `~/.claude` or equal to `$HOME`, gated on the `.claude.json` sibling existing - Guard in `SyncCommand.perform` silently redirects when `--global` is set, hard-errors on `--pack`/`--all`, prompts otherwise - Extract `effectiveTargetURL` and shared `makeClaudeHome` test helper; add 17 unit tests
- Treat --dry-run and closed/non-TTY stdin as non-interactive — hard-error instead of silently accepting askYesNo's default=true - Warn on chdir failure and announce cwd switch when --global redirects from ~/.claude - Improve error messages and add tests for non-interactive bare-sync and --dry-run paths
bguidolim
added a commit
that referenced
this pull request
Apr 19, 2026
- Annotates Environment.swift and SyncCommand.swift index entries with the new `isInsideClaudeHome(_:)` / `guardClaudeHomeCwd()` APIs from #330 - Adds a troubleshooting section covering the prompt, hard-error, and silent-redirect paths users hit when running `mcs sync` from `~/.claude` or `$HOME`
bguidolim
added a commit
that referenced
this pull request
Apr 19, 2026
* #328: Delta-aware picker + confirmation for mcs sync - Picker renders cursor-contextual tags (installed/uncheck/WILL REMOVE/new/will install), dynamic footer verbs, and a live +/- counter so users see which toggles add or remove packs. - Review screen with add/remove/keep summary appears before any removals and requires explicit y (default: false) before mutation. - Extract ANSIStyle, PickerDelta, and SyncDeltaSummary as pure, unit-tested helpers; reframe picker header copy. * Address #332 review: non-TTY guard, full-wipe prompt, palette unification - Non-TTY guard at top of interactiveConfigure throws ExitCode.failure with --pack/--all hint; prevents piped-stdin silent no-ops. - Full-wipe case (SyncDeltaSummary.isFullWipe) emits a warn and switches prompt copy to "Remove all configured packs?" before the destructive confirmation. - ANSIStyle becomes the canonical palette (now includes bold/cyan/blue); CLIOutput's private color vars delegate. DeltaCounts struct deleted. renderReviewBlock converted to instance method. Test assertions tightened with golden strings. * Document SyncDeltaSummary.swift in CLAUDE.md - Adds the new file to the Sync/ section inventory so future sessions find it alongside the rest of the convergence engine * Document #330 claude-home guard in CLAUDE.md + troubleshooting - Annotates Environment.swift and SyncCommand.swift index entries with the new `isInsideClaudeHome(_:)` / `guardClaudeHomeCwd()` APIs from #330 - Adds a troubleshooting section covering the prompt, hard-error, and silent-redirect paths users hit when running `mcs sync` from `~/.claude` or `$HOME` * Address Copilot review: decouple stdin/stdout predicates; fix unchanged count - Split CLIOutput predicates: hasInteractiveStdin (stdin TTY) gates prompts; isInteractiveTerminal (both TTYs) gates raw picker UI. Previously both were coupled to colorsEnabled, breaking mcs sync > out.log even with interactive stdin. - Non-TTY guard in interactiveConfigure now uses hasInteractiveStdin so piped-stdout-with-TTY-stdin falls through to the working fallback picker + readline prompt. - Include .notInstalled rows in the "unchanged" counter so additions + removals + unchanged equals total rows shown; the label's truth value no longer depends on baseline install state.
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.
Context
Running
mcs syncfrom~/.claudeor from$HOMEitself silently syncs project artifacts into the global Claude scope — creating~/.claude/.claude/junk, writingsettings.local.jsoninstead ofsettings.json, and leavingdoctorunable to recognize the install.ProjectDetectorreturns nil in that location so the sync "succeeds" and the user believes the global install worked.Fixes #329.
Changes
Environment.isInsideClaudeHome(_:)— returns true whencandidateis insideclaudeDirectoryor equal tohomeDirectory, gated on the.claude.jsonsibling existing to confirm a real Claude Code layout. The sibling check prevents false positives in test fixtures where$HOMEpoints to a tmp dir that happens to contain.claude/.SyncCommand.guardClaudeHomeCwd(env:output:)at the top ofperform():--globalalready set → silent chdir to$HOME, proceed--pack/--all(non-interactive) → hard error, exit failure--global; yes flips and chdir's, no hard-errorsglobalflag (rather than mutatingself.global) becauseLockedCommand.run()snapshotsselfbefore callingperform().path ?? cwdidiom intoeffectiveTargetURL, reused byperformProject.makeClaudeHometest helper inTestHelpers.swift.Acceptance Criteria
cd ~/.claude && mcs sync(bare) prompts with--globalsuggestioncd ~/.claude && mcs sync --pack foohard-errors with clear messagecd ~/.claude && mcs sync --global --pack foosilently redirects (no prompt)cd ~ && mcs sync --pack foohard-errors (same protection applies at$HOME)cd ~/Projects/my-app && mcs sync --pack foounaffected (no false positives)~/.claude.jsondoesn't trigger the guardTesting
Environment.isInsideClaudeHome(exact-match, nested, sibling-missing, prefix-collision,$HOMEmatch,$HOME/subdirnon-match)SyncCommand.guardClaudeHomeCwdexercising each branch viaSyncCommand.parse([...])+ direct call