feat(hooks): auto-claim edited files + cross-session overlap warnings#10
Merged
feat(hooks): auto-claim edited files + cross-session overlap warnings#10
Conversation
Observed-not-predictive claims: PostToolUse watches Edit / Write /
MultiEdit / NotebookEdit, extracts file_path, and writes a claim into
task_claims for the current session's joined task. Agents don't have to
remember to call task_claim_file for the claim system to protect their
work.
The warning half lives in UserPromptSubmit. A new buildConflictPreface
queries recentClaims(task_id, now - 5m) for claims held by *other*
sessions on the same task, groups them by session, and injects one line
per collaborator ("A: src/viewer.tsx, src/api.ts") plus a nudge to
coordinate via task_post / task_hand_off before editing those files.
Storage: new recentClaims(task_id, since_ts) method — the conflict
preface's query surface. Older-than-window claims are intentionally
excluded; stale claims describe finished work, not live collisions.
Ordering choice worth flagging: claims are written by the session that
did the edit, not reserved by the session that intends to edit.
Predictive claims require agents to remember to call a tool in advance
(they won't). Observed claims require nothing and are always grounded
in actual edits, which makes the resulting warnings trustworthy. Agents
tune out warnings that are wrong a third of the time.
Tests: storage test for recentClaims window + 7 hook-layer tests
(extractTouchedFiles coverage, auto-claim on joined / unjoined / stolen
cases, buildConflictPreface grouping + own-claim exclusion, plus an
end-to-end runHook integration where A edits -> B's next turn sees the
warning naming viewer.tsx and A). All gates green.
4 tasks
NagyVikt
added a commit
that referenced
this pull request
Apr 24, 2026
Add non-negotiable rule #10 and a Worktree discipline section to CLAUDE.md: never edit on the local `main` checkout, always run work in an `agent/*` branch + worktree via `gx branch start`, claim files via `gx locks claim`, finish via PR with `gx branch finish ... --via-pr --wait-for-merge --cleanup`, and coordinate with codex through colony MCP `task_post` / `task_claim_file` / `task_hand_off`. This matches how codex already operates via Guardex and keeps parallel lanes safe from primary-checkout drift. Co-authored-by: NagyVikt <nagy.viktordp@gmail.com>
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.
Summary
Turns the soft advisory claims system into something agents actually use — without asking them to call any new tools. PostToolUse observes Edit / Write / MultiEdit / NotebookEdit and writes a claim for the editing session; next turn, UserPromptSubmit surfaces a compact warning naming files that other sessions have recently touched.
Why observed, not predictive
Predictive claims ("I plan to edit X") require agents to call a tool in advance. They won't. Observed claims require nothing from the agent and are always grounded in actual edits — which makes the resulting warnings trustworthy instead of something agents learn to ignore.
What's new
Storage.recentClaims(task_id, since_ts)— the query powering the conflict preface. Stale (outside-window) claims are intentionally excluded; they describe finished work, not live collisions.PostToolUseauto-claim —extractTouchedFiles+autoClaimFromToolUseinpackages/hooks/src/handlers/post-tool-use.ts. Silent-skip on unknown tools and malformed input: PostToolUse runs on every tool call, so any throw would degrade every turn.UserPromptSubmitconflict preface —buildConflictPrefacegroups claims by session ("A: src/viewer.tsx, src/api.ts") so the agent reads one clustered warning instead of three disjoint ones. 5-minute window, own-session claims excluded.recentClaims; 7 new hook tests —extractTouchedFilescoverage (write vs non-write tools, malformed input),autoClaimFromToolUse(joined / unjoined / stolen-claim),buildConflictPrefacegrouping + own-claim exclusion, plus an end-to-endrunHookintegration proving A edits → B's next turn sees the warning namingsrc/viewer.tsxand A.Test plan
Deliberately deferred
Stale handoff reclamation — the next turn's "your handoff expired" nudge — is deferred until we've run the system on a real two-agent task for a day or two. The shape of the right notification depends on how often expiries actually happen; a theoretical design here would probably pick the wrong primitive.
🤖 Generated with Claude Code