Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

Have wt-switch-create read the new repo's root instructions (#4414)

Maximilian Roosa4045b8959f6
diff --git a/plugins/worktrunk/skills/wt-switch-create/SKILL.md b/plugins/worktrunk/skills/wt-switch-create/SKILL.md
index e48703d21..2b084ef18 100644
--- a/plugins/worktrunk/skills/wt-switch-create/SKILL.md
+++ b/plugins/worktrunk/skills/wt-switch-create/SKILL.md
@@ -84,6 +84,13 @@ design choices behind this — read it before re-adding guards or routes. -->
Then call `EnterWorktree({path: "<path from the JSON>"})`.
+ With a repo argument, once the session works in the new worktree (entered,
+ or reached by `cd` in the recovery below), read whichever of its root
+ `CLAUDE.md` and `AGENTS.md` exist before the task. Claude Code keeps the
+ launch repo's root instructions in context and loads only the new repo's
+ nested ones, so the new repo's root files supersede the launch repo's for
+ the rest of the session.
+
- **Accepted** → the session is re-rooted in the worktree. Do the task (or,
with no task text, confirm it's ready and wait).
- **Tool error** — the tool ran and returned an error (`Cannot enter
diff --git a/plugins/worktrunk/skills/wt-switch-create/rationale.md b/plugins/worktrunk/skills/wt-switch-create/rationale.md
index 0dbaf90b7..bafbfe9e7 100644
--- a/plugins/worktrunk/skills/wt-switch-create/rationale.md
+++ b/plugins/worktrunk/skills/wt-switch-create/rationale.md
@@ -234,6 +234,26 @@ enlarge that set itself (`/add-dir` is user-typed; the only automatic add is a
narrow symlink-resolving-to-the-same-cwd fixup), so a repo reachable by neither
the cwd nor config is a genuine handback to the user.
+### Re-rooting keeps the launch repo's instructions
+
+Re-rooting into another repo changes the cwd but not the instruction context.
+Verified 2026-10-10 against Claude Code 2.1.296 with three headless sessions.
+Two launched in another repo, then ran `cd` plus `EnterWorktree({path})` or
+`cd` plus `EnterWorktree({name})`; each context still held the launch repo's
+root `AGENTS.md` and auto-memory index, with nothing from the new repo. The
+third, started in the worktree, loaded the new repo's. Nested instruction files of the
+new repo still load lazily when a file in their directory is read. Both routes
+run the same post-entry code in the binary, which clears the memo of loaded
+instruction files but doesn't rebuild the root block, which reloads only at
+session start and compaction; the entry confirmation's "loads project
+configuration (CLAUDE.md, settings)" doesn't hold for it. The `name` route can't
+cross repos anyway: the `WorktreeCreate` hook `cd`s to `$CLAUDE_PROJECT_DIR`,
+which stays the launch repo, so the worktree lands there.
+
+So with a repo argument, the skill has the agent read the new root files after
+entry. That fixes the instructions only; the launch repo's root file stays in
+context, as does its auto-memory.
+
### Why `--no-cd`
The Bash tool is not a bare shell: Claude Code replays the user's shell startup
diff --git a/skills/wt-switch-create/SKILL.md b/skills/wt-switch-create/SKILL.md
index e48703d21..2b084ef18 100644
--- a/skills/wt-switch-create/SKILL.md
+++ b/skills/wt-switch-create/SKILL.md
@@ -84,6 +84,13 @@ design choices behind this — read it before re-adding guards or routes. -->
Then call `EnterWorktree({path: "<path from the JSON>"})`.
+ With a repo argument, once the session works in the new worktree (entered,
+ or reached by `cd` in the recovery below), read whichever of its root
+ `CLAUDE.md` and `AGENTS.md` exist before the task. Claude Code keeps the
+ launch repo's root instructions in context and loads only the new repo's
+ nested ones, so the new repo's root files supersede the launch repo's for
+ the rest of the session.
+
- **Accepted** → the session is re-rooted in the worktree. Do the task (or,
with no task text, confirm it's ready and wait).
- **Tool error** — the tool ran and returned an error (`Cannot enter
diff --git a/skills/wt-switch-create/rationale.md b/skills/wt-switch-create/rationale.md
index 0dbaf90b7..bafbfe9e7 100644
--- a/skills/wt-switch-create/rationale.md
+++ b/skills/wt-switch-create/rationale.md
@@ -234,6 +234,26 @@ enlarge that set itself (`/add-dir` is user-typed; the only automatic add is a
narrow symlink-resolving-to-the-same-cwd fixup), so a repo reachable by neither
the cwd nor config is a genuine handback to the user.
+### Re-rooting keeps the launch repo's instructions
+
+Re-rooting into another repo changes the cwd but not the instruction context.
+Verified 2026-10-10 against Claude Code 2.1.296 with three headless sessions.
+Two launched in another repo, then ran `cd` plus `EnterWorktree({path})` or
+`cd` plus `EnterWorktree({name})`; each context still held the launch repo's
+root `AGENTS.md` and auto-memory index, with nothing from the new repo. The
+third, started in the worktree, loaded the new repo's. Nested instruction files of the
+new repo still load lazily when a file in their directory is read. Both routes
+run the same post-entry code in the binary, which clears the memo of loaded
+instruction files but doesn't rebuild the root block, which reloads only at
+session start and compaction; the entry confirmation's "loads project
+configuration (CLAUDE.md, settings)" doesn't hold for it. The `name` route can't
+cross repos anyway: the `WorktreeCreate` hook `cd`s to `$CLAUDE_PROJECT_DIR`,
+which stays the launch repo, so the worktree lands there.
+
+So with a repo argument, the skill has the agent read the new root files after
+entry. That fixes the instructions only; the launch repo's root file stays in
+context, as does its auto-memory.
+
### Why `--no-cd`
The Bash tool is not a bare shell: Claude Code replays the user's shell startup