install: ship hooks as share/codedb/install-hooks.sh + codedb install-hooks, add nix flake - #700
Draft
poelzi wants to merge 1 commit into
Draft
Conversation
Hook setup used to live as an inline python heredoc inside install.sh, so it only ever ran during a curl install and could not be re-run, inspected, or fixed without re-downloading the installer. - install/install-hooks.sh: the hook installer as a standalone, packaged script. Carries the existing Claude Code logic verbatim (CODEDB_NO_HOOKS / ~/.codedb/no-hooks opt-out, the justrach#658 deliberate-removal receipt, repo- scoped block-legacy guard, competitor-aware hook merge, additive mcp__codedb__* permission) and adds the Codex codedb_remote guard plus features.codex_hooks that docs/hooks-labs.md previously left to the user. - Generated hooks now bake in the resolved codedb path instead of relying on `command -v codedb`; hook subshells inherit a minimal PATH, which misses ~/bin and nix store paths. - build.zig installs it to share/codedb/install-hooks.sh; `codedb install-hooks` (src/install_hooks.zig) resolves it relative to the running binary and runs it, so hooks can be (re)installed any time. - install.sh copies or fetches the same script and delegates to it; a hook failure no longer fails the install. website/ copies kept in sync. - flake.nix/flake.lock: nix build/run/develop/flake check. Zig comes from zig-overlay pinned to the master snapshot matching minimum_zig_version; autoPatchelfHook fixes the ELF interpreter zig bakes in. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TqTyTJVJ4cd1MzFF54Hrbh
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
Hook setup lives as an inline Python heredoc inside
install/install.sh. That means it only ever runs during acurl | bashinstall — it cannot be re-run, inspected before it executes, or fixed without re-downloading the installer.docs/hooks-labs.mdalso left all Codex hook wiring to the user.Changes
install/install-hooks.sh— the hook installer as a standalone, packaged script.It carries the existing Claude Code logic verbatim: the
CODEDB_NO_HOOKS/~/.codedb/no-hooksopt-out, the #658 deliberate-removal receipt, the repo-scoped block-legacy guard, the competitor-aware hook merge, and the additivemcp__codedb__*permission. Behaviour is unchanged; it just lives somewhere you can read it before it runs.codedb install-hooks(src/install_hooks.zig) resolves<prefix>/share/codedb/install-hooks.shrelative to the running binary and executes it, so hooks can be installed or repaired at any time.build.ziginstalls the script viab.installFile.install.shdelegates to the same script (copying it from a checkout, or fetching it), so there is one implementation instead of two. A hook failure no longer aborts the install. Thewebsite/copies stay byte-identical — the existing sync test covers this.Generated hooks bake in the resolved codedb path instead of relying on
command -v codedb. Hook subshells inherit a minimal PATH that misses~/binand nix store paths, socommand -vsilently fails open and the hooks never fire.flake.nix/flake.lock—nix build,nix run,nix develop,nix flake check. Zig comes fromzig-overlaypinned to themaster-2026-06-07snapshot, which is exactly theminimum_zig_versionnightly inbuild.zig.zon(nixpkgs only carries tagged releases).autoPatchelfHookrewrites the ELF interpreter zig bakes in, without which the built binary cannot execute on NixOS. The package version is parsed frombuild.zig.zonso it cannot drift.Two bugs fixed along the way
Both are pre-existing and were hit while testing:
The block-legacy hook told agents to use
codedb_edit, which the server does not expose.sed/awkwere blocked with no available alternative. Now points atcodedb_search/codedb_readplus the caller's own editor tool.The Codex hook guarded
mcp__codedb__codedb_remote, a tool currentmainno longer exposes, so the matcher could never fire while still flippingfeatures.codex_hooks = truein the user's config. Repointed atcodedb_search.One judgement call worth review:
docs/hooks-labs.md's lab example denies whenmax_resultsis missing or > 100. Denying on missing would fire on ordinary calls (the server already defaults to 20), so the packaged guard denies only an explicitmax_results > 100. Happy to change if you'd rather ship the doc's exact rule.Verification
zig buildandzig build testpass (the one unrelatedtest_indexissue-690inotify crash on this base is addressed in a separate PR).nix buildproduces a working binary;codedb install-hooksverified end to end from the nix store path — which is exactly the case the oldcommand -v codedblookup got wrong.install-hooksexercised against sandboxedHOMEs: competitor-hook front-insertion, additive permission merge, and the installer re-registers the unconditional codedb-block-legacy.sh hook, overriding user removal #658 deliberate-removal path all behave as before.bash -nclean; the Codex guard verified to denymax_results=500and stay silent for unset and for50.