Skip to content

install: ship hooks as share/codedb/install-hooks.sh + codedb install-hooks, add nix flake - #700

Draft
poelzi wants to merge 1 commit into
justrach:release/0.2.5842from
poelzi:feat/install-hooks-and-nix
Draft

install: ship hooks as share/codedb/install-hooks.sh + codedb install-hooks, add nix flake#700
poelzi wants to merge 1 commit into
justrach:release/0.2.5842from
poelzi:feat/install-hooks-and-nix

Conversation

@poelzi

@poelzi poelzi commented Aug 20, 2026

Copy link
Copy Markdown

Problem

Hook setup lives as an inline Python heredoc inside install/install.sh. That means it only ever runs during a curl | bash install — it cannot be re-run, inspected before it executes, or fixed without re-downloading the installer. docs/hooks-labs.md also 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-hooks opt-out, the #658 deliberate-removal receipt, the repo-scoped block-legacy guard, the competitor-aware hook merge, and the additive mcp__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.sh relative to the running binary and executes it, so hooks can be installed or repaired at any time. build.zig installs the script via b.installFile.

install.sh delegates 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. The website/ 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 ~/bin and nix store paths, so command -v silently fails open and the hooks never fire.

flake.nix / flake.locknix build, nix run, nix develop, nix flake check. Zig comes from zig-overlay pinned to the master-2026-06-07 snapshot, which is exactly the minimum_zig_version nightly in build.zig.zon (nixpkgs only carries tagged releases). autoPatchelfHook rewrites the ELF interpreter zig bakes in, without which the built binary cannot execute on NixOS. The package version is parsed from build.zig.zon so 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/awk were blocked with no available alternative. Now points at codedb_search / codedb_read plus the caller's own editor tool.

  • The Codex hook guarded mcp__codedb__codedb_remote, a tool current main no longer exposes, so the matcher could never fire while still flipping features.codex_hooks = true in the user's config. Repointed at codedb_search.

    One judgement call worth review: docs/hooks-labs.md's lab example denies when max_results is missing or > 100. Denying on missing would fire on ordinary calls (the server already defaults to 20), so the packaged guard denies only an explicit max_results > 100. Happy to change if you'd rather ship the doc's exact rule.

Verification

  • zig build and zig build test pass (the one unrelated test_index issue-690 inotify crash on this base is addressed in a separate PR).
  • nix build produces a working binary; codedb install-hooks verified end to end from the nix store path — which is exactly the case the old command -v codedb lookup got wrong.
  • install-hooks exercised against sandboxed HOMEs: 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.
  • Installer delegation exercised from a checkout; all generated hook scripts bash -n clean; the Codex guard verified to deny max_results=500 and stay silent for unset and for 50.

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
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