Skip to content

base-image/files/claude-statusline-command.sh: land the usage-snapshot publisher block that claude-usage-guard.sh and claude-usage read — the repo copy never carried it, so setup-claude-profiles.sh kept overwriting the local patch that did (#47) - #48

Merged
brettheap merged 2 commits into
mainfrom
fix/statusline-usage-snapshots
Sep 11, 2026

Conversation

@brettheap

@brettheap brettheap commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Problem

claude-usage-guard.sh (a UserPromptSubmit hook) and the claude-usage
command both read account-scoped usage snapshots from
$HOME/.claude/usage-snapshots/profile.<key>.json plus a session-keyed
context file. Those files were published by a ~43-line block that existed
only as a hand-applied patch to the deployed
~/.claude-profiles/shared/statusline-command.sh on Eagle (added
~2026-08-22) — the repository's copy,
base-image/files/claude-statusline-command.sh, never carried it.
scripts/setup-claude-profiles.sh:149-150 installs the repo copy over the
shared file on every setup run, and base-image/Dockerfile:184 COPYs the
same repo file into the image. At 2026-09-11T09:48:22Z a profile-setup run
did exactly that: the shared file became byte-identical to the unpatched
repo copy, every profile's snapshot froze at that minute, and claude-usage
reported STALE (exit 4) on all 29 profiles.

Fix

  • Make base-image/files/claude-statusline-command.sh byte-identical to the
    shared file as hand-restored on Eagle from
    statusline-command.sh.bak-20260910T1836Z — cmp-verified, mode 0755
    preserved, no other change to the file.
  • Add devcontainer.test/test-claude-statusline-snapshots.sh (registered in
    devcontainer.test/test.sh next to the existing statusline test): feeds
    the renderer a payload with rate_limits/context_window and asserts the
    profile- and session-keyed snapshot files are written correctly, that a
    payload with no rate_limits still exits 0 and fails quiet (nulls, not an
    error), and that the visible status line is byte-identical whether or not
    $HOME/.claude is writable.
  • Document the publisher, its snapshot path, and its two readers in
    docs/claude-multi-account-profiles.md, noting why the fix has to live in
    this file rather than the deployed copy.

Test plan

  • env -u TMUX -u WORKBENCHES_CLAUDE_TMUX_CHILD bash devcontainer.test/test-claude-tmux-statusline.sh (existing statusline test) — passes unchanged
  • env -u TMUX -u WORKBENCHES_CLAUDE_TMUX_CHILD bash devcontainer.test/test-claude-statusline-snapshots.sh (new test) — passes against the fixed file
  • Same new test run against the pre-fix file content — fails as expected (confirms the test actually exercises the defect)
  • cmp base-image/files/claude-statusline-command.sh ~/.claude-profiles/shared/statusline-command.sh — identical
  • Full devcontainer image build + docker compose exec test ./test.sh (not run; requires a Layer 0 image rebuild)

Closes #47

Lane: openreposhape-2 (openRepoShape-2)

🤖 Generated with Claude Code

Summary by Sourcery

Restore repository-managed usage snapshot publishing and add regression coverage to prevent profile setup from overwriting it.

Bug Fixes:

  • Restore statusline usage-snapshot publishing so Claude usage guards and usage reporting continue receiving fresh profile- and session-scoped data after profile setup runs.

Enhancements:

  • Separate account rate-limit snapshots from session context snapshots and keep snapshot failures from affecting the visible status line.

Documentation:

  • Document the usage-snapshot publisher, its consumers, storage paths, fail-quiet behavior, and why it must remain in the repository source file.

Tests:

  • Add regression coverage for snapshot contents, missing rate-limit data, unwritable snapshot storage, and existing statusline behavior.

…t publisher block that claude-usage-guard.sh and claude-usage read — the repo copy never carried it, so setup-claude-profiles.sh kept overwriting the local patch that did (#47)

The publisher lived only as a hand-applied patch to the shared, deployed
copy on Eagle (~/.claude-profiles/shared/statusline-command.sh, added
~2026-08-22). scripts/setup-claude-profiles.sh re-installs the status line
from this repo file on every run, so a patch to only the shared copy is
transient by construction. A routine setup run at 2026-09-11T09:48:22Z
proved it: the shared file became byte-identical to this file's unpatched
contents, claude-usage-guard.sh and the claude-usage command lost their only
input, and claude-usage reported STALE (exit 4) on all 29 profiles.

Make this file byte-identical to the shared copy as hand-restored on Eagle
from statusline-command.sh.bak-20260910T1836Z (cmp-verified, mode 0755
preserved). Add devcontainer.test/test-claude-statusline-snapshots.sh,
registered in devcontainer.test/test.sh next to the existing statusline
test: it exercises the publisher's profile-keyed and session-keyed snapshot
writes, confirms a payload with no rate_limits still exits 0 and fails
quiet (nulls, not an error), and confirms the visible status line is
byte-identical whether or not $HOME/.claude is writable. Document the
publisher, its snapshot path, and its two readers in
docs/claude-multi-account-profiles.md, and note why the fix has to live in
this file rather than the deployed copy.

Lane: openreposhape-2 (openRepoShape-2)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Copilot AI lite review requested due to automatic review settings September 11, 2026 11:10

@sourcery-ai sourcery-ai 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.

Sorry @brettheap, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 3 days and 6 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@brettheap

Copy link
Copy Markdown
Contributor Author

@codex review

@sourcery-ai

sourcery-ai Bot commented Sep 11, 2026

Copy link
Copy Markdown

Reviewer's Guide

Moves the Claude usage-snapshot publisher into the repository-owned statusline renderer so profile setup and image builds retain it, adds focused regression tests for data publication and rendering isolation, and documents the behavior and deployment requirement.

Sequence diagram for Claude usage snapshot publication

sequenceDiagram
    participant Claude as Claude statusline
    participant Renderer as statusline-command.sh
    participant ProfileSnapshot as profile snapshot
    participant SessionSnapshot as session snapshot
    participant Guard as claude-usage-guard.sh
    participant Usage as claude-usage

    Claude->>Renderer: Render payload with rate_limits and context_window
    Renderer->>ProfileSnapshot: Write account rate limits and reset times
    Renderer->>SessionSnapshot: Write session context percentage
    Guard->>ProfileSnapshot: Read profile.<key>.json
    Guard->>SessionSnapshot: Read session.<sid>.json
    Usage->>ProfileSnapshot: Read profile.<key>.json
    Usage->>SessionSnapshot: Read session.<sid>.json
Loading

File-Level Changes

Change Details Files
Restore and persist usage-snapshot publication in the repository’s statusline renderer.
  • Extract the session ID from the statusline payload.
  • Write account-scoped rate-limit data to a sanitized profile-keyed JSON file.
  • Write session-scoped context usage to a session-keyed JSON file.
  • Use temporary files and atomic moves, while swallowing directory and write failures so rendering remains unaffected.
base-image/files/claude-statusline-command.sh
Add regression coverage for snapshot contents and fail-quiet behavior.
  • Verify profile and session snapshots for complete payloads.
  • Verify missing rate limits produce null fields without a nonzero exit.
  • Verify an unwritable snapshot path leaves visible output unchanged.
  • Register the test in the devcontainer test suite.
devcontainer.test/test-claude-statusline-snapshots.sh
devcontainer.test/test.sh
Document snapshot publication, consumers, storage semantics, and deployment rationale.
  • Describe the two snapshot readers and profile/session file split.
  • Document key sanitization and fail-quiet behavior.
  • Explain why the publisher must be maintained in the repository source to survive profile setup reinstalls.
docs/claude-multi-account-profiles.md

Assessment against linked issues

Issue Objective Addressed Explanation
#47 Add the usage-snapshot publisher to the repository's Claude status-line renderer so profile-scoped rate-limit snapshots and session-scoped context snapshots are written and survive profile setup and image builds. ✅
#47 Ensure snapshot publishing is fail-quiet: payloads without rate-limit data still produce valid null snapshots and exit successfully, and snapshot write failures do not alter the visible status line. ✅
#47 Add regression coverage and documentation describing the snapshot publisher, its readers, file paths, behavior, and why it must reside in the repository copy of the renderer. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@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.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

Copilot AI 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.

🟡 Changes recommended

Snapshot writer/reader contracts are inconsistent, and an existing test leaves persistent artifacts.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Restores repository-owned Claude usage-snapshot publishing, with regression tests and documentation.

Changes:

  • Adds profile and session snapshot publishing.
  • Registers snapshot regression coverage.
  • Documents snapshot behavior and consumers.
File summaries
File Summary
docs/claude-multi-account-profiles.md Documents snapshot publishing and consumption.
devcontainer.test/test.sh Registers the new regression test.
devcontainer.test/test-claude-statusline-snapshots.sh Tests snapshot generation and fail-quiet behavior.
base-image/files/claude-statusline-command.sh Restores usage-snapshot publishing.
Review details

Suppressed comments (2)

base-image/files/claude-statusline-command.sh:442

  • The checked-in claude-usage-guard.sh does not consume these two files separately: it opens $SNAP_DIR/$sid.json and reads the rate-limit and context fields from that single file (lines 42 and 72-75). This publisher writes rate limits to profile.<key>.json and context to session.<sid>.json, so the hook exits without warnings (and the session. prefix cannot match its lookup). Please align the writer and reader by either emitting the combined per-session file the hook expects or updating the hook to merge both snapshots.
            mv -f "$session_tmp" "$snap_dir/session.$sid.json" 2>/dev/null

base-image/files/claude-statusline-command.sh:420

  • This new write path gives the existing test-claude-tmux-statusline.sh a persistent side effect: that test sets a temporary CLAUDE_CONFIG_DIR but leaves HOME untouched, so each standalone run now leaves a profile._tmp_...json artifact under the caller's ~/.claude/usage-snapshots. Run the statusline fixtures with a temporary HOME (and clean it) so the documented regression command remains hermetic.
snap_dir="$HOME/.claude/usage-snapshots"
profile_key=$(printf '%s' "${CLAUDE_CONFIG_DIR:-default}" | sed 's/[^A-Za-z0-9._-]/_/g')
mkdir -p "$snap_dir" 2>/dev/null && {
  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

…e layout, stop the tmux statusline test from leaking artifacts into the caller's real HOME

Copilot review on #48 caught two real gaps in the first commit:

- base-image/files/claude-usage-guard.sh still read the old merged
  $SNAP_DIR/$sid.json (five_hour/fable_weekly/context_pct in one file) that
  predates both the ancestor-walk gate and the profile/session snapshot
  split. It was never updated when the publisher it depends on evolved on
  Eagle, so a build that ever wires this checked-in copy into an image
  would ship a guard hook that never fires. Sync it to
  ~/.claude-profiles/shared/usage-guard.sh — the hand-patched copy that
  already reads profile.<key>.json and session.<sid>.json separately and is
  the one actually running today — the same fix as the parent commit,
  applied to this file. Verified end-to-end: publish a snapshot with the
  fixed statusline script, feed the same session/cwd to the synced guard
  script, confirm it emits the expected threshold warning.

- devcontainer.test/test-claude-tmux-statusline.sh sets CLAUDE_CONFIG_DIR to
  a temp directory for its statusline invocations but never touched HOME,
  so now that the renderer publishes snapshots under
  $HOME/.claude/usage-snapshots, running that test for real left
  profile._tmp_*.json artifacts under the caller's actual home directory
  (confirmed: this happened on this machine during local verification of
  the parent commit, and the stray files have been removed by hand). Pin
  HOME to a throwaway directory under the test's own TEST_ROOT, alongside
  the existing CLAUDE_CONFIG_DIR isolation, so the test is fully hermetic
  again.

Both devcontainer.test/test-claude-tmux-statusline.sh and
devcontainer.test/test-claude-statusline-snapshots.sh still pass, and a
before/after listing of the real ~/.claude/usage-snapshots confirms the
tmux statusline test no longer writes there.

Lane: openreposhape-2 (openRepoShape-2)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Copilot AI review requested due to automatic review settings September 11, 2026 11:23
@brettheap

Copy link
Copy Markdown
Contributor Author

Fix round 708345d addresses both issues from Copilot's review: synced claude-usage-guard.sh to the publisher's profile/session file split (replied on that thread), and pinned HOME in test-claude-tmux-statusline.sh so it no longer leaks profile._tmp_*.json artifacts into the real ~/.claude/usage-snapshots (that finding was in the review body's suppressed-comments list, not a separate thread).

@brettheap
brettheap merged commit c578cc6 into main Sep 11, 2026
6 checks passed
@brettheap
brettheap deleted the fix/statusline-usage-snapshots branch September 11, 2026 11:27

Copilot AI 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.

🔵 Needs a closer look

Clean setups do not install the usage guard, and the snapshot test does not compare raw status-line output.

Review details

Suppressed comments (2)

base-image/files/claude-usage-guard.sh:48

  • This reader is not deployed by a clean image or profile setup: base-image/Dockerfile:178-184 copies the statusline but not this claude-usage-guard.sh, and scripts/setup-claude-profiles.sh:149-150 installs only the statusline. configure_profile_runtime therefore cannot find usage-guard.sh, leaves guard_ok=false, and these new profile/session snapshot paths are never consumed in a fresh bench. Add the guard install/rename step (and a clean-setup regression) before relying on this change.
# Rate limits are account-scoped (profile-keyed, shared by every sibling
# session on that CLAUDE_CONFIG_DIR); context is session-scoped (each
# conversation's own window). Read independently so a stale/missing file on
# one side never hides fresh data on the other.
profile_key=$(printf '%s' "${CLAUDE_CONFIG_DIR:-default}" | sed 's/[^A-Za-z0-9._-]/_/g')
PROFILE_SNAP="$SNAP_DIR/profile.$profile_key.json"
SESSION_SNAP="$SNAP_DIR/session.$sid.json"

devcontainer.test/test-claude-statusline-snapshots.sh:143

  • The test plan says the visible status line must be byte-identical for writable and failed snapshot writes, but both outputs are passed through strip_ansi before comparison. A regression that changes or drops ANSI sequences would therefore pass even though the emitted status line differs. Compare the raw outputs here (and strip only for diagnostics if needed).
out_writable=$(run_statusline "$FAKE_HOME_WRITABLE" "$payload_full" | strip_ansi)
out_unwritable=$(run_statusline "$FAKE_HOME_UNWRITABLE" "$payload_full" | strip_ansi)

[[ "$out_writable" == "$out_unwritable" ]] \
  • Files reviewed: 6/6 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants