Skip to content

fix(hooks): refresh nerf statusline on PreCompact + SessionStart:compact#557

Merged
bakeb7j0 merged 1 commit into
mainfrom
fix/555-stale-statusline-after-compact
Apr 29, 2026
Merged

fix(hooks): refresh nerf statusline on PreCompact + SessionStart:compact#557
bakeb7j0 merged 1 commit into
mainfrom
fix/555-stale-statusline-after-compact

Conversation

@bakeb7j0
Copy link
Copy Markdown
Contributor

Summary

Layer 2 of the stale-statusline fix. Wires mcp-server-nerf v1.2.3's new clear-indicator and refresh-indicator subcommands 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) — CC PreCompact hook. Reads stdin JSON, shells out to ~/.local/bin/nerf-server clear-indicator (with --session-id when present). Best-effort: always exits 0; logs to stderr on subprocess failure per lesson_best_effort_must_log.md.
  • scripts/hooks/nerf/session-start-compact.sh (new) — CC SessionStart hook scoped to matcher: "compact". Same shape, calls refresh-indicator --session-id <id>.
  • config/settings.template.json — adds the new PreCompact block (matcher: "*") and a second SessionStart array entry (matcher: "compact") alongside the preserved crystallizer entry.

Both scripts pass shellcheck and run cleanly when ~/.local/bin/nerf-server is missing/older (graceful no-op via [[ -x "$NERF_BIN" ]] guard plus best-effort exit 0).

Linked Issues

Closes #555

Dependencies

  • mcp-server-nerf v1.2.3 (release, PR #27, issue #26) — installs to ~/.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() in install only 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 has SessionStart in their ~/.claude/settings.json will get PreCompact (genuinely new) but will NOT get the second SessionStart: matcher "compact" entry. Workaround: fresh install (mv ~/.claude/settings.json{,.bak} && ./install) or manually copy the new SessionStart entry from config/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/ and PreCompact is recognized as a missing event key
  • Manual smoke: echo '{"session_id":"<uuid>",...}' | scripts/hooks/nerf/pre-compact.sh → exit 0, no stderr noise; same for session-start-compact.sh against a freshly-installed v1.2.3 binary
  • trivy fs --scanners vuln --severity HIGH,CRITICAL . → 0 findings
  • Code review: 1 Important fixed (misleading "falling back to resolver" log string in session-start-compact.sh); 1 Important deferred to fix(install): union-merge hook matcher arrays in merge_settings() #556 (install merge gap, predates this PR)
  • End-to-end: trigger a compact in a live Claude Code session post-merge, confirm indicator clears during PreCompact and repaints with post-compact size after SessionStart:compact (requires this PR merged + a fresh-install or manual settings.json edit per upgrade-gap caveat above)

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>
@bakeb7j0 bakeb7j0 added this pull request to the merge queue Apr 29, 2026
Merged via the queue into main with commit 775eb3d Apr 29, 2026
1 check passed
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.

fix(hooks): refresh nerf statusline on PreCompact + SessionStart:compact

1 participant