feat(cockpit): PostToolUse tool-mirror hook — zero-token live worker activity (3c spike, closes #71) - #75
Merged
Conversation
…fault) Adds log-worker-tool.sh, a harness-side PostToolUse hook that mirrors Bash/Edit/Write tool calls into .claude/state/worker-tools.jsonl (0 agent tokens — runs outside the sandbox, off stdin). Mirrors log-event.sh's node-based JSON building, resolve-roots.sh sourcing, CLAUDE_*_FILE override, and atomic rotation exactly. Strict no-op on any failure (malformed stdin, missing node, unwritable dir): always exits 0. Not wired into .claude/settings.json's PostToolUse array — spike discipline per issue #71. The script's header comment carries a copy-paste-ready enable snippet. Adds log-worker-tool.test.sh (17 checks) covering per-tool mirroring, non-target-tool/malformed-input no-ops, multi-line command collapsing, JSON escaping, and rotation; picked up automatically by .claude/self/checks.sh's *.test.sh glob. Refs #71 Co-Authored-By: Claude Haiku 4.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SxWgee2T3w45nnPw5yZ4iu
robercano
approved these changes
Jul 7, 2026
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.
Summary
Spike (Cockpit 3c, part 3 of 3 — design in #68, unblocked by #70) adding a harness-side PostToolUse tool-mirror hook that records worker
Bash/Edit/Writetool calls to.claude/state/worker-tools.jsonlat zero agent tokens. Ships disabled by default — enabling is a one-line wiring change pending the go/no-go decision below.Closes #71.
What's here
.claude/scripts/log-worker-tool.sh— PostToolUse hook. Mirrors only Bash/Edit/Write into JSONL{ts, tool, summary(one-line), path}(path =cwdfor Bash → worktree-path attribution;file_pathfor Edit/Write). JSON built vianode(safe escaping, single-line collapse, 200-char Bash cap). Strict no-op on any failure (alwaysexit 0). Rotation capped to${WORKER_TOOLS_MAX_LINES:-2000}via atomic temp+rename, mirroringlog-event.sh.CLAUDE_WORKER_TOOLS_FILEoverride for tests. Not wired into.claude/settings.json— a commented, copy-paste wiring snippet lives in the script header..claude/scripts/log-worker-tool.test.sh— 17 checks (discovered by thetestgate): per-tool capture, non-target drop, empty/malformed stdin no-op, multi-line collapse, JSON escaping, rotation cap, unwritable-dir exit-0.Gates (self-adapter
.claude/self/gates.json)build / lint / test — all pass (test includes
checks.sh+smoke-fanout.sh).Review
Consensus (all) met: correctness (opus) APPROVE, tests (sonnet) APPROVE. Non-blocking nits noted for follow-up: Edit/Write
summaryfield not asserted (trivial derivative of well-testedpath); no explicit 200-char truncation test.Go/no-go evaluation
nodeabsent from PATH — no error output, no corruption (0-byte file worst case).cwd/pathfrom real PostToolUse payloads resolve to the worktree paths cockpit expects (this spike exercised synthetic hook-event JSON only). Cockpit read/attribution path deferred to the go decision, per plan.🤖 Generated with Claude Code
https://claude.ai/code/session_01SxWgee2T3w45nnPw5yZ4iu