Files
PaperClipAI/packages/adapters
Devin Foley 2181df544c fix(claude-local): skip the setup-token login-method line (#22652)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - People connect a Claude subscription from "Connect a model".
Paperclip runs `claude setup-token` in a terminal and reads the sign-in
link from the output
> - `parseSetupTokenPrompt` binds the link only when the browser-code
prompt follows the URL block. It skips repeated URL rows and the copy
hint, and it fails closed on any other line
> - Claude Code 2.1.306 prints a new line, `Login method pre-selected:
Subscription Plan (Claude Pro/Max)`, between the copy hint and the
prompt
> - The parser returns null for that layout, and the runner waits for
the 5-minute timeout. The dialog stays on "Preparing browser sign-in…",
and the log says only "timed out"
> - This pull request skips the login-method line with a bounded pattern
and logs one fixed line when the prompt is on screen but the parser does
not bind it
> - The benefit is that Claude subscription sign-in works on Claude Code
2.1.306, and the next layout change shows up in the log at once

## Linked Issues or Issue Description

Fixes #19949

Refs #19958 (the same fix by @adity982, written before #19211 changed
the copy-hint check; this pull request ports it onto `master` and widens
the pattern to other method names). Refs #19211, #15550 (earlier
copy-hint fixes). Refs #20050 (PTY window size, a separate fix). Refs
#22520 (the 2.1.330 short link, a separate fix in the URL validator).

The plain-text URL reassembly defect from the same issue is in a
separate pull request, as the triage comment asks.

## What Changed

- `setup-token-parse.ts`: add `LOGIN_METHOD_LINE_RE`.
`findBrowserCodePrompt` skips a line that matches it. The method name is
1 to 80 characters of prose with no `:`, so a URL or a `code:value`
cannot hide in it. Any other unknown line still returns null.
- `setup-token-parse.ts`: add `hasSetupTokenPromptLine`. It returns true
when the output holds the prompt line. It binds no value.
- `setup-token-runner.ts`: when the prompt line is on screen and
`parseSetupTokenPrompt` still returns null, log one fixed line:
`Setup-token login: the browser-code prompt is on screen, but the parser
did not recognize the sign-in screen.` The line holds no input bytes,
and the runner logs it at most one time per run.
- Tests: the 2.1.306 layout (OSC 8 link per row, CHA-spaced words, copy
hint, login-method line, prompt), the login-method line without a copy
hint, four malformed login-method lines that must fail closed, and two
runner tests for the new log line.

## Verification

- `pnpm exec vitest run packages/adapters/claude-local/src/server/`: 396
passed, 2 skipped.
- The two positive parser tests fail on `master` and pass with this
change.
- `pnpm --filter @paperclipai/adapter-claude-local typecheck` passes.
- I ran the parser on a synthetic 2.1.306 screen built from the output
in #19949. `master` returns null. This branch returns the full URL.
- Not run: a live `claude setup-token` sign-in on 2.1.306.

## Risks

- Low risk. The change adds one allowlisted line shape. The parser keeps
its fail-closed contract for every other line.
- A future CLI can print another new line. The parser then still returns
null, but the new log line names the cause.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with shell, file
edit, and code execution tools.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge
2026-11-23 11:52:16 -08:00
..