Skip to content

chore: wire the claude-ops reference telemetry sink for this repo's own hooks - #2048

Merged
kyle-sexton merged 6 commits into
mainfrom
chore/wire-telemetry-sink
Aug 9, 2026
Merged

kyle-sexton merged 6 commits into
mainfrom
chore/wire-telemetry-sink

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

No linked issue

Summary

Dogfoods the hook-telemetry opt-in contract in this repo and settles #2021 remediation line 5: the six inert claude-ops audit hooks are consumer-opt-in by design, not dead weight — the correct remediation is wiring the sink here, not retiring the hooks.

Fix

  • Copies the reference sink to .claude/hooks/hook-telemetry-sink.sh, repointed at the repo's SSOT lib/hook-utils.sh (the sink sources hook-utils.sh from its own directory, so the README's bare-copy form fails at startup).
  • Sets HOOK_TELEMETRY_SINK: .claude/hooks/hook-telemetry-sink.sh in .claude/settings.json env — relative values resolve against the consuming repo root per the plugin README; env map semantics verified against https://code.claude.com/docs/en/settings (fetched this session).
  • Fixes the claude-ops README wiring form to name the hook-utils.sh dependency; claude-ops 0.27.3 → 0.27.4 with changelog.

Verification

Smoke-tested the wired sink in the worktree: a valid envelope (hook, hook_event, duration_ms, status) appends the mapped record to .claude/observability/hook-events.jsonl; an invalid envelope exits 0 silently (fire-and-forget contract). Catalog/cheat-sheet regeneration: no diff.

Related

Refs #2021 (line 5 disposition: document-and-dogfood). Note: claude-ops itself stays out of this repo's enabledPlugins (lean-set curation per docs/CLOUD-SESSIONS.md) — the sink pays for itself via the already-enabled guardrails + formatter envelope producers.

🤖 Generated with Claude Code

…wn hooks

