Repository navigation
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
Conversation
…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]>
There was a problem hiding this comment.
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.
|
@codex review |
Reviewer's GuideMoves 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 publicationsequenceDiagram
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
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
🟡 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.shdoes not consume these two files separately: it opens$SNAP_DIR/$sid.jsonand reads the rate-limit and context fields from that single file (lines 42 and 72-75). This publisher writes rate limits toprofile.<key>.jsonand context tosession.<sid>.json, so the hook exits without warnings (and thesession.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.sha persistent side effect: that test sets a temporaryCLAUDE_CONFIG_DIRbut leavesHOMEuntouched, so each standalone run now leaves aprofile._tmp_...jsonartifact 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]>
|
Fix round 708345d addresses both issues from Copilot's review: synced |
There was a problem hiding this comment.
🔵 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-184copies the statusline but not thisclaude-usage-guard.sh, andscripts/setup-claude-profiles.sh:149-150installs only the statusline.configure_profile_runtimetherefore cannot findusage-guard.sh, leavesguard_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_ansibefore 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
Problem
claude-usage-guard.sh(aUserPromptSubmithook) and theclaude-usagecommand both read account-scoped usage snapshots from
$HOME/.claude/usage-snapshots/profile.<key>.jsonplus a session-keyedcontext 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.shon 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-150installs the repo copy over theshared file on every setup run, and
base-image/Dockerfile:184COPYs thesame 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-usagereported STALE (exit 4) on all 29 profiles.
Fix
base-image/files/claude-statusline-command.shbyte-identical to theshared file as hand-restored on Eagle from
statusline-command.sh.bak-20260910T1836Z—cmp-verified, mode0755preserved, no other change to the file.
devcontainer.test/test-claude-statusline-snapshots.sh(registered indevcontainer.test/test.shnext to the existing statusline test): feedsthe renderer a payload with
rate_limits/context_windowand asserts theprofile- and session-keyed snapshot files are written correctly, that a
payload with no
rate_limitsstill exits 0 and fails quiet (nulls, not anerror), and that the visible status line is byte-identical whether or not
$HOME/.claudeis writable.docs/claude-multi-account-profiles.md, noting why the fix has to live inthis 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 unchangedenv -u TMUX -u WORKBENCHES_CLAUDE_TMUX_CHILD bash devcontainer.test/test-claude-statusline-snapshots.sh(new test) — passes against the fixed filecmp base-image/files/claude-statusline-command.sh ~/.claude-profiles/shared/statusline-command.sh— identicaldocker 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:
Enhancements:
Documentation:
Tests: