Skip to content

Commit e5c68eb

Browse files
committed
chore(agents): anchor subagent bash commands to the worktree path
1 parent 6ebface commit e5c68eb

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

home/dot_agents/AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Always edit the source, not the deployed file. When updating any memory file: re
5151
- When the cwd is inside a Claude Code worktree (e.g. `.claude/worktrees/<id>`), git and gh commands act on the worktree branch. The main repo's working tree may be locked by another agent; do not `git checkout` or `gh pr checkout` against it.
5252
- To pull a PR branch, materialize it into a new worktree: `git -C /path/to/main-repo fetch origin <branch> && git -C /path/to/main-repo worktree add <path> origin/<branch>`.
5353
- Use `git -C <path>` for all subsequent commands. Confirm the active branch with `git -C <path> branch --show-current` before reading or editing files.
54+
- **Anchor subagent commands to the worktree explicitly.** When dispatching subagents from inside a worktree, include `cd <absolute-worktree-path> && <command>` (or pass absolute paths) in every Bash invocation in the subagent's prompt. Subagents may run from a different effective cwd than the controller, and from a sibling main repo at a parent path you get superficially plausible but wrong git/file answers (e.g. a staged file reported as unstaged, a CRLF-free file reported as CRLF, HEAD reported as a different commit). The signal that you've hit this: the subagent reports a state that contradicts what you can directly verify yourself, and re-dispatching with explicit anchoring makes the contradiction disappear.
5455
- **After a PR merges, proactively offer to clean up its worktree and branches.** When the user confirms a PR has been merged (or you observe the merge while working), surface a cleanup offer via `AskUserQuestion` before doing anything destructive. The cleanup is: `git worktree remove <path>`, `git branch -D <name>` locally, and `git push origin --delete <name>` (often a no-op because GitHub auto-deletes the head branch on merge). Refuse to delete dirty worktrees without explicit per-tree consent. If the current shell's CWD is inside the worktree being removed, expect a "Permission denied" on the directory itself: the git entry, contents, and branches still get cleaned, leaving only an empty husk that vanishes once the shell exits.
5556
- **Cloning for tag comparison.** `--depth=1 --no-single-branch` does not fetch tags. When you need to compare specific tags, either clone without `--depth`, or run `git fetch --tags` after the shallow clone.
5657
- **Inspecting a PR's diff.** Always diff the remote PR branch against `origin/main` (e.g. `git diff origin/main...origin/<pr-branch>`), not local HEAD. Local HEAD may be on an unrelated branch, so a diff against it is meaningless and returns empty output without any error.

0 commit comments

Comments
 (0)