Repository navigation
Install hooks user-wide by default, and record each turn once - #7
Merged
Merged
Conversation
`loch install` now writes the user's hooks file (Claude Code's settings.json under CLAUDE_CONFIG_DIR or ~/.claude, Codex's $CODEX_HOME/hooks.json), so one install covers every project. `--local` is this project on this machine (.claude/settings.local.json; Codex has no uncommitted file, so .codex/hooks.json), and the old committed default stays as `--project`. A user-wide hook records only in a git repository: anywhere else it would snapshot whatever directory a session started in. Every scope's hooks run for an event, so each line names its scope and a wider one steps aside when a narrower file in the project holds loch's hook and the agent will run it (for Codex, a trusted project and a trusted hook). Local lines are unchanged, so Ness's `install --local --cwd --command` writes what it always did. Install rewrites an existing loch line in place rather than adding a second, and touches no other hook. The payload gains `scope` and `replaced`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…p aside The user-wide hook stepped aside when a project's file held loch's hook and the agent would run it. Answering that took guesses (where Claude Code reads project settings, Codex trust keys, settings changed mid-session), and a wrong one lost the turn: with a team hook trusted at the same event and loch's project hook not, Codex skipped loch's and nobody recorded. Both agents hand every hook for an event the same bytes (verified on Claude Code 2.1.329 and Codex 0.166), so the hooks of a session now take turns under a lock and one handed an event handled moments ago does nothing. An event is the hook's name, its payload and its transcript's length, since Claude Code stopping twice for one prompt sends identical payloads. This needs nothing from either agent's file or trust rules, and also covers an old committed line beside a local one. Install also removes a second loch line for an event from Claude Code's settings, and leaves it (reporting `duplicates`) in Codex's, whose trust is keyed by position. Only user-wide lines name a scope now, so project lines are what they were. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
frenchie4111
force-pushed
the
feat/install-global-default
branch
from
November 20, 2026 15:52
6f6d175 to
ca000e8
Compare
Another hook's copy of an event reads the claim within milliseconds of its being written, while a genuine repeat that hashes the same (a second Stop before the transcript is flushed) follows a model round trip. The 10s window could only drop such an event and lose its edits; seconds also truncated the window by up to one. A test fires an identical stop past the window. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.
Builds on #5 (Codex support), now merged. Rebased onto
mainand retargeted.What changes
loch installnow writes user-level hooks by default, so one install covers every project:settings.jsonunder$CLAUDE_CONFIG_DIRor~/.claude$CODEX_HOME/hooks.json--local.claude/settings.local.json.codex/hooks.json(Codex has no uncommitted file, so git sees it)--project.claude/settings.json(the old default).codex/hooks.jsonI kept
--projectinstead of dropping it, because it's the only way to make recording travel with a repo to teammates. The code path already existed.Ness's
install --local --cwd <worktree> --command <abs>is unchanged. It writes the same lines to the same file and still means "this worktree only".Hooks outside a repo
User-level hooks fire in every directory. A user-wide hook now records only in a git repository. Anywhere else it would have snapshotted whatever directory the session was in (the plain-directory fallback), e.g.
~/Downloads. A repository with no commits still records. The check (hook::applies) runs before any store is opened.Measured: 2.8ms outside a repo (process start), and nothing is written. Without the check, the same 2,000-file directory took 83ms and got snapshotted. Project-level installs still record plain directories, as before.
No double recording
Both agents run every scope's hooks for an event, at once, and each hook gets byte-identical stdin. I verified this on Claude Code 2.1.329 and Codex 0.166: two user hooks and a project-local hook for one event got the same bytes. So the hooks of a session take turns under a lock (
hook::claim), and a hook handed an event that another finished handling within 10s does nothing. An event is the hook's name, its payload and its transcript's length. The length matters because Claude Code stopping twice for one prompt sends identical payloads, while the transcript grows in between.The first version of this PR had the wider hook step aside when a narrower file held loch's hook and the agent would run it. That needed guesses about where the agent reads settings, about trust, and about settings changed mid-session, and a wrong guess lost the turn. Review showed one: a team hook trusted at the same event, with loch's project hook untrusted. That was replaced, and the trust parsing is gone. A real Codex run of that exact case now records the turn.
Install also removes a second loch line for an event from Claude Code's settings. It leaves the line in Codex's file, where trust is keyed by position, and reports it as
duplicates. Only user-wide lines name a scope (--scope user), so project and Ness-local lines are unchanged.Other hooks untouched
Only lines
hook_linewrote are recognised (parse_hook_line). An existing loch line in another form, such as another path or no scope, is rewritten in place (reported asreplaced), so no other hook moves. Codex keys trust by position. Trust stays manual.JSON
New fields
scope,replacedandduplicates, at the top level and per agent. No field changed meaning, soschemastays 2.--local --projectis ausageerror.Verified
cargo fmt --check,clippy -D warnings,cargo test --release.New tests run the installed lines the way the harness does: they read the settings files and run every command through
sh, both in parallel and one by one. They cover:CLAUDE_CONFIG_DIR;~/.loch, no store);With the claim disabled, the double-record tests fail: Claude shows
[true, true, false]interrupted flags, and Codex records 3 turns for 2.Real Codex 0.166, in a scratch
HOME/CODEX_HOME, with hooks trusted through the TUI and no bypass flag:Claude Code: it ran
UserPromptSubmitunder a scratchHOMEbefore failing on its missing login. That was enough to show identical payloads across hooks, and that a session launched inrepo/subruns the repo root's.claude/settings.local.json.🤖 Generated with Claude Code