Skip to content

refactor(claude): simplify the .claude hook and bootstrap scripts - #14410

Merged
kyle-sexton merged 2 commits into
mainfrom
refactor/simplify-claude-hooks
Nov 9, 2026
Merged

kyle-sexton merged 2 commits into
mainfrom
refactor/simplify-claude-hooks

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

Closes #14326

Summary

Applies /simplify's four checks (reuse, simplification, efficiency, abstraction level) to the three .claude files #14326 lists. Outputs, exit codes, printed text, flags and names are unchanged. hook-telemetry-sink.sh is left as it is (explained below).

Fix

  • .claude/cloud-bootstrap.sh
    • needs_refresh and snapshot_problem ran the same jq lookup of the user-scope gitCommitSha. Both now call a new recorded_sha helper, defined inside the plugin block so the plugin test's extraction still includes it. The two functions keep their opposite defaults.
    • End-state verification reads each plugin's user-scope state (installed, enabled, disabled) with one jq call instead of up to three. That saves one or two jq processes per declared plugin on every session start. Each check sits in try ... catch false, so an unreadable entry still counts as no match, as the separate jq -e calls did, and short-circuit order is unchanged.
    • The check-jsonschema install writes its failure warning in one place, not in each installer branch.
    • Respelled honours as honors in an existing comment. The pre-push typos check reads the whole changed file, so this old spelling blocked the push.
  • .claude/hooks/check-affected-pre-push.sh: moved is now declared with the other push_dir_to locals, and one comment over the line length is rewrapped.
  • .claude/hooks/hook-telemetry-sink.sh: unchanged. .claude/hooks/hook-telemetry-sink.test.sh requires it to stay byte-identical to plugins/harness-ops/hooks/hook-telemetry-sink.sh outside its source block. Simplifying it would mean editing the plugin copy as well, which this issue puts out of scope.

Left alone because the change might alter behavior: the push-command parser in check-affected-pre-push.sh, and the nested bash -c that builds hook_safe_path in cloud-bootstrap.sh. The second one splits PATH by unquoted word splitting, which also glob-expands each entry. An in-process loop would stop that globbing.

Verification

Each test was run directly against the branch:

  • bash .claude/hooks/cloud-bootstrap-plugins.test.sh: PASS=79 FAIL=0
  • bash .claude/hooks/cloud-bootstrap-author.test.sh: PASS=7 FAIL=0
  • bash .claude/hooks/check-affected-pre-push.test.sh: PASS=51 FAIL=0
  • bash .claude/hooks/hook-telemetry-sink.test.sh: both PASS
  • bash plugins/guardrails/hooks/cloud-shfmt.test.sh: PASS=6 FAIL=0
  • bash scripts/check-hook-wiring-liveness.test.sh: PASS=10 FAIL=0
  • bash scripts/check-plugin-catalog-enablement.test.sh: PASS=15 FAIL=0
  • bash scripts/check-script-contract.test.sh: PASS=60 FAIL=0
  • uvx pytest -q plugins/source-control/skills/babysit-prs/scripts/tests/test_babysit_risk.py: 132 passed, 11 skipped
  • shellcheck .claude/cloud-bootstrap.sh .claude/hooks/check-affected-pre-push.sh: clean
  • typos --config _typos.toml on both edited files: clean
  • The lefthook pre-push check-affected passed.
  • A jq probe on a mixed list ([project-scope entry, user-scope disabled entry, "junk"]) gave true false true, the same results as the three separate any() checks.

Related

Epic #14161

🤖 Generated with Claude Code

kyle-sexton and others added 2 commits November 9, 2026 02:47
cloud-bootstrap.sh: needs_refresh and snapshot_problem share one
recorded_sha helper for the user-scope gitCommitSha lookup; the
end-state check reads each plugin's user-scope state with one jq call
instead of up to three; the check-jsonschema install prints its warning
from one place.

check-affected-pre-push.sh: declare `moved` with the other locals and
rewrap an over-long comment.

hook-telemetry-sink.sh is unchanged: hook-telemetry-sink.test.sh holds
it byte-identical to the harness-ops reference sink.

Closes #14326

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The pre-push typos check reads every changed file whole, so the
pre-existing `honours` in a cloud-bootstrap.sh comment now blocks the push.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kyle-sexton
kyle-sexton marked this pull request as ready for review November 9, 2026 07:50
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-09T07:50:21.157703Z
We couldn’t complete this review. Comment @codex review to try again.
4701b3b Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@kyle-sexton
kyle-sexton enabled auto-merge November 9, 2026 07:51
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 4701b3bf2adb93765efb24604c27fb5e8bebad40: read 2 of 2 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #14410 (head 4701b3b)

