fix(hooks): refresh nerf statusline on PreCompact + SessionStart:compact#557
Merged
Merged
Conversation
Wires mcp-server-nerf v1.2.3's clear-indicator and refresh-indicator subcommands into Claude Code's hook system. The nerf statusline widget previously went stale across compaction boundaries — it would display the pre-compact context size (e.g. 126%) until the next nerf_* MCP tool call repainted it. Now PreCompact clears the entry and SessionStart (matcher: compact) repaints it with the post-compact context size. The existing SessionStart matcher "*" entry (crystallizer session-start) is preserved alongside the new "compact" matcher. Closes #555 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
Layer 2 of the stale-statusline fix. Wires mcp-server-nerf v1.2.3's new
clear-indicatorandrefresh-indicatorsubcommands into Claude Code's hook system so the nerf widget clears before compaction and repaints after the compact resume — fixing the ~126% pre-compact percentage that lingered until a manual/nerf status.Changes
scripts/hooks/nerf/pre-compact.sh(new) — CCPreCompacthook. Reads stdin JSON, shells out to~/.local/bin/nerf-server clear-indicator(with--session-idwhen present). Best-effort: always exits 0; logs to stderr on subprocess failure perlesson_best_effort_must_log.md.scripts/hooks/nerf/session-start-compact.sh(new) — CCSessionStarthook scoped tomatcher: "compact". Same shape, callsrefresh-indicator --session-id <id>.config/settings.template.json— adds the newPreCompactblock (matcher: "*") and a secondSessionStartarray entry (matcher: "compact") alongside the preserved crystallizer entry.Both scripts pass
shellcheckand run cleanly when~/.local/bin/nerf-serveris missing/older (graceful no-op via[[ -x "$NERF_BIN" ]]guard plus best-effort exit 0).Linked Issues
Closes #555
Dependencies
~/.local/bin/nerf-server. Older binaries don't recognize the subcommands; the hooks log and exit 0 in that case (no breakage).Upgrade gap (acknowledged, follow-up #556)
merge_settings()ininstallonly adds new event keys from the template — it does not union-merge new matcher entries into an existing event array. So a user who already hasSessionStartin their~/.claude/settings.jsonwill getPreCompact(genuinely new) but will NOT get the secondSessionStart: matcher "compact"entry. Workaround: fresh install (mv ~/.claude/settings.json{,.bak} && ./install) or manually copy the new SessionStart entry fromconfig/settings.template.json.The complete fix to the merge logic is tracked in #556 so this PR doesn't expand scope.
Test Plan
./scripts/ci/validate.sh→ 122 passed, 0 failed (shellcheck+shfmt+ regression suite)./install --check→ confirms new hook scripts deploy to~/.local/bin/hooks/nerf/andPreCompactis recognized as a missing event keyecho '{"session_id":"<uuid>",...}' | scripts/hooks/nerf/pre-compact.sh→ exit 0, no stderr noise; same forsession-start-compact.shagainst a freshly-installed v1.2.3 binarytrivy fs --scanners vuln --severity HIGH,CRITICAL .→ 0 findingssession-start-compact.sh); 1 Important deferred to fix(install): union-merge hook matcher arrays in merge_settings() #556 (install merge gap, predates this PR)