Skip to content

feat(claude): run quest's worktree hooks through the flake's pinned quest - #7674

Merged
kixelated merged 10 commits into
mainfrom
quest/m0/quest-worktree-hooks
Nov 3, 2026
Merged

kixelated merged 10 commits into
mainfrom
quest/m0/quest-worktree-hooks

Conversation

@kixelated

@kixelated kixelated commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Works on quest/m0/quest-worktree-hooks.md. Claude Code's worktree and subagent hooks now run the quest moq pins, through nix, and the pin moves past moq-dev/quest#425, so PR worktrees and workflow agents behave under them. The quest is rewritten to what remains: moq-dev/quest teaching quest init to recognize the wrapped hooks.

Summary

  • .claude/settings.json: WorktreeCreate, WorktreeRemove, SubagentStart and SubagentStop run nix run "${CLAUDE_PROJECT_DIR}#quest" -- worktree hook. That's the flake's packages.<system>.quest, the moq-dev/quest input in flake.lock. Hooks get the PATH Claude Code started with, not the dev shell, so a bare quest worktree hook fails with quest: not found here.
  • flake.nix/flake.lock: quest 5e66075 → 36d0429 (current main). That includes moq-dev/quest#425 (53f78b9), so --worktree '#N' starts at the PR head and workflow agents' checkouts are released. It also includes moq-dev/quest#451 (a subagent's .tmp survives release) and moq-dev/quest#445 (worktree submodules). Quest's own quest-pinned input moved with it.
  • Skill stubs refreshed with the drop-and-restore step below. Only quest-merge's description changed.
  • AGENTS.md: one line. The hooks run the pinned quest through nix run, and since quest init refuses them, a pin bump drops them for its run and restores .claude/settings.json afterwards.
  • .gitignore: /.worktrees/, where quest's checkouts land under the main checkout. Each carries its own biome.jsonc, the same reason /.claude/worktrees/ is ignored.
  • Quest narrowed to quest init recognizing the wrapped hooks. Its ## Waiting item is on moq-dev/quest, so the quest stays open after this PR.
  • Merged origin/main.

Decisions

Settled by the maintainer on 2026-11-03:

  1. How the hooks reach quest: ✅ nix (or a submodule) long-term, so the hooks run moq's pin; a host-wide quest on PATH only as a temporary bridge.
    • Rejected: a quest installed on PATH; direnv exec; adopting the bare quest worktree hook now; dropping the quest.
  2. Bump moq's quest pin past moq-dev/quest#425: ✅ in this PR, before landing.
    • Rejected: land now and bump later.
  3. quest init and wrapped hooks: ✅ ask moq-dev/quest to have quest init treat any command hook whose arguments end in worktree hook as its own. Another agent is planning that in moq-dev/quest. Until it lands, the drop-and-restore step stays in AGENTS.md.
    • Rejected: a configured hook command; not asking.

Which nix shape

Measured from Claude's hook environment (its PATH, no dev shell), printing quest --version. "Cold" uses a fresh XDG_CACHE_HOME, so the eval and fetcher caches are empty. Times are noisy under host load.

Hook command Warm Cold cache Notes
nix run "$CLAUDE_PROJECT_DIR#quest" -- … ✅ 0.12–0.49 s (clean, dirty, or just-changed tree) 1.5–3.2 s needs only nix; resolves from a subdirectory too
nix run --inputs-from "$CLAUDE_PROJECT_DIR" quest -- … 0.13–1.3 s 0.9 s same pin through the registry; a less obvious spelling for no gain
nix develop "$CLAUDE_PROJECT_DIR" --command quest … 0.6–17 s 2.7–4.9 s evaluates and realises the whole dev shell
direnv exec "$CLAUDE_PROJECT_DIR" quest … 0.16 s 4.4 s needs direnv as well; rejected (decision 1)

After a pin bump, the first call builds the new quest in about 6 s here. A submodule would need bun and node_modules in each checkout to run the CLI, so nix is simpler. The hook runs the checkout's own pinned quest, so a PR head chooses the code its hooks run. That's the same trust the existing direnv SessionStart hook already gives the checkout's flake.

