Move Claude Code hook registration into code-trace setup - #11
Closed
winjer wants to merge 1 commit into
Closed
Conversation
First slice of shrinking install.sh toward a thin bootstrap: the Stop hook registration that lived in install.sh as an embedded python3 program now ships in the binary as `code-trace setup --register-hook`. - New src/setup.rs: a pure register_stop_hook(Value) -> Value transform (migrate legacy/absolute/args code-trace hooks to the canonical bare command, dedup, preserve unrelated settings and hooks, reset malformed shapes) plus file IO that refuses to overwrite invalid JSON, wired to a `setup` subcommand. - install.sh delegates to the binary, dropping its only python3 dependency; the installer now needs no interpreter. - Hook-registration coverage moves from the python-based tests/install_hook_test.sh (deleted) to Rust: 14 unit tests on the transform plus 7 integration tests driving the real binary, including the invalid-JSON refusal. Behaviour is unchanged except JSON key ordering (serde_json sorts keys vs python's insertion order) — cosmetic and functionally identical. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This was referenced Jul 20, 2026
Contributor
Author
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.
First slice of the installer-slimming direction we discussed: move the fragile, growing logic out of
install.shand into the binary, starting with the highest fragility-per-line piece — the Claude Code Stop-hook registration, which was an embeddedpython3program.What changed
src/setup.rs— a pureregister_stop_hook(Value) -> Valuetransform (migrate legacy~/.claude/hooks/code-trace, absolute-path, and with-args hooks to the canonical barecode-tracecommand; dedup; preserve unrelated settings and unrelated Stop hooks; reset malformedhooks/Stopshapes), plus file IO that treats a missing file as empty and refuses to overwrite invalid JSON. Exposed ascode-trace setup --register-hook [--settings-file <path>].install.sh—register_claude_code_hooknow delegates to the binary, dropping the installer's onlypython3dependency. The installer no longer needs an interpreter.tests/install_hook_test.sh(deleted) to Rust: 14 unit tests on the transform + 7 integration tests driving the real built binary (CARGO_BIN_EXE_code-trace), including a new invalid-JSON-refusal case.Behaviour parity
Identical to the old python logic across all previously-covered cases (verified end to end through the sourced
install.shwrapper), with one cosmetic difference:serde_jsonsorts JSON keys alphabetically vs python's insertion order. Functionally identical — Claude Code reads it as JSON.Why
The
python3heredoc was an untested mini-program and a hidden dependency (the only thing in the project needing python). In Rust it's type-checked, unit-tested, and interpreter-free. This also establishes thesetupsubcommand pattern for migrating the remaining install steps (config write, prompts, plugin copy) incrementally.cargo test(all suites) andcargo clippy --all-targetsare clean.🤖 Generated with Claude Code