Skip to content

Commit aa8ca93

Browse files
committed
chore(agents): warn against chezmoi apply --source <worktree>
Deploying from an uncommitted worktree source is fragile; a later apply from a different source silently reverts the deploy and chezmoi records the reverted content as its last-written state.
1 parent 9a48894 commit aa8ca93

2 files changed

Lines changed: 2 additions & 0 deletions

File tree

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ Deleting a file from the chezmoi source does **not** remove it from the target (
118118
- Keep source edits, `chezmoi apply`, and git operations as separate commands unless a later step strictly depends on the previous one within the same concern.
119119
- When `chezmoi apply` triggers a brew bundle run (via an onchange script), treat it as fire-and-forget once the apply succeeds.
120120
- If `chezmoi apply` fails because an unrelated template needs a secret (e.g. Bitwarden locked), apply only the file you need with `chezmoi apply <target-path>` to bypass the failing template.
121+
- Commit chezmoi source changes to the relevant branch before testing with `chezmoi apply`. Deploying from an uncommitted `--source <worktree-path>` is fragile: any subsequent `chezmoi apply` from a different source silently reverts the deploy, and chezmoi records the reverted content as its last-written state so nothing looks wrong on inspection. Diagnose suspected reverts by comparing `Get-FileHash` of the deployed file against the source and against chezmoi's tracked `contentsSHA256` (visible via `chezmoi state get-bucket --bucket=entryState`).
121122

122123
---
123124

home/dot_agents/AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Always edit the source, not the deployed file. When updating any memory file: re
5050
- 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.
5151
- 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>`.
5252
- Use `git -C <path>` for all subsequent commands. Confirm the active branch with `git -C <path> branch --show-current` before reading or editing files.
53+
- **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.
5354
- **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.
5455
- **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.
5556
- **Before opening a PR: clean up history.** Squash messy work-in-progress or AI-attributed commits into a clean, atomic commit sequence on the branch. The branch is yours until `gh pr create` succeeds.

0 commit comments

Comments
 (0)