quest init and pin bumps

quest init recognizes its hook only by the exact string quest worktree hook (isQuestHook in moq-dev/quest's src/core/init.ts, still the case at 36d0429).

  • With the nix command in place, quest init exits 1 (already has a WorktreeCreate hook, and only one can manage Claude's worktrees) and writes nothing.
  • For SubagentStart/SubagentStop it would add a second, bare quest worktree hook.
  • Workaround, used for this PR's stub refresh and documented in AGENTS.md: drop the four entries, run the pinned quest init (it then changes only .claude/settings.json and stale stubs), and restore .claude/settings.json.

Live T3 check (on the new pin, Claude Code 2.1.316)

All of this ran against the real quest registry, which was empty before and after.

Route Created Released Cleaned up
Native isolation: "worktree" subagent from this T3 worktree thread ✅ ~/work/moq/.worktrees/agent-ac5c51df91121bd23 at origin/HEAD (fb9a4fbb00) ✅ released on SubagentStop ✅ quest worktree remove
T3 delegate_task with isolation: "worktree" from f26e953 ✅ T3's own ~/worktrees/moq/t3-bd4a8297 (t3/bd4a8297, 4 nix hooks, pin 36d0429); never registered with quest, left clean (not quest's) ✅ T3-style git worktree remove, branch deleted
Native isolated subagent inside that delegate ✅ ~/work/moq/.worktrees/agent-a789581853623b2a8 at origin/HEAD ✅ released ✅ quest worktree remove
claude --worktree '#7674' -p … ✅ ~/work/moq/.worktrees/pr-7674 at f26e953f66, exactly the PR's head then, fetched into origin/pr/7674 session checkout, stays active (as upstream documents) ✅ quest worktree remove

An interrupted probe also showed the crash case: its checkout was created and stayed active, since no SubagentStop fired, and quest worktree remove recovered it. T3's own worktree create and remove are plain git operations that never reach Claude's WorktreeCreate/WorktreeRemove, and the subagent hooks act only on a registered agent-<agent_id> checkout, so T3 checkouts are left alone. I didn't exercise t3_worktree_handoff: it refuses a thread that already has a worktree, and it's a T3 git operation the hooks don't take part in. Workflow agents (wf_…) weren't run live here; moq-dev/quest#425 verified them upstream.

Choices made without asking

  • nix run "${CLAUDE_PROJECT_DIR}#quest" over --inputs-from, nix develop and a submodule, for the reasons above.
  • Pinned quest to main (36d0429) rather than exactly 53f78b9, as pin bumps usually do. It also brings the .tmp-preserving release from moq-dev/quest#451.
  • The live check used the real quest registry and ~/work/moq/.worktrees/, then removed everything it made. No settings outside the repository changed.
  • Kept the AGENTS.md addition to one line, per PROMPTING.md.

Review

  • Reviewer: Codex gpt-6.1-sol, medium effort, via quest review --base origin/main (session 01a1a286).
  • Round 1, on ae281b59f7743aa41f3a33b66f3d064495802954: 1 finding.
  • Round 2, on d41d0bca660bef5e728b34c5654e4b0a252dfe38: no findings.

Checks

  • quest check --base origin/main with the new pin: 583 documents ok.
  • quest gate just check origin/main on d41d0bc: passes. The flake module was skipped because this host's Nix builder can't create user namespaces; CI runs it. nix run .#quest built and ran the new pin.

Suggested follow-ups

  • Sweep the leaked agent-* worktrees under ~/work/moq/.claude/worktrees. There are 419 from before these hooks. That's host state, not repository work, but a one-off removal of the clean ones would reclaim the disk.

🤖 Generated with Claude Code

(Written by Claude Opus 5.5)

kixelated and others added 2 commits November 2, 2026 22:21
The hooks leave T3 Code's checkouts alone, but they run with the PATH
Claude Code started with, which has no `quest` here, so every isolated
subagent and `--worktree` would fail. Record the findings and what the
quest waits on, and ignore the main checkout's `.worktrees/`, where
quest's checkouts already land.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title Agents use quest's worktree hooks chore(quest): record why moq can't adopt quest's worktree hooks yet Nov 3, 2026
kixelated and others added 3 commits November 3, 2026 09:44
…uest

Claude Code runs hooks with the PATH it started with, not the dev shell,
so a bare `quest worktree hook` fails here. Run the quest moq pins with
`nix run "${CLAUDE_PROJECT_DIR}#quest" -- worktree hook` instead, and
note in AGENTS.md how to keep the hooks across `quest init`, which
refuses a command other than its literal one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Record the maintainer's nix-or-submodule decision, the measured hook
latency, and what still waits on moq-dev/quest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title chore(quest): record why moq can't adopt quest's worktree hooks yet feat(claude): run quest's worktree hooks through the flake's pinned quest Nov 3, 2026
kixelated and others added 4 commits November 3, 2026 10:58
moq-dev/quest#425 merged, so the bump is ready work, not a wait.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With the PR-head and workflow-agent fixes from moq-dev/quest#425, the
worktree hooks start `--worktree '#N'` at the PR head and release
workflow agents' checkouts. Refresh the skill stubs with `quest init`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The pin bump past moq-dev/quest#425 is done; what remains is quest init
recognizing the nix-wrapped hooks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Record the maintainer's pick: quest init treats any command hook whose
arguments end in `worktree hook` as its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated marked this pull request as ready for review November 3, 2026 19:53
@coderabbitai

coderabbitai Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 7 seconds.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 77fb8941-be5d-45b8-9a79-f2e3c5a83987
Commits

Reviewing files that changed from the base of the PR and between fb9a4fb and d41d0bc.

Files ignored due to path filters: 1
  • flake.lock is excluded by !**/*.lock
Files selected for processing: 7
  • .claude/settings.json
  • .claude/skills/quest-merge/SKILL.md
  • .gitignore
  • AGENTS.md
  • flake.nix
  • quest/m0/README.md
  • quest/m0/quest-worktree-hooks.md
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

@kixelated kixelated left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review by review (OpenAI)

Reviewed head d41d0bca660bef5e728b34c5654e4b0a252dfe38 against base fb9a4fbb0012ea02347616ded42e4e83efc53a02. No actionable findings in the hook wiring, pin integration, or accompanying documentation. The pinned Quest source supports all four events and confirms the documented quest init limitation.

Verification: static review through the GitHub connector only. I did not run Nix builds, repository checks, or live Claude/T3 worktree lifecycle tests.

(Written by OpenAI)

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — read the full 8-file diff at d41d0bc and checked the pin and hook wiring against the upstream quest repository.

  • Claude worktree hooks — .claude/settings.json runs nix run "${CLAUDE_PROJECT_DIR}#quest" -- worktree hook for WorktreeCreate, WorktreeRemove, SubagentStart and SubagentStop; the existing direnv SessionStart hook is untouched.
  • Quest pin — flake.nix and flake.lock move quest 5e66075 → 36d0429 and its quest-pinned input 7a191e6 → 2aa60a2. The lock revisions and lastModified values match the upstream commits, the nested lock at 36d0429 pins the same quest-pinned, and the commits for quest #425, #451 and #445 are all ancestors of the new pin.
  • Checkout scratch — .gitignore adds /.worktrees/, matching where the pinned quest creates checkouts under the main checkout.
  • Docs and stubs — AGENTS.md records the nix wrapper and the quest init drop-and-restore workaround; the quest and m0 README narrow the remaining work to upstream quest init recognizing the wrapped command. All 15 skill stubs match the pinned quest exactly, and .agents/skills is a symlink to them.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@kixelated
kixelated added this pull request to the merge queue Nov 3, 2026
Merged via the queue into main with commit d66a519 Nov 3, 2026
11 checks passed
@kixelated
kixelated deleted the quest/m0/quest-worktree-hooks branch November 3, 2026 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant