Repository navigation
fix(claude): preserve original repository for mutation-scope lifecycle - #359
Merged
Merged
Conversation
davidabram
marked this pull request as ready for review
November 24, 2026 14:41
Document the verified stable lookup anchor and fallback policy needed to route Claude mutation attempts across changing hook working directories. Record the probe evidence, project Git-directory anchor, route location, and fail-closed behavior for unresolved project roots. Plan: claude-mutation-scope-stable-repository-routing; task: T01. Co-authored-by: SCE <sce@crocoder.dev>
…gnostic Persist per-tool invocation routes at the stable project Git anchor with atomic, idempotent updates, target-checked removal, and fail-closed table handling. Document the route store and record completion of plan claude-mutation-scope-stable-repository-routing task T02, while preserving the adapter-state lock-timeout diagnostic from the hook run. Co-authored-by: SCE <sce@crocoder.dev>
Terminal Claude hook events can report a cwd different from PreToolUse, leaving scopes active in the original repository. Persist per-tool routes under the stable project Git directory before Start, and resolve terminal and cleanup events through the recorded target while preserving legacy fallback for older attempts. Add lifecycle coverage and document the routing decision and behavior. Plan: `claude-mutation-scope-stable-repository-routing` Task: `T03` Co-authored-by: SCE <sce@crocoder.dev>
Complete task T04 in the claude-mutation-scope-stable-repository-routing plan by recording the routing validation, live nested-repository rerun, measured hook overhead, and remaining recovery limits. Add local Git identity setup to the worktree-removal fixture so the sandboxed test is self-contained; no production code changes. Co-authored-by: SCE <sce@crocoder.dev>
davidabram
force-pushed
the
claude-stable-scope-repository-routing
branch
from
November 24, 2026 14:55
8b4d7e3 to
54b8450
Compare
…e route sync errors PreToolUse stored the raw tool cwd as the route checkout path. When that cwd was a subdirectory the tool later deleted or renamed, terminal events drove the seam with a path that no longer existed. PreToolUse now resolves the canonical worktree root with the existing resolve_worktree_root and derives the Git directory from that root, so both route fields describe one checkout, including linked worktrees and nested repositories. The route store discarded directory open and sync_all failures after the atomic rename. Both now fail the write with the directory path in the error, so PreToolUse denies the tool. A same-key, same-target replay re-syncs the directory before reporting AlreadyRouted. A route left visible without an attempt is retired by the next terminal or cleanup event. Remove the tracked sce-next-task session log and ignore its tmp directory. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: SCE <sce@crocoder.dev>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Claude mutation-scope hooks resolved the Git repository separately from each event's
cwd. IfPreToolUsestarted in repository A andPostToolUseran after the session moved into nested repository B, the adapter looked for the attempt in B and left the original scope active in A.Fix
$CLAUDE_PROJECT_DIRlocates a durable route table (<anchor-git-dir>/sce/claude-mutation-scope-routes.json). A live probe confirmed it stays the same acrosscwdchanges, subagents, and terminal events. The anchor never identifies a mutation target.Start,PreToolUsepersists(session_id, agent_id?, tool_use_id) -> (checkout_path, git_dir).checkout_pathis the canonical worktree root of the tool'scwd, andgit_diris resolved from that root. Failing to resolve the root, persist the route (including the directory sync after the rename), or a conflict denies the tool.PostToolUse,PostToolUseFailure,PermissionDenied,Stop/StopFailure/UserPromptSubmit,SubagentStop,SessionEnd, andWorktreeRemovefinish attempts in the routed checkout and never scan other repositories. A route is removed only after its attempt is gone.routedmarker) are still found through the eventcwd. A routed attempt whose route is missing is never closed throughcwd.sync_data, an atomic rename, and a directory sync on Unix. Directory open and sync failures fail the write. A same-key retry syncs the directory again before it reportsAlreadyRouted.No change to
spec/mutation_cursor.qnt, the mutation protocol, generic ingress, or migrations. The onlymutation_tracechange re-exports the existingresolve_worktree_root.Plan and validation report:
context/plans/claude-mutation-scope-stable-repository-routing.md(AC1–AC9, T01–T05).Validation
nix develop -c ./scripts/run-cli-cargo.sh test --manifest-path cli/Cargo.toml: 920 passed, including the Quint MBT connect tests-D warningsandcargo fmt --checkpassnix flake check: all checks passedclosedin itsPreToolUserepository, noactivescopes, route table emptyKnown limits
cwdchanged before completion is still orphaned.state.rs) still treat the directory sync as best-effort.🤖 Generated with Claude Code