I found no security issues. This was a full review; the prior-findings file says this lane had not reviewed an earlier head.

Both changed files match the **/.claude/** trusted path. I read every hunk of each, plus the surrounding code in .claude/cloud-bootstrap.sh (lines 240–450) to see what the changed logic gates.

.claude/cloud-bootstrap.sh

  • recorded_sha helper (L292-L296): it runs the same jq filter on the same registry path that needs_refresh and snapshot_problem each used to run inline. It is defined before either function is called. Both functions still keep their own guards, so nothing changes:
    • needs_refresh still answers "do not bother" when it can't tell.
    • snapshot_problem still fails closed with a "cannot verify" reason on an empty or null SHA.
  • End-state verification (L421-L441): three jq -e calls became one @tsv call. It still fails closed:
    • The jq only runs when listed=1, which means type == "array" was checked at L411.
    • Each predicate is wrapped in try … catch false.
    • If jq fails or read gets nothing, the variables stay empty, and [[ "$on_user" != true ]] then reports "not installed at user scope".
    • The default-disabled exception still needs enabled == false (a JSON boolean) and a catalog defaultEnabled: false entry, as before.
  • check-jsonschema install: moving || echo … from inside each branch to after the whole if … fi gives the same exit and warning behavior. The check_jsonschema_pin pin is unchanged.
  • honours → honors: comment only.

.claude/hooks/check-affected-pre-push.sh

  • local moved=0 moved onto the function's first local line. It is still local to push_dir_to and still set before the nested end_segment uses it, so the pre-push guard's parsing is unchanged. The other hunk only rewraps a comment.

Nothing in the diff widens a trusted-actor list, a token scope, a kill switch, a merge hold, or what untrusted text reaches a lane. No plugin manifest changed. No standing instruction was deleted or softened, so the instruction-exception register did not need to be consulted. The PR context file contains no embedded directives aimed at this lane.

critical-findings: 0

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

claude-review reviewed 4701b3bf2adb93765efb24604c27fb5e8bebad40: read 2 of 2 changed file(s); 0 finding(s), 0 as inline comments.

Code review: no findings

I read every hunk of both changed files (.claude/cloud-bootstrap.sh and .claude/hooks/check-affected-pre-push.sh). I also read the unchanged code those hunks call in cloud-bootstrap.sh, lines 240–464. Both files are on trusted paths (**/.claude/**), so I read their whole change.

Behavior equivalence (checked by reading the code; I ran nothing):

  • recorded_sha: it uses the same jq program and the same 2>/dev/null | tr -d '\r' as the two lookups it replaces. It is defined at L292, before the first caller (L367 loop) and inside the plugin block. needs_refresh and snapshot_problem still keep their opposite defaults.
  • One jq call per id in end-state verification (L423–441):
    • listed=1 guarantees end_state is an array, so .[]? iterates the same elements as before.
    • try any(...) catch false gives false wherever the old jq -e exited nonzero (a jq error, or a false result), and any's short-circuit order is unchanged.
    • If jq is missing or fails, read gets nothing, so all three variables stay empty and the code takes the same not installed at user scope branch as before.
    • The @tsv fields are always true or false, so collapsing tab separators in IFS whitespace cannot shift a field.
    • The enabled/default-disabled condition is the same boolean as before, with the same default_disabled membership test.
  • check-jsonschema install (L562–566): an if compound returns the status of the branch it ran, so fi || echo ... warns in exactly the cases the two per-branch || echo did.
  • check-affected-pre-push.sh: moved=0 now sits with the other push_dir_to locals and is still in the same function scope, set before end_segment can run. The other change only rewraps a comment.

Closing issue #14326:

  • Behavior unchanged: met, as far as reading shows. .claude/hooks/cloud-bootstrap-plugins.test.sh asserts the verification reasons ("not installed at user scope", "not enabled", the defaultEnabled exception, a missing gitCommitSha), so a regression there would fail a test.
  • Diff edits only the listed files: met (2 of the 3 listed files; the PR body explains why hook-telemetry-sink.sh is unchanged).
  • Within 400 lines / 15 files: met.
  • ci-status green: I can't check this from here. The test runs in the PR body are the author's claims, not results I verified.

No manifest changes, no paved-path concerns, and no embedded instructions in the PR context.

@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 9, 2026
Merged via the queue into main with commit e29987f Nov 9, 2026
80 checks passed
@kyle-sexton
kyle-sexton deleted the refactor/simplify-claude-hooks branch November 9, 2026 08:02
@github-actions github-actions Bot added the merge-path: owner-agent Post-merge accounting record (README.md, Merge paths) label Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-path: owner-agent Post-merge accounting record (README.md, Merge paths)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Simplify the .claude and hooks .claude files

1 participant