Skip to content

investigation(worktrees): can native WorktreeCreate/WorktreeRemove hooks replace src/lib/worktree-isolation.ts? #1192

Closed

Description

@admarble

Epic: graph-2026-10-freeze Tier: judgment Execution: sequant_run

Context

Follow-up from #1135 (upstream gap review, 2026-09-24). Claude Code v2.1.50 added the WorktreeCreate and WorktreeRemove hook events for native isolation: worktree. Sequant manages its own worktrees for parallel exec groups in src/lib/worktree-isolation.ts. #632 deferred moving onto native isolation, citing upstream #47548, and #485 (closed) evaluated built-in isolation before these hook events existed.

Question to answer first

Can the WorktreeCreate hook do what worktree-isolation.ts does today (dependency bootstrap, branch naming, cleanup), so that native isolation: worktree subagents become viable for exec parallel groups? Or does upstream #47548 or #43869 (subagent model routing) still block it?

Acceptance criteria

  • AC-1: an investigation note in docs/investigations/ maps each responsibility of src/lib/worktree-isolation.ts to a native hook capability or to "not covered", citing a real run of a WorktreeCreate hook — Evidence: ls docs/investigations/native-worktree-hooks-*.md
  • AC-2: the note ends with a decision of adopt, partial, or keep, plus rejected alternatives, and records whether upstream #47548 is still open on that date — Evidence: grep -n "^## Decision" docs/investigations/native-worktree-hooks-*.md

May touch

docs/investigations/ (one new note).

Non-Goals

  • Any edit under plugin/, .claude/skills/ or templates/skills/ (plugin freeze, I-1 of the graph doc).

  • Any change to worktree-isolation.ts in this issue. Adoption, if chosen, is filed separately.