Dogfoods the hook-telemetry opt-in contract: copies the reference sink to
.claude/hooks/ (repointed at the repo's SSOT lib/hook-utils.sh) and sets
HOOK_TELEMETRY_SINK in .claude/settings.json, so the enabled envelope
producers (guardrails, the formatters) flow into
.claude/observability/hook-events.jsonl for /claude-ops:observability.

Also fixes the claude-ops README's "copy the reference sink" wiring form,
which omitted the sink's hook-utils.sh source dependency — the documented
bare copy fails at startup. claude-ops 0.27.3 -> 0.27.4.

Settles #2021 remediation line 5 as document-and-dogfood: the six inert
audit hooks are consumer-opt-in by design (README "no-op until a consumer
wires a sink"), not dead weight.

Co-Authored-By: Claude Fable 5 <[email protected]>
@cursor

cursor Bot commented Aug 8, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@claude

claude Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 3m 25s —— View job


Security review: PR #2048 (wire claude-ops telemetry sink)

  • Gather context (diff, changed files)
  • Review .claude/hooks/hook-telemetry-sink.sh
  • Review .claude/settings.json changes
  • Review plugins/claude-ops/plugin.json / README / CHANGELOG changes
  • Post findings

Scope: the 5 files changed in this PR (.claude/hooks/hook-telemetry-sink.sh, .claude/settings.json, plugins/claude-ops/.claude-plugin/plugin.json, plugins/claude-ops/README.md, plugins/claude-ops/CHANGELOG.md). Reviewed the diff plus the pre-existing (unchanged) hook::emit_telemetry / hook::repo_root / hook::append_jsonl functions in lib/hook-utils.sh for calling context. No GitHub Actions files in this diff, so no pull_request_target/workflow_run/permissions findings apply.


1. IMPORTANT — Committed sink script is non-executable, silently disabling the audit trail it claims to enable

File: .claude/hooks/hook-telemetry-sink.sh

The new file is committed with mode 100644 (verified via git ls-files -s), not 100755 like the reference copy at plugins/claude-ops/hooks/hook-telemetry-sink.sh (mode 100755). The consumer, hook::emit_telemetry in lib/hook-utils.sh (unchanged by this PR), invokes the sink as a bare executable, not via bash:

printf '%s\n' "$envelope" | ("$sink" >/dev/null 2>&1) &

— lib/hook-utils.sh#L879

On a fresh clone (any POSIX checkout — Linux/macOS respect the git executable bit), execing a 644 file fails with "Permission denied" (exit 126). Because the call site backgrounds the subshell and redirects both stdout and stderr to /dev/null (by design, per the fire-and-forget contract), this failure is completely silent — no error surfaces anywhere.

Why this matters for security, not just correctness: the six claude-ops audit hooks this PR is meant to wire up (permission-denied-audit, config-change-audit, tool-failure-audit, pre-compact-audit, instructions-loaded-audit, skill-usage-audit) are exactly the audit/detection surface a security-conscious team would rely on to notice guardrail bypasses, unexpected config changes, or permission denials. A telemetry pipeline that looks wired (env var set, sink file present, PR says "smoke-tested... appends the mapped record") but silently never executes is a false sense of monitoring coverage — worse in some ways than no telemetry at all, because nothing signals the gap.

The PR body's own verification claim ("Smoke-tested the wired sink in the worktree... appends the mapped record") is very likely true only because the author's local worktree copy had the executable bit set (e.g., via cp --preserve or a local chmod +x) and that bit was never git added / committed.

Confidence: High — directly confirmed via git ls-files -s:

100644 50e290d3b864d3b289421bdd627c55a53bd8ead5 0  .claude/hooks/hook-telemetry-sink.sh
100755 24929dfd61c4bcd9b4b5a5f869190a9e3345e7ea 0  plugins/claude-ops/hooks/hook-telemetry-sink.sh

Fix: chmod +x .claude/hooks/hook-telemetry-sink.sh && git add --chmod=+x .claude/hooks/hook-telemetry-sink.sh (or re-stage with the mode set) before merge.

Fix this →


No other security issues found

  • Injection surfaces: the sink parses the telemetry envelope entirely through jq -r/jq -nc with --arg/--argjson parameter binding — no field value is ever interpolated into a shell command, eval, or filename built from untrusted input. data.tool/data.subject (the fields most likely to carry externally-influenced content, e.g. file paths) flow through as bound jq arguments only. No injection path found.
  • Path handling: log_dir is derived from hook::repo_root (a git rev-parse --show-toplevel call) plus a fixed .claude/observability suffix — not attacker-influenced. .claude/observability/ is git-ignored (.gitignore:14), so telemetry output can't leak into commits.
  • Trust boundary / opt-in contract: the sink only activates when HOOK_TELEMETRY_SINK is set in the repo's own tracked .claude/settings.json, i.e., under this repo's control — consistent with the plugin's documented "consumer-opt-in, no-op until wired" design. No new attack surface is exposed to untrusted external actors.
  • Fail-open behavior (missing jq, malformed envelope, empty input, sink write failure) is scoped to dropping a telemetry record, never to escalating privileges or affecting the hook's own exit code/stdout — consistent with the documented fire-and-forget contract.
  • Settings/permissions: the only change to .claude/settings.json is the new env.HOOK_TELEMETRY_SINK key; no permissions block, enabledPlugins, or hook matcher/command entries were touched. No permission-widening.
  • Version/README/CHANGELOG changes (plugin.json 0.27.3→0.27.4, README wiring-note fix, CHANGELOG entry) are documentation/metadata only, no executable or trust-boundary impact.
  • Supply-chain / unpinned-action / excessive-permissions / trigger-pattern concerns are out of scope for this lane per instructions (zizmor's advisory lane), and this diff contains no workflow files regardless.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 63deaa3ba1

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .claude/hooks/hook-telemetry-sink.sh Resolved
The sink is invoked as an executable via HOOK_TELEMETRY_SINK; CI's exec-bit
hygiene check requires mode 100755 on hook scripts.

Co-Authored-By: Claude Fable 5 <[email protected]>
@claude

claude Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 1m 58s —— View job


Security review: PR #2048 (wire claude-ops telemetry sink) — re-run at 770f8e3

  • Gather context (diff, changed files)
  • Review .claude/hooks/hook-telemetry-sink.sh (post-fix state)
  • Review .claude/settings.json changes
  • Review plugins/claude-ops/plugin.json / README / CHANGELOG changes
  • Post findings

Scope: the 5 files changed in this PR, diffed against the PR's actual base commit d894e3b (.claude/hooks/hook-telemetry-sink.sh, .claude/settings.json, plugins/claude-ops/.claude-plugin/plugin.json, plugins/claude-ops/README.md, plugins/claude-ops/CHANGELOG.md), plus the pre-existing (unchanged) hook::emit_telemetry / hook::repo_root / hook::append_jsonl in lib/hook-utils.sh for calling context. No GitHub Actions files in this diff.


Previously-flagged issue: now fixed

My prior pass on commit 63deaa3 flagged the sink as committed non-executable (100644), which meant hook::emit_telemetry's direct ("$sink" ...) exec (no bash wrapper — lib/hook-utils.sh#L879) would fail silently (exit 126, output redirected to /dev/null, backgrounded), defeating the audit trail this PR exists to wire up.

Commit 770f8e3 fixes this directly — old mode 100644 / new mode 100755 on .claude/hooks/hook-telemetry-sink.sh, no other changes in that commit. Verified via git show 770f8e3 -- .claude/hooks/hook-telemetry-sink.sh. Resolved.


No security issues found in the current state

  • Sink content vs. reference: diffed .claude/hooks/hook-telemetry-sink.sh against plugins/claude-ops/hooks/hook-telemetry-sink.sh at the PR base — the only delta is the source line repointed from a colocated hook-utils.sh to the repo's SSOT copy at ../../lib/hook-utils.sh (plus a comment explaining why), exactly as described in the PR body. No logic changes.
  • Injection surfaces: all envelope fields flow through jq -r / jq -nc with --arg / --argjson binding only — no field is interpolated into a shell command, eval, or a filename built from untrusted input.
  • Path handling: log_dir derives from hook::repo_root (git rev-parse --show-toplevel-based) plus a fixed .claude/observability suffix — not attacker-influenced. Confirmed .claude/observability/ remains git-ignored (.gitignore:14), so sink output can't leak into commits.
  • Sink path resolution (lib/hook-utils.sh#L858-L870, unchanged by this PR): a relative HOOK_TELEMETRY_SINK is joined onto the resolved repo root, or skipped fail-open if no root is available — never exec'd from a drifted/ambiguous CWD.
  • Trust boundary / opt-in contract: activation is gated entirely on HOOK_TELEMETRY_SINK in this repo's own tracked .claude/settings.json — no new attack surface exposed to untrusted external actors, no permissions or enabledPlugins changes.
  • Fail-open behavior (missing jq, malformed envelope, empty input, lock/write failure) only drops a telemetry record — never affects the producing hook's own exit code or stdout (the "never write to fd1" contract holds).
  • plugin.json / README.md / CHANGELOG.md changes are version bump + documentation only, no executable or trust-boundary impact.

Supply-chain / unpinned-action / trigger-pattern concerns remain out of scope for this lane (zizmor's advisory lane), and this diff contains no workflow files.

Conclusion: no outstanding security issues in this PR at 770f8e3.

@claude

claude Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 4m 9s —— View job


Code review: PR #2048 (wire claude-ops telemetry sink)

  • Gather context (diff, changed files)
  • Review .claude/hooks/hook-telemetry-sink.sh
  • Review .claude/settings.json changes
  • Review plugins/claude-ops plugin.json / README / CHANGELOG changes
  • Post findings

Lane scope: correctness/architecture/error-handling/test-coverage/maintainability. Security is out of scope here — the security-review lane and Codex already flagged (and this PR's second commit, 770f8e3, already fixed) the non-executable-bit issue on the sink; not duplicating that.


Findings

1. Maintainability — the new repo-local sink is a full duplicate with no drift check covering it. Posted inline on .claude/hooks/hook-telemetry-sink.sh. It's byte-for-byte identical to plugins/claude-ops/hooks/hook-telemetry-sink.sh except for the source ../../lib/hook-utils.sh line. Neither of this repo's two existing drift mechanisms sees this pair: scripts/sync-hook-utils.sh only tracks hook-utils.sh copies, and scripts/check-cross-plugin-source-drift.sh (whose own stated purpose is catching exactly this kind of new shared-copy pattern) only scans under plugins/*/, so a copy under .claude/hooks/ is structurally invisible to it. The next fix to the reference sink's mapping logic (this PR's own CHANGELOG shows the sink evolving release-to-release) has nothing automatically flagging this dogfood copy as stale.

2. Minor — no test coverage for the repo-local copy's one point of difference. The upstream reference sink ships plugins/claude-ops/hooks/hook-telemetry-sink.test.sh, exercising the mapping/parsing logic. The new .claude/hooks/hook-telemetry-sink.sh has no sibling test, so the one line that actually differs from the tested original — the relative source path resolving hook-utils.sh from .claude/hooks/../../lib/ — is verified only by the PR description's manual smoke test, not by anything CI re-runs. I weigh this as low-priority: this repo doesn't have a blanket convention wiring every .claude/hooks/*.sh into an automated test (session-start.sh has none either, and even the existing pr-linkage-mcp-gate.test.sh doesn't appear to be invoked from .github/workflows/ci.yml), so this isn't a regression against an established bar — just a gap worth closing given the file's only novel content is untested.

3. Everything else checked out:

  • .claude/settings.json's new env.HOOK_TELEMETRY_SINK entry is well-formed and matches the sink's committed path; no other keys touched.
  • I independently fetched https://code.claude.com/docs/en/settings and confirmed the PR body's claim that env values are injected literally with no ${VAR} expansion — the relative-path wiring form this PR relies on is consistent with that.
  • plugin.json version bump (0.27.3 → 0.27.4), README addition, and CHANGELOG entry are all consistent with each other and with the existing Keep-a-Changelog format used by prior entries in this file.
  • The sink's cross-directory source "$(dirname "${BASH_SOURCE[0]}")/../../lib/hook-utils.sh" pattern mirrors the existing pr-linkage-mcp-gate.sh precedent of reaching a shared script by relative BASH_SOURCE path, so it's consistent with this repo's established convention rather than a one-off.
  • Field-mapping/parsing logic in the sink itself is unchanged from the already-shipped, already-tested upstream reference implementation, so I didn't re-litigate its internals here.

Comment thread .claude/hooks/hook-telemetry-sink.sh Resolved
@github-actions

github-actions Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Claude has reviewed this PR 4 times. The lane skips further automatic reviews after 5; deleting this comment resets the count.

… reference

The repo-local copy is byte-identical to the reference sink except for its
hook-utils.sh resolution block; nothing previously watched the pair (the
cross-plugin drift tooling clusters plugins/* only, so a .claude/hooks copy
is outside its scope). The test diffs the two modulo that block and names
the re-copy procedure on failure. It runs directly today and joins CI when
the plugin-test runner is extended to .claude/hooks tests (queued follow-up
to #2021 line 4's defer-guard PR).

Co-Authored-By: Claude Fable 5 <[email protected]>
@kyle-sexton

Copy link
Copy Markdown
Member Author

Both threads addressed: the exec bit was fixed in 770f8e3 (the P1 was anchored to the initial commit), and e473251 adds a dedicated drift test binding the repo-local copy to the claude-ops reference sink modulo the source-resolution block — the cross-plugin drift tooling can't cover it because it clusters plugins/* paths only. The test joins CI when the plugin-test runner is extended to .claude/hooks tests (queued follow-up PR for #2021 line 4).

…sink

# Conflicts:
#	plugins/claude-ops/CHANGELOG.md
@claude

claude Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 1m 18s —— View job


Security review: PR #2048 (wire claude-ops telemetry sink) — re-run at 469a06a

  • Gather context (git diff origin/main...HEAD, changed files)
  • Review .claude/hooks/hook-telemetry-sink.sh (post-merge state)
  • Review .claude/hooks/hook-telemetry-sink.test.sh (new drift check)
  • Review .claude/settings.json changes
  • Review plugins/claude-ops plugin.json / README / CHANGELOG changes
  • Post findings

Scope: the 6 files changed in this PR versus origin/main, plus the pre-existing (unchanged) hook::emit_telemetry / hook::repo_root / hook::append_jsonl in lib/hook-utils.sh for calling context. No GitHub Actions files in this diff.


Previously-flagged issue: confirmed still fixed

My earlier pass on 63deaa3 flagged the sink as committed non-executable (100644), which would have made hook::emit_telemetry's direct ("$sink" ...) exec (no bash wrapper — lib/hook-utils.sh#L879) fail silently (exit 126, redirected to /dev/null, backgrounded), defeating the audit trail this PR wires up. The current diff still shows .claude/hooks/hook-telemetry-sink.sh staged as new file mode 100755 at this HEAD — the fix from 770f8e3 survived the merge from main. Confirmed resolved.


New since last review: .claude/hooks/hook-telemetry-sink.test.sh

This drift check (blob) only reads and diffs two repo-local files with fixed, hardcoded paths — no untrusted input, no eval, no command construction from variable data. Not wired into any CI trigger by this PR (per the PR thread, that's a queued follow-up), so it adds no new automated-execution attack surface today. No findings.


No security issues found in the current state

  • Injection surfaces: all envelope fields flow through jq -r / jq -nc with --arg / --argjson binding only (.claude/hooks/hook-telemetry-sink.sh#L38-L41, #L73-L82) — no field is interpolated into a shell command, eval, or a filename built from untrusted input.
  • Sink content vs. reference: unchanged from my prior pass — the only delta from plugins/claude-ops/hooks/hook-telemetry-sink.sh is the source line repointed to the repo's SSOT lib/hook-utils.sh (.claude/hooks/hook-telemetry-sink.sh#L26-L28); logic is otherwise byte-identical, now with an automated test enforcing that.
  • Path handling: log_dir derives from hook::repo_root plus a fixed .claude/observability suffix (.claude/hooks/hook-telemetry-sink.sh#L84-L86) — not attacker-influenced; .claude/observability/ remains git-ignored, so sink output can't leak into commits.
  • Sink path resolution (lib/hook-utils.sh#L858-L870, unchanged): a relative HOOK_TELEMETRY_SINK is joined onto the resolved repo root, or skipped fail-open with no root available.
  • Trust boundary / opt-in contract: activation is gated entirely on HOOK_TELEMETRY_SINK in this repo's own tracked .claude/settings.json — full contents reviewed (.claude/settings.json); only the new env.HOOK_TELEMETRY_SINK key was added. No permissions block, no enabledPlugins change (claude-ops correctly stays out, per the PR description), no hook matcher/command changes. No permission-widening.
  • Fail-open behavior (missing jq, malformed envelope, empty input, mkdir/write failure) only drops a telemetry record, never affects the producing hook's own exit code or stdout — the "never write to fd1" contract holds.
  • plugin.json (0.27.4 → 0.27.5), README.md, CHANGELOG.md changes are version bump + documentation only, no executable or trust-boundary impact.

Supply-chain / unpinned-action / trigger-pattern concerns remain out of scope for this lane (zizmor's advisory lane), and this diff contains no workflow files.

Conclusion: no outstanding security issues in this PR at 469a06a.

@claude

claude Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 6m 25s —— View job


Code review: PR #2048 (wire claude-ops telemetry sink) — re-run at 469a06a

  • Gather context (diff since last review, changed files)
  • Review new commit(s): drift test, exec-bit fix, merge from main
  • Check maintainability/test-coverage findings from prior reviews for resolution
  • Post findings

Lane scope: correctness/architecture/error-handling/test-coverage/maintainability, per REVIEW.md's lane split — security stays with the dedicated security lane, which already reviewed this PR twice.

Since the last code-review pass (at 770f8e3), the branch merged main and added one new commit, e473251 (test: add a drift check binding the repo-local sink to the claude-ops reference), directly responding to my prior maintainability finding. I re-verified the state of both findings from that pass rather than re-litigating already-settled ground.


Findings

1. .claude/hooks/hook-telemetry-sink.test.sh closes the drift-coverage gap but not the source-path-correctness gap. Posted inline on hook-telemetry-sink.test.sh#L25.

I independently re-derived the test's normalize() filter against both files' actual committed content (pulled both blobs via git show, applied the same grep -v -E exclusion patterns, diffed the result myself — not just reading the PR's claim) and confirmed it currently passes: the repo-local copy is otherwise byte-identical to plugins/claude-ops/hooks/hook-telemetry-sink.sh. That resolves the first prior finding (no drift protection for a pair check-cross-plugin-source-drift.sh structurally can't see, since it only scans plugins/*/).

The second prior finding — no automated check on the one line that actually differs, the relative source path to hook-utils.sh — is not resolved by this test, though it looks like it should be. The exclusion regex matches by line-prefix (^source "\$\(dirname), so it strips any line shaped that way from the comparison, including one with a wrong or typo'd path. A broken source line would still pass. Details and a suggested functional-test addition are in the inline comment.

This isn't a blocker: the test isn't wired into CI yet either way (confirmed directly — scripts/run-plugin-tests.sh only globs plugins/**/*.test.sh, and .github/workflows/ci.yml names every *.test.sh step it runs explicitly, neither covers .claude/hooks/*.test.sh), consistent with the test's own header comment and kyle-sexton's comment about a queued follow-up PR extending the runner. Worth folding into that follow-up.

2. Exec-bit fix and its scope are correctly closed out. Independently confirmed via git show 770f8e3 --raw that the fix commit is a pure mode change (100644→100755, same blob hash 50e290d, zero content diff) — matches what the security lane reported. Also confirmed via .github/workflows/ci.yml (lines 38–41) that this repo runs an unconditional, repo-wide exec-bit check flagging every tracked shebang file recorded 100644, so this class of bug is now caught mechanically going forward, not just by manual review. The new test file (hook-telemetry-sink.test.sh) is itself committed at 100755 (verified via git show e473251 --raw), so it doesn't reintroduce the same class of bug.

3. Everything else re-checked at the current HEAD, no new issues:

  • plugins/claude-ops/.claude-plugin/plugin.json is now 0.27.5 (the merge from main picked up an unrelated 0.27.4 entry first) with a matching CHANGELOG.md entry — version and changelog stay consistent.
  • .claude/settings.json's env.HOOK_TELEMETRY_SINK entry and the README wiring-note fix are unchanged from the previously-reviewed content and still consistent with each other.
  • No other files in the PR's diff changed since the last code-review pass.

Note on environment, not the PR: the local working tree in this review sandbox had .claude/hooks/hook-telemetry-sink.sh, .claude/hooks/hook-telemetry-sink.test.sh, and the env block in .claude/settings.json missing/reverted on disk despite being present at HEAD — I read all committed content via git show HEAD:<path> instead of the working tree, and did not touch or restore those files. This looks like a review-sandbox artifact (plausibly the harness declining to materialize a hook script that widens settings.json's env/hook surface for an automated reviewer), not something introduced by this PR.
· branch chore/wire-telemetry-sink

…lcheck

SC2310 (function invoked in a condition disables set -e) fails the CI
shellcheck lane at info severity; the normalize step now writes temp files
and the conditions test plain commands.

Co-Authored-By: Claude Fable 5 <[email protected]>
@claude

claude Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 1m 2s —— View job


Security review: PR #2048 (wire claude-ops telemetry sink) — re-run at a43de9a

  • Gather context (diff since last review at 469a06a, changed files)
  • Review new commit a43de9a (precompute normalized files for drift test)
  • Confirm previously-fixed issues (exec bit) still hold
  • Post findings

Scope: everything changed between the last reviewed commit (469a06a) and current HEAD (a43de9a). That's a single commit touching one file: .claude/hooks/hook-telemetry-sink.test.sh (git diff 469a06a..a43de9a --stat confirms no other file changed — .claude/hooks/hook-telemetry-sink.sh, .claude/settings.json, and plugins/claude-ops/* are untouched by this commit).


What changed

a43de9a ("fix: precompute normalized files so the drift test passes strict shellcheck") replaces a normalize() shell function called inside diff -u <(normalize ...) <(normalize ...) — which trips shellcheck's SC2310 (function invoked in a condition disables set -e) — with the equivalent logic inlined: grep -v -E "$strip_re" writes to two mktemp temp files, cleaned up via an EXIT trap, and diff -u compares the plain files instead of process substitutions.

This is a pure control-flow refactor of the drift-check test added in the prior commit (e473251) — no change to what is compared or how.

No security issues found

  • strip_re is a fixed, hardcoded regex literal — not derived from any external or file-content input — so grep -v -E "$strip_re" carries no injection risk.
  • The two mktemp paths (norm_upstream, norm_local) are process-local temp files with no attacker-influenced naming, cleaned up unconditionally via trap ... EXIT.
  • $upstream / $local_copy are still derived the same way as before (fixed, repo-relative paths off BASH_SOURCE), unchanged by this commit.
  • This test script only reads two repo-local files and diffs them — no execution of file contents, no eval, no network or credential access. Confirmed not wired into any CI trigger by this PR (per the PR thread, that remains a queued follow-up), so it still adds no new automated-execution attack surface.
  • The previously-flagged and previously-fixed non-executable-bit issue on the sink itself (.claude/hooks/hook-telemetry-sink.sh, mode 100755 since 770f8e3) is untouched by this commit and remains fixed.

Conclusion: no security issues in this PR at a43de9a. This commit is a mechanical shellcheck-compliance fix to the drift test with no behavioral or trust-boundary impact.
· branch chore/wire-telemetry-sink

@claude

claude Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 2m 34s —— View job


Code review: PR #2048 (wire claude-ops telemetry sink) — re-run at a43de9a

  • Gather context (gh pr diff 2048, full 4-commit patch series)
  • Review new commit a43de9a (shellcheck fix to the drift test)
  • Re-check prior findings (executable bit, duplicate/drift coverage, test coverage)
  • Post findings

Lane scope: correctness/architecture/error-handling/test-coverage/maintainability. Security is out of scope (dedicated security lane already reviewed and cleared this PR through 469a06a, and this commit touches no sink logic).


What's new since the last code-review pass (770f8e3)

Both findings from my prior pass are resolved:

  • Executable bit — fixed in 770f8e3, still holds.
  • No drift check across the .claude/hooks/ ↔ plugins/claude-ops/hooks/ copy — e473251 added .claude/hooks/hook-telemetry-sink.test.sh, which diffs the two files modulo the source-repoint block and fails on any other divergence. Also closes the test-coverage gap noted in the same pass.

a43de9a is a follow-up mechanical fix to that new test file only — no other file changed in this commit.

Review of a43de9a

The prior version of the test called a local normalize() function inside process substitutions that fed the if diff ...; then condition — SC2310 flags that because a function invoked (even transitively, via a command substitution that's part of the condition list) as part of an if/&&/|| condition has set -e suppressed for that invocation, per bash's documented conditional-context behavior. The fix replaces the function + <(...) pattern with two precomputed temp files (mktemp) and a plain diff -u "$norm_upstream" "$norm_local" as the condition:

Traced it against the rest of the script and it's behavior-preserving:

  • The two mktemp calls happen before the trap ... EXIT is registered, but before any command that could plausibly fail, so there's no leak window in practice.
  • grep -v -E "$strip_re" ... || true correctly tolerates grep's exit 1 ("no lines removed" — not expected here, but would be benign) without tripping set -euo pipefail.
  • The strip regex and its five alternatives are unchanged from e473251, so the actual drift-detection semantics (diff modulo the source-repoint block) are untouched by this commit — only the mechanism for producing the two normalized inputs changed.
  • Both the pass and fail branches were updated consistently to reference the new temp-file variables; no stale <(normalize ...) call left behind.

I don't see a correctness issue introduced by this change. One process note: I attempted to run shellcheck directly against the committed file to independently confirm the SC2310 finding is actually clear now, but the tool invocation required interactive approval that wasn't granted in this session — so I can't independently confirm the "passes strict shellcheck" claim in the commit message; it's author-claimed and unverified from my end. The logic itself checks out on manual review regardless.

Outstanding from earlier passes (unchanged, not new)

  • The drift test still only runs manually (bash .claude/hooks/hook-telemetry-sink.test.sh) — it isn't wired into scripts/run-plugin-tests.sh yet. Per the PR thread this is an intentionally queued follow-up once the plugin-test runner is extended to .claude/hooks tests, not a gap introduced by this PR.

Conclusion: no new findings at a43de9a. The commit is a narrowly-scoped, behavior-preserving lint fix to the drift test added earlier in this PR.
· branch chore/wire-telemetry-sink

The normalize exclusion is a prefix match, so it could not detect a copy
whose source line points at a broken target. The test now asserts the
exact ../../lib/hook-utils.sh target and proves the wiring end-to-end: a
valid envelope through the repo copy must append a record under a temp
CLAUDE_PROJECT_DIR.

Co-Authored-By: Claude Fable 5 <[email protected]>
@claude

claude Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 1m 22s —— View job


Security review: PR #2048 (wire claude-ops telemetry sink) — re-run at d2348b5

  • Gather context (diff since last security pass at a43de9a, changed files)
  • Review new commit d2348b5 (pin the source target and smoke-run the sink in the drift check)
  • Confirm previously-fixed issues (exec bit) still hold
  • Post findings

Scope: everything changed between the last reviewed commit (a43de9a) and current HEAD (d2348b5). That's a single commit touching one file — git diff a43de9a..d2348b5 --stat confirms only .claude/hooks/hook-telemetry-sink.test.sh changed; hook-telemetry-sink.sh, .claude/settings.json, and plugins/claude-ops/* are untouched by this commit.


What changed

d2348b5 adds 21 lines to the end of the drift-check test (blob), directly closing the gap the code-review lane flagged on the prior commit (normalize()'s exclusion regex was a prefix match, so it would silently pass a source line pointed at a wrong/typo'd target):

  1. A grep -qF pin asserting the local copy's source line is exactly source "$(dirname "${BASH_SOURCE[0]}")/../../lib/hook-utils.sh".
  2. A functional smoke test: pipes a fixed, hardcoded envelope literal through bash "$local_copy" with CLAUDE_PROJECT_DIR pointed at a fresh mktemp -d, then asserts a non-empty hook-events.jsonl landed under that temp dir.

No security issues found

  • No injection surface. expected_source and the smoke-test envelope are both fixed string literals in the script, not derived from any external, file, or environment input. grep -qF (fixed-string mode) is used for the pin check, so no regex-metacharacter concerns either.
  • Isolation of the smoke run is correct. CLAUDE_PROJECT_DIR="$smoke_dir" points hook::repo_root (in the sourced lib/hook-utils.sh) at an isolated mktemp -d, not the real repo. Traced hook::repo_root: since $smoke_dir isn't a git worktree, git -C "$hint" rev-parse --show-toplevel fails and the function falls back to using $hint itself as root, so the sink's mkdir -p/append only ever touches $smoke_dir/.claude/observability/ — confirmed this can't write into the real repo tree or leak into git-tracked paths.
  • Cleanup. The second trap ... EXIT (line 42) correctly supersedes the first and covers all three temp artifacts ($norm_upstream, $norm_local, $smoke_dir) — no resource leak, and no window where a stale trap misses the new temp dir.
  • No new execution surface. This file is still not wired into any CI trigger (scripts/run-plugin-tests.sh globs plugins/**/*.test.sh only; .github/workflows/ci.yml names each *.test.sh step explicitly and doesn't include this one) — same as previously confirmed, unchanged by this commit. It remains manual-invocation-only.
  • File mode unchanged. git show d2348b5 --raw confirms 100755 → 100755 — no mode regression reintroducing the previously-fixed non-executable-sink issue.
  • The previously-flagged and previously-fixed non-executable-bit issue on the sink itself (.claude/hooks/hook-telemetry-sink.sh, mode 100755 since 770f8e3) is untouched by this commit and remains fixed; also now backstopped by the repo's unconditional exec-bit CI check (confirmed in an earlier pass).

Conclusion: no security issues in this PR at d2348b5. This commit is a test-only strengthening of the drift check with no behavioral or trust-boundary impact — it tightens verification, it doesn't touch the sink's logic, the settings wiring, or introduce new inputs from an untrusted source.
· branch chore/wire-telemetry-sink

@kyle-sexton

Copy link
Copy Markdown
Member Author

Accepted and fixed in d2348b5: the drift test now pins the exact expected source line (a prefix-match exclusion alone could pass a copy pointing at a broken target) and smoke-runs the wired copy end-to-end — a valid envelope through the repo copy must append a record under a temp CLAUDE_PROJECT_DIR, proving the source target resolves.

@claude

claude Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 3m 22s —— View job


Code review: PR #2048 (wire claude-ops telemetry sink) — re-run at d2348b5

  • Gather context (diff since last code-review pass at a43de9a)
  • Review new commit d2348b5 (pin the source target and smoke-run the sink in the drift check)
  • Re-check prior findings for resolution
  • Post findings

Lane scope: correctness/architecture/error-handling/test-coverage/maintainability. Security stays with the dedicated security lane (already reviewed and cleared this PR through 469a06a; this commit touches no sink logic, only the test).

Scope of this pass: git diff a43de9a..d2348b5 — a single commit touching one file, .claude/hooks/hook-telemetry-sink.test.sh (+21 lines, nothing else changed).


This commit resolves my last open finding

My prior pass (at 469a06a) flagged that the drift test's normalize() exclusion regex is a prefix match (^source "\$\(dirname) — it strips any source "$(dirname ...)"/... line from the diff, so a typo'd or wrong hook-utils.sh path would still pass. d2348b5 closes that gap with two additions, both of which I traced by hand rather than executing (this sandbox declined to run the script — same restriction the prior code-review pass hit with shellcheck):

  1. Static pin (hook-telemetry-sink.test.sh#L44-L48) — grep -qF against the exact literal source "$(dirname "${BASH_SOURCE[0]}")/../../lib/hook-utils.sh". I confirmed via git show d2348b5:.claude/hooks/hook-telemetry-sink.sh that this string matches the committed sink's source line byte-for-byte, so the check currently passes and would fail on any deviation (wrong relative depth, renamed file, etc.) that the normalize-based diff can't see.
  2. Functional smoke test (hook-telemetry-sink.test.sh#L50-L59) — pipes a valid envelope through the real $local_copy under bash, with CLAUDE_PROJECT_DIR pointed at a fresh mktemp -d, and asserts a record lands at $smoke_dir/.claude/observability/hook-events.jsonl. I traced this against hook::repo_root (lib/hook-utils.sh#L315-L325): git -C "$smoke_dir" rev-parse --show-toplevel fails (fresh temp dir, no .git in any parent), so the function falls back to returning $smoke_dir itself — meaning log_dir really does resolve under $smoke_dir, and the assertion is checking the right path. This is exactly the pattern the already-shipped upstream test uses (plugins/claude-ops/hooks/hook-telemetry-sink.test.sh's run_sink(): env CLAUDE_PROJECT_DIR="$proj" bash "$SINK" against a mktemp -d project dir), so it's not a novel isolation strategy — it's proven precedent, not new risk.

Together these actually execute the sourced lib/hook-utils.sh end-to-end (not just check its path resolves syntactically), which is a stronger guarantee than what I asked for in the prior review — it also implicitly re-verifies hook::append_jsonl still works when reached via this repo-local sourcing path.

I didn't find a bug in the new code: the trap on line 52 (trap 'rm -f "$norm_upstream" "$norm_local"; rm -rf "$smoke_dir"' EXIT) replaces the earlier EXIT trap (bash traps don't stack), so cleanup of all three temp paths is still covered — not a leak.

Outstanding from earlier passes (unchanged, not new)

  • The test still isn't wired into scripts/run-plugin-tests.sh or CI. Per the PR thread this remains an intentionally queued follow-up once the plugin-test runner is extended to .claude/hooks tests, not a gap introduced by this PR.

Conclusion: d2348b5 fully closes the last open code-review finding on this PR with no new issues. I have no further findings to post inline.
· branch chore/wire-telemetry-sink

@kyle-sexton
kyle-sexton merged commit 0ea1b56 into main Aug 9, 2026
1 check passed
@kyle-sexton
kyle-sexton deleted the chore/wire-telemetry-sink branch August 9, 2026 07:32
kyle-sexton added a commit that referenced this pull request Aug 9, 2026
…racked copy (#2068)

No linked issue

## Summary

Executes #2021 remediation line 4 (de-dup the double-fired MCP linkage
gate) per the read-only investigation's verdict: the plugin copy yields
to a consumer repo's own tracked equivalent, and the repo-local hook
tests join CI so the two copies can never drift silently again.

## Fix

- `plugins/source-control/hooks/pr-linkage-mcp-gate.sh`: after the
gate-file and scope checks, the hook defers (`emit_tel "deferred"`, exit
0) when `<repo>/.claude/settings.json` wires any PreToolUse command
naming `pr-linkage-mcp-gate`. The plugin side is the sound place to
yield — the settings file states the wiring authoritatively; the
repo-local script has no reliable "plugin active" signal (plugin source
present ≠ plugin enabled). Named, accepted cost documented in the script
and changelog: a same-named no-op script suppresses the gate; it is a
policy gate, and the required `pr-issue-linkage` CI check remains the
authority.
- `scripts/run-plugin-tests.sh` now also runs `.claude/hooks/*.test.sh`
— `.claude/hooks/pr-linkage-mcp-gate.test.sh` never ran in CI, which is
how the two copies drifted apart silently. (This also activates the
telemetry-sink drift test added on #2048.)
- Tests: two new defer cases in the plugin suite (consumer's tracked
gate defers; unrelated settings wiring does not) — plugin suite 22/0,
repo-local suite 17/0.
- source-control 0.49.1 → 0.49.2 with changelog.

## Verification

Both suites green locally (22/0, 17/0); shellcheck clean at info
severity; catalog/cheat-sheet regeneration: no diff. The cheaper
alternative (deleting the repo-local settings entry) was rejected
because docs/CLOUD-SESSIONS.md and docs/MIGRATION-PLAYBOOK.md currently
contradict each other on whether cloud sessions load the plugin at all —
tracked as #2053; this defer-guard is sound in both worlds.

## Related

Refs #2021 (line 4), #2053 (the doc contradiction gating the cheaper
fix), #2048 (the drift-test this runner extension activates).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Fable 5 <[email protected]>
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