Skip to content

Windows: report clawde auth success correctly; skip re-auth when already logged in - #17

Merged
ClintonSarkar merged 1 commit into
mainfrom
fix/auth-utf8-report
Jul 20, 2026
Merged

Windows: report clawde auth success correctly; skip re-auth when already logged in#17
ClintonSarkar merged 1 commit into
mainfrom
fix/auth-utf8-report

Conversation

@ClintonSarkar

Copy link
Copy Markdown
Owner

Summary

Fixes #16: on Windows, clawde auth reported "Authentication failed" even when the Claude login succeeded. The auth completes and the token is saved, but the proxy crashes printing its success message under Windows' legacy console encoding, and clawde judged the outcome purely by the crashed process's exit code. A first-run config step also crashed on a redirect conflict.

What changed (all in cli/clawde.ps1)

  • Force UTF-8 on the proxy child (PYTHONIOENCODING/PYTHONUTF8) so it can print its non-ASCII success message without crashing on a legacy code page. This is the load-bearing fix — it makes the exit code trustworthy again.
  • Skip login when already authenticated: clawde auth now checks status first and reports "[OK] Already authenticated" instead of pushing a needless re-login. clawde auth --force (or --relogin) still forces a fresh login for account-switching or replacing revoked credentials; the skip message names that escape and the help text reflects it.
  • Fix the first-run config crash: the config-init step no longer sends the child's stdout and stderr to the same file (which Windows rejects), guards against a null process, and reports a real launch error instead of a false "timed out".
  • Robust success detection: login counts as successful when the exit code is 0 or the output shows the explicit success signal, so a cosmetic non-zero exit can't mask a real login.

Verified live on Windows

The affected account was in fact already authenticated (valid credentials + refresh token in the keyring) and the proxy serves healthily — the failure was purely in reporting. The new already-authenticated pre-check was confirmed to fire correctly on the real machine.

Reviewer note

The .ps1 blob is LF vs. the base's stale CRLF, so the plain diff is inflated — review with git diff --ignore-cr-at-eol (real change ~68 lines).

Note

Defect 1 is an upstream proxy bug (it shouldn't crash printing its own success message); clawde neutralizes it by setting the child's encoding. Pre-existing on Windows, not a recent regression.

Closes #16


🤖 Generated with Claude Code

`clawde auth` reported "Authentication failed" on a SUCCESSFUL Windows login:
ccproxy authenticated, saved the token, then crashed printing its Unicode
success glyph under a legacy code page (cp1252), exiting non-zero - and Cmd-Auth
judged success purely by exit code. A first-run config-init step also crashed
because it redirected the child's stdout and stderr to the SAME file.

- Force PYTHONIOENCODING=utf-8 / PYTHONUTF8=1 on every ccproxy child (Cmd-Auth
  and Invoke-CCProxyWithTimeout) so the success message prints and the exit code
  becomes trustworthy again. This is the load-bearing fix.
- Skip login entirely when already authenticated: Cmd-Auth now runs
  `auth status claude` first and returns "[OK] Already authenticated" on valid
  credentials, instead of pushing the user through a needless OAuth round-trip.
- Invoke-CCProxyWithTimeout: separate stdout/stderr temp files (Start-Process
  rejects the same file for both), combine both on return, guard $p.Kill()
  against a null process, and on a launch failure return a real error + exit 1
  instead of a false "timed out".
- Test-AuthSucceeded: treat login as successful when exit code is 0 OR the
  login-emitted "Authentication successful" appears, so a cosmetic non-zero exit
  cannot mask a real login. (Only the login string is matched; the
  "valid credentials" phrasing belongs to `auth status`, used by the pre-check.)

Verified live on Windows: the affected account was already authenticated (valid
credentials + refresh token in the keyring) and the proxy serves healthily - the
new pre-check correctly detects this and reports "already authenticated".

Closes #16

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@ClintonSarkar
ClintonSarkar merged commit 410eb6f into main Jul 20, 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.

Windows: clawde auth reports failure on a successful login (UTF-8 crash + redirect conflict)

1 participant