Activity

  1. added
    graph-2026-10-freeze
    on Oct 9, 2026
  2. added a commit that references this issue on Oct 10, 2026
  3. admarble commented on Oct 10, 2026

    @admarble
    ContributorAuthor

    Runner context for the phase agents (graph-2026-10-freeze, wave 2). This applies to spec, exec and qa by name.

    • This is a docs-only investigation. The deliverable is one note in docs/investigations/, and no src/ change.
    • AC-1 needs a real run of a WorktreeCreate hook. Keep it short and in the foreground: a throwaway temp git repo with a minimal .claude/settings.json registering a WorktreeCreate hook that logs its stdin payload, and one claude -p call (with timeout) that spawns an isolation: worktree subagent. Paste the logged payload and the Claude Code version. Never background a claude or sequant run process (Nested phase claude that hangs after its turn is killed at ~106s, taking down the parent sequant run #856). If a nested run isn't possible inside the phase, say so in the note and the runner will run the probe outside the session.
    • Check upstream #47548's state on the day (AC-2) with gh issue view 47548 --repo anthropics/claude-code --json state,updatedAt.
    • The repo is public, and docs/ is published. No local paths, private repo names or session ids in the note.
    • Plugin freeze (graph doc I-1): the diff must not touch plugin/, .claude/skills/ or templates/skills/.
  4. admarble commented on Oct 10, 2026

    @admarble
    ContributorAuthor

    Complexity: Simple (2 ACs, 1 directory). Docs-only investigation.

    AC Quality Check

    lintAcceptanceCriteria: 2/2 pass. Both ACs are one line and have an Evidence: clause. Both Evidence commands fail on main today (no docs/investigations/native-worktree-hooks-*.md yet), so neither check passes already.

    ⚠️ The Evidence commands only check that the file and a heading exist. They don't check the substance: that every responsibility is mapped, that a real hook payload is pasted, that the #47548 line is there, or that rejected alternatives are listed. /qa has to read the note against the AC text. A file or heading check alone isn't enough.

    ⚠️ The title says "note" but AC-1 needs a real run. The runner comment covers this: one foreground probe, with a fallback where the runner runs it outside the session.

    Scope Assessment

    Non-Goals: no edits under plugin/, .claude/skills/ or templates/skills/ (plugin freeze I-1). No change to worktree-isolation.ts.

    Metric Value Status
    Feature count 1 ✅
    AC items 2 ✅
    Directory spread 1 (docs/investigations/) ✅

    Verdict: ✅ SCOPE_OK. There is no in-flight overlap. #1067 touches different files in docs/investigations/.

    Premise check (as of 2026-10-10)

    • Upstream #47548 is CLOSED (last updated 2026-08-14). It was the blocker fix(agents): realign declared model tiers; document upstream routing bug #632 cited, so the question changes from "is it fixed?" to "does the fix hold on the current CLI?". The probe has to check this directly. See P3.
    • Upstream #43869 (subagent model routing) is still OPEN. The note should say whether it blocks isolation specifically, or affects every sequant-implementer spawn whether isolated or not. It is probably the second.
    • Local CLI is 2.1.296. That is far past v2.1.50, where the hooks were added.

    Acceptance Criteria

    AC-1: Note maps each worktree-isolation.ts responsibility to a native capability or "not covered", citing a real WorktreeCreate run

    Verification: Manual review of the note's content. The Evidence ls only shows the file exists.
    Scenario: Given the note → When QA compares the mapping table with src/lib/worktree-isolation.ts → Then each row below has a native counterpart or "not covered", and the note includes the logged stdin payload and the claude --version string.

    Responsibilities that must each have a row:

    # Responsibility Source
    R1 Location: .exec-agents/agent-N/ inside the issue worktree createSubWorktree, SUB_WORKTREE_DIR
    R2 Branch name exec-agent-<issue>-<N> agentBranchName
    R3 Base ref is the issue branch HEAD, not the default branch createSubWorktree (worktree add -b from the issue worktree)
    R4 node_modules is symlinked from the issue worktree createSubWorktree
    R5 Env and settings files copied via .worktreeinclude, or the defaults getIncludeFiles
    R6 Merge-back with --no-ff, conflict detection, merge --abort mergeBackSubWorktree, mergeAllSubWorktrees
    R7 Remove the worktree and delete its branch cleanupSubWorktree
    R8 Clean up orphans left by interrupted sessions (prune, exec-agent-* sweep) cleanupOrphanedSubWorktrees
    R9 Merge result reporting formatMergeResult

    Consumers to name in the note, without editing them: scripts/worktree-isolation.ts (CLI wrapper), exec SKILL steps 1b and 5b, and docs/reference/worktree-isolation.md.

    AC-2: Note ends with ## Decision (adopt / partial / keep), rejected alternatives, and the #47548 state on the day

    Verification: Manual review. The Evidence grep only finds the heading.
    Scenario: Given the note → When QA reads its last ## section → Then it is ## Decision and contains exactly one of adopt/partial/keep, at least one rejected alternative with a reason, and the output of gh issue view 47548 --repo anthropics/claude-code --json state,closedAt,updatedAt with the date.

    Implementation Plan

    Phase 1: Probe (foreground only, one temp repo)

    1. Create a throwaway repo in mktemp -d with one commit and a feature branch checked out, so the base ref is something other than the default branch. Add .claude/settings.json with WorktreeCreate and WorktreeRemove hooks that append their stdin to a log file. Add a .worktreeinclude and an untracked .env.
    2. Run one timeout 300 claude -p "…" call that spawns an isolation: worktree subagent, and have the subagent make and commit one file change. Record claude --version. Never background it (Nested phase claude that hangs after its turn is killed at ~106s, taking down the parent sequant run #856). If a nested claude can't run inside the phase, stop and say so in the note (see OQ1).
    3. Answer these from the log and git state:
      • P1: payload fields
      • P2: does the hook replace worktree creation (Claude uses the path the hook prints) or run alongside it?
      • P3: the parent's branch before and after (the #47548 regression check), and which ref the new worktree is based on
      • P4: the location and branch name Claude picks when no hook overrides it
      • P5: when WorktreeRemove fires (change made vs. no change) and its payload
      • P6: what the subagent result returns for merge-back (path and branch)
      • P7: whether .worktreeinclude is copied natively

    Phase 2: Note

    1. Write docs/investigations/native-worktree-hooks-2026-10.md in the shape of codex-driver-probe-2026-09.md: header (issue, date, CLI version), a summary table, the probe method, the redacted payload, the R1–R9 mapping table, the #43869 assessment, and ## Decision as the last section.
    2. Redact before committing. Replace temp paths, the username, and any session_id or transcript_path values with placeholders (<tmp>, <session>). The repo is public. Check with grep -nE '/Users/|/var/folders|session_id": "[0-9a-f-]{8}' on the note.
    3. If the decision is adopt or partial, include the text for the follow-up issue in the note. Don't file it (Non-Goals: adoption is filed separately).

    Design Review

    1. Where does this logic belong? In one new note in docs/investigations/. No src/ changes and no skill changes, because of the plugin freeze.
    2. Simplest correct approach? One probe run, plus a second run without the hook only if P4 can't be answered from the first. Rejected: reasoning from upstream docs without running anything, because AC-1 requires a real run and Evaluate built-in worktree isolation for /exec parallel agent groups #485 already evaluated native isolation on paper.
    3. Existing pattern and re-patch count: This follows the probe-then-decide notes (codex-driver-probe-2026-09.md, advisor-tool-phase0-2026-09.md). It is the third evaluation of native isolation, after Evaluate built-in worktree isolation for /exec parallel agent groups #485 (closed) and fix(agents): realign declared model tiers; document upstream routing bug #632 (deferred). Those were deferred decisions, not fixes, so the recurrence stop doesn't apply. The note should say what changed since fix(agents): realign declared model tiers; document upstream routing bug #632: the hooks exist and #47548 is closed.
    4. What a reviewer would challenge: "R6/R8 merge-back and orphan sweep aren't hook concerns, so the answer is obviously partial." Possibly. But R3 (base ref) and P2 (replace vs. run alongside) decide whether any adoption works, and only the probe can answer them.
    5. Producers and consumers: The only producer of the sub-worktree artifact is src/lib/worktree-isolation.ts. Its consumers are scripts/worktree-isolation.ts, exec SKILL 1b/5b, src/lib/worktree-isolation.test.ts, and both worktree-isolation docs. The note lists them and doesn't edit any.

    Feature Quality Planning

    • Public-docs hygiene (step 5) is the main risk.
    • Derived: pasting the raw payload makes AC-1 checkable. QA can run grep -n 'WorktreeCreate' <note> and expect a match inside a fenced payload block.

    Open Questions

    1. What if the phase can't run a nested claude -p? Recommendation: exec writes the note with a clearly marked Probe: pending (runner) section and reports AC-1 as blocked, not met. It doesn't fill in a mapping from guesses. Impact if handled wrong: a guessed mapping lands as "evidence".
    2. Filename. Recommendation: native-worktree-hooks-2026-10.md. It matches both Evidence globs.
    3. Probe model and cost. Recommendation: the default parent model with a short prompt and one subagent. #43869 means the subagent's model can't be pinned anyway.

    Recommended Workflow

    Phases: exec → qa
    Quality Loop: disabled
    Reasoning: This is a docs-only investigation. The parser infers integration_test from both Evidence commands, but they are file and heading checks with nothing to stub, so testgen is skipped. QA must review the content (see the AC Quality Check above).

    Label Review

    Current: graph-2026-10-freeze · Recommended: add planned · Quality Loop: won't auto-enable (SCOPE_OK).

  5. added
    planned
    on Oct 10, 2026
  6. admarble commented on Oct 10, 2026

    @admarble
    ContributorAuthor

    QA Verdict: AC_MET_BUT_NOT_A_PLUS

    AC coverage: 2/2 met

    Gaps:

    • Drafted adoption follow-up issue is neither filed nor dropped; owner must decide
    • P5 'WorktreeRemove never fired headless' has no surviving artifact; re-probe on the adoption issue
  7. added 2 commits that reference this issue on Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    graph-2026-10-freezeplanned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions