Repository navigation
Conversation
Two bugs made every Claude usage scrape time out, leaving snapshots local-only so budget calibration never ran: - Session size was applied with resize-pane after a detached new-session. A lone pane cannot grow past its window (80x24), so /usage rendered cut off and "Current week" never appeared. Pass -x/-y to new-session instead. - The trust prompt now reads "Quick safety check ... one you trust" with the cursor on "No, exit", so the "Do you trust" match missed it and Enter would exit. Detect both wordings, move the cursor to "Yes", and re-read the pane before confirming, since keys sent right after the prompt renders can be dropped. Never confirm while "No" is selected. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This branch has not been deployed
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
nightshift reads Claude's usage percentage by starting
claudein a hidden tmux session, typing/usage, and reading the screen. With current Claude Code, every one of these reads timed out. As a result, budget snapshots only ever used local token counts, and calibration never got any data. This PR fixes the two causes: the tmux window was too small to show the usage figure, and a changed trust prompt defaulted to "No, exit".The two bugs
1. The tmux pane stayed at 80×24 (
internal/tmux/tmux.go)Startrantmux new-session -dand thenresize-pane -x 120 -y 40. A pane can't grow bigger than its window, and a detached session's window defaults to 80×24, so the resize did nothing. At 80×24,/usageis cut off before the "Current week (all models)" line that the scraper waits for, soWaitForPatterntimed out.The fix passes the size to
new-sessionwith-x/-y, so the window is created at 120×40.2. The folder-trust prompt changed (
internal/tmux/scraper.go)When
claudestarts in a folder it hasn't seen before, it asks whether to trust that folder. Claude Code v2.1.273 changed this prompt to "Quick safety check … one you trust?", with the cursor starting on "No, exit". nightshift only recognised the old wording ("Do you trust") and pressed Enter, which picked whatever option was selected.The fix:
claudeTrustPromptKeysrecognises both wordings and works out where the cursor is relative to the "Yes" option.acceptClaudeTrustPromptmoves the cursor to "Yes". It then reads the screen again and presses Enter only once "Yes" is actually selected. It never presses Enter while "No" is selected.Why it checks the screen before pressing Enter. My first version sent Down then Enter straight away. It passed the unit tests but failed in real use. Keys sent right after the prompt appears are sometimes dropped. When Down was dropped and Enter wasn't, Claude exited. A fixed delay could still lose that race, so the code checks that "Yes" is selected first.
Something to consider
nightshift already accepted the trust prompt automatically, and this PR keeps that behaviour. It means every folder nightshift scrapes from ends up marked as trusted in
~/.claude.json. Running the scrape from one dedicated folder would avoid that. I left it for a separate change.Testing
internal/tmux/tmux_test.gocover:new-sessionarguments. This test fails on the old code.go test ./...,go vetandgofmtare clean.nightshift budget snapshot -p claudesucceeded in an already-trusted project and in three new untrusted folders. The unpatched binary timed out in every case.🤖 Generated with Claude Code