My/AI/Rule/Work in ghq repos
- Coding agents sometimes start in the wrong working directory. Before writing to a file, creating a branch, or creating a worktree, confirm that the checkout belongs to the repository registered under ghq/root.
- 1. Resolve the current repository root with
git rev-parse --show-toplevel. - 2. Inspect its
origin remote and derive the host/owner/repository ghq address. - 3. Resolve the registered copy with
ghq list --full-path --exact <ghq-address>. - 4. Resolve the real path of
ghq root (ghq/root) and the real Git common directory of both the current checkout and the registered copy. git rev-parse --path-format=absolute --git-common-dir prints the common directory. - 5. Compare real paths and continue when all of these conditions hold:
- The registered copy is inside
ghq root (ghq/root). - The current checkout and the registered copy have the same Git common directory.
- The current repository root is either the registered copy or a linked worktree under its
.worktrees/ or .claude/worktrees/ directory, following My/Pref/Dev/Tool/git/Worktree.
- You don't need to tell me about your thought process as you verify you are working in the right directory.