xbpb6 on X (0.1.4281, Windows 11, TUI mode): the account Claude Code is
signed in to said "Sign-in required" with "can't read the allowance";
signing in again fixed it for a while, then it came back.
Claude Code on Windows writes .credentials.json and .claude.json through
a temp file and a rename. Go's os.ReadFile opens without
FILE_SHARE_DELETE, so while magpie reads the file the rename gets EPERM.
Claude Code then truncates the file and writes it in place (xO in its
writer). A read in between finds the file empty or cut short.
- rememberLogins took that read as a sign-out. claudeLoggedOut marked
the Held account lapsed with claudeLogoutLapse, which breaks the rule
that a failed read means unknown.
- The account then read as not in use. Then claudeSavedDir, which has no
Held check, could copy Claude Code's own sign-in into
claude-accounts/<id> for a warm-up, a usage read or a request. Two
Claude Codes then held one rotating refresh token, so whichever
refreshed second signed the other out for good. That is why the
account comes back as signed out again and again.
Now:
- claudeSignInUnsure reads the files again. The account counts as
signed out only if the file is gone, Claude Code emptied it,
`claude auth status` says logged out, or no account is named. A
file that can't be read or isn't whole JSON is unknown for up to
claudeUnsureGrace (2 minutes).
- Meanwhile, rememberLogins doesn't lapse the Held account, and
Logins and renewLogins keep it active.
- claudeSavedDir refuses a Held account with errClaudeHeld, whose text
is not one ClaudeSignInRequired matches.
- The Mac keychain path is unchanged.
Run:
- TestClaudeHalfWrittenSignInIsNoLogout was red on the old code on mote,
in two ways (logs kept). An empty credentials file gave Active:false
with claudeLogoutLapse, the screenshot's state. claudeSavedDir put the
Held account in .config/magpie/claude-accounts/7f327d2462d8fb58 with
no error. Green after.
- mote: go test ./internal/provider ./internal/gateway -count=1
-timeout 45m: ok, 142s and 913s.
- win-run (xiaomi-gpu, Windows 11): TestClaudeHalfWrittenSignInIsNoLogout,
TestClaudeAccountsOutliveLogout and TestClaudeSwitchIsNoLogout pass.
- gofmt -l is clean. GOOS=windows and GOOS=linux go vet
./internal/provider pass.
Not tried:
- No real Claude account on Windows. The EPERM rewrite was read from
Claude Code 2.1.316's source, not watched.
- No full ./... suite.
- A Claude Code killed mid-refresh on Windows is not covered.