Skip to content

install-tend: fix oauth-token.sh returning an invalid token on macOS - #398

Merged
max-sixty merged 1 commit into
mainfrom
oauth-token-extract
May 8, 2026
Merged

max-sixty merged 1 commit into
mainfrom
oauth-token-extract

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

The wrapper's grep extraction ran past the token's last char into the next TUI line (Store this token securely…), returning a malformed bearer that api.anthropic.com rejected with 401 Invalid bearer token. The token and the following line are joined in the captured TUI by ANSI styling alone — no whitespace — so after CSI strip + tr -d '\r\n', the [A-Za-z0-9_-]* class greedily consumed Store too. Wrapper exited 0 and the bot got a token that looked plausible, silently bricking tend install runs that used the CLI path.

Changes

  • Widen the PTY to 250 cols via stty inside a shell wrapper, so Ink renders the ~108-char token on a single line. End-of-line then becomes a natural right boundary.
  • Drop tr -d '\n'; rely on grep -oE not crossing newlines, which makes the "runs into Store" failure mode structurally impossible regardless of label wording.
  • Redirect script(1)'s stdout passthrough to stderr — pre-existing leak that polluted TOKEN=$(./oauth-token.sh) callers; was masked by the broken extraction. The user still sees the TUI on their terminal via stderr.
  • Length sanity check (80 ≤ len ≤ 200) as a safety net.
  • Correct the in-script comment about why script(1) is needed. The OAuth callback server binds fine without a TTY (verified by running claude setup-token with no TTY — bound localhost:50706 and connected to claude.com); what needs a TTY is stdout, because Ink only renders when process.stdout.isTTY.
  • SKILL.md: route Windows sessions directly to the Manual fallback (the wrapper depends on bash + script(1), validated only on macOS/Linux).

Verification

End-to-end with a real claude setup-token burn: extracted token returns "role":"assistant" from api.anthropic.com/v1/messages with Authorization: Bearer <token> and anthropic-beta: oauth-2025-04-20. Confirms the original 401 failure mode is gone.

This was written by Claude Code on behalf of Max.

The wrapper's grep extraction ran past the token's last char into the
next TUI line ("Store this token securely…"), returning a malformed
bearer that the API rejected with 401. Captured TUI: token and the
following line are joined by ANSI styling alone — no whitespace
separator — so after CSI strip + `tr -d '\r\n'`, the character class
greedily consumed "Store" too.

Fix:

- Widen PTY to 250 cols via `stty` in a shell wrapper so Ink doesn't
  wrap the ~108-char token; the trailing newline becomes a natural
  right boundary.
- Drop `tr -d '\n'`; rely on grep not crossing newlines.
- Redirect script(1)'s stdout passthrough to stderr so it doesn't
  pollute the caller's `TOKEN=$(./oauth-token.sh)` capture (pre-existing
  leak, masked by the broken extraction).
- Length sanity check (80 ≤ len ≤ 200) as a safety net.
- Correct the comment about why script(1) is needed: it's for stdout
  rendering (Ink checks isTTY), not the OAuth callback server (which
  binds fine without a TTY).

Verified end-to-end: extracted long-lived token returns "role":"assistant"
from api.anthropic.com/v1/messages.

Also update SKILL.md so install-tend sessions on Windows route directly
to Manual instead of attempting the bash + script(1) wrapper.

Co-Authored-By: Claude <[email protected]>
@max-sixty
max-sixty merged commit ae52c64 into main May 8, 2026
5 checks passed
@max-sixty
max-sixty deleted the oauth-token-extract branch May 8, 2026 18:45
@max-sixty max-sixty mentioned this pull request May 13, 2026
max-sixty added a commit that referenced this pull request May 13, 2026
Bumps generator to 0.0.18.

## Headline

Expose the `__TEND_DELETE__` sentinel so TOML overrides can reach RFC
7396 delete-key semantics — useful for dropping a generator-injected key
(e.g. `on.schedule` from a scheduled workflow) while keeping the rest.
Closes #439, thanks @jrdncstr for reporting.

## Other changes since 0.0.17

- fix(action): sum usage and num_turns across all result entries (#437)
- diag(action): upload execution-output.json (#408)
- fix(mention): run setup before PR checkout so stale PRs don't drop
mentions (#391)
- fix(running-in-ci): base skill worktree on default branch (#401)
- install-tend: fix oauth-token.sh returning an invalid token on macOS
(#398)
- oauth-token.sh: don't tee the OAuth token to stderr (#421)
- Skill hardening: bang-escape guidance, review-reviewers corruption
scans, dedup rules, $GITHUB_RUN_ID requirement

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <[email protected]>
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.

2 participants