Skip to content

Detect and redirect when mcs sync runs from ~/.claude #329

@bguidolim

Description

@bguidolim

Problem

Users trying to install packs globally cd ~/.claude && mcs sync instead of running mcs sync --global from anywhere. This is broken:

  • ~/.claude is a real directory, so SyncCommand proceeds as if it were a project root.
  • ProjectDetector walks up, potentially latching onto weird state or creating ~/.claude/.claude/ garbage.
  • Nothing tells the user they took the wrong path — they may believe the install succeeded.

Proposed solution

1. Detect ~/.claude as cwd and redirect

At the start of SyncCommand.perform() (or inside performProject), resolve the effective target path. If it's env.claudeDirectory or anywhere under it, and --global wasn't passed:

It looks like you want to sync global scope.
Use 'mcs sync --global' instead? [Y/n]
  • Yes → set global = true internally, chdir to env.homeDirectory to keep ProjectDetector well-behaved, then proceed.
  • No → hard error with the same suggestion in the message.

If --global is passed but cwd happens to be ~/.claude, silently chdir to $HOME before running — no prompt, just avoid the footgun.

2. Scope picker on bare mcs sync (bonus, same root cause)

When mcs sync runs with no --global / --pack / --all flags and ProjectDetector fails to find a project root (no .git/, no CLAUDE.local.md), show a scope picker before the pack picker:

Where to sync?
  > This directory (./)
    Global (~/.claude)

This kills the cd ~/.claude instinct at the root — users never need to "go somewhere" to configure globally.

Tradeoff

Pure block (error-only) is simpler but less helpful — users who get the error often retry the wrong thing. Offering the right command inline (with a confirmation prompt) converts confusion into learning. Auto-redirect without prompt is friendlier but surprising; explicit confirmation keeps intent clear.

Scope

Sources/mcs/Commands/SyncCommand.swift — add a cwd guard at the top of perform(), before performGlobal / performProject branch. Uses existing Environment.claudeDirectory for the comparison.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions