mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-24 14:20:12 +01:00
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - The "Connect a model" step signs in to a Claude subscription. The
server runs `claude setup-token` in a PTY. The parser reads the output
for the authorization URL.
> - Claude Code prints a copy hint between the URL and the code prompt.
The key in the hint depends on the host terminal. The server passes its
environment to the child, so the terminal that started Paperclip decides
the hint.
> - The parser accepts only `Hold Shift while selecting…` on one line.
Claude Code also prints `Fn`, `Option`, and `Shift (Option in iTerm2, Fn
in Terminal.app)`. The long hint wraps across two rows.
> - For these hints the parser returns `null`. The UI stays on
"Preparing browser sign-in…" with no error until the 5-minute timeout.
> - This pull request accepts the four key phrases and joins a hint that
wraps.
> - The benefit is that sign-in works on macOS, over SSH, and in tmux,
screen, or zellij. The parser still fails closed for all other text.
## Linked Issues or Issue Description
Refs #17868. The macOS comment on that issue shows this symptom:
`local/check` returns `sign_in_required` with no `authorizationUrl`.
This PR fixes the copy hint part of that issue. It does not fix the
token parse part (#17276).
Related PRs. I searched all open PRs that change `setup-token-parse.ts`:
- #15550 (merged) added the one-line `Shift` hint.
- #16988 and #18560 (open) accept a `Shift` hint only. A comment on
#16988 reports the long `Shift (Option in iTerm2, Fn in Terminal.app)`
hint under tmux on WSL2. Neither PR accepts that hint, and neither
accepts `Fn` or `Option`.
- #17276 (open) reads the token from the rendered screen. That is the
next step after this one. The two changes do not overlap, and both are
necessary. With this PR alone, the sign-in link shows, but the token
step can still fail (see Verification).
**What happened?**
On macOS, the connect step shows "Preparing browser sign-in…" and never
shows the sign-in link. The `claude setup-token` child is alive. It
prints the URL and the code prompt.
**Root cause**
Claude Code 2.1.317 selects the hint key with this logic (paraphrased
from the CLI bundle):
| Condition | Key in the hint |
|---|---|
| `TERM_PROGRAM=Apple_Terminal` | `Fn` |
| `TERM_PROGRAM=iTerm.app`, `LC_TERMINAL=iTerm2`, or VS Code/Cursor on
macOS | `Option` |
| a known terminal such as xterm, kitty, or WezTerm | `Shift` |
| other: SSH session (`SSH_CONNECTION`), multiplexer (`TMUX`, `STY`,
`ZELLIJ`), or macOS | `Shift (Option in iTerm2, Fn in Terminal.app)` |
`findBrowserCodePrompt` returns `null` when the first non-blank line
after the URL is not the prompt and not the `Shift` hint.
**Steps to reproduce**
1. On macOS, start Paperclip from Terminal.app, from iTerm2, or from a
shell with no `TERM_PROGRAM`.
2. Open onboarding. Select Connect a model → Claude (Subscription).
3. The UI stays on "Preparing browser sign-in…".
**Paperclip version or commit**
`master` at f5891564. Claude Code 2.1.317. macOS on Apple Silicon.
Local, `local_trusted`, embedded Postgres.
## What Changed
- `COPY_HINT_LINE_RE` accepts four key phrases: `Shift`, `Option`, `Fn`,
and `Shift (Option in iTerm2, Fn in Terminal.app)`. The other words of
the pattern do not change. The pattern lists the phrases. It does not
accept an arbitrary key.
- `findBrowserCodePrompt` joins up to three non-blank rows
(`MAX_COPY_HINT_LINES`) to match a wrapped hint, and then skips them.
- New tests: each key phrase, the two-row wrap, an unknown key (`Ctrl`)
that returns `null`, and a partial hint followed by an unrelated line
that returns `null`.
## Verification
- `cd packages/adapters/claude-local && npx vitest run
src/server/setup-token-parse.test.ts`: 77 passed. The four new positive
tests fail on `master`.
- `npx tsc --noEmit -p packages/adapters/claude-local`: pass.
- Live capture. I ran `claude setup-token` (2.1.317) through the same
`PYTHON_PTY_BRIDGE` and environment as `startLocalBrowserLogin`, with a
fresh `CLAUDE_CONFIG_DIR`. I gave each capture to
`parseSetupTokenPrompt`:
| Environment | Hint key | `master` | This PR |
|---|---|---|---|
| no `TERM_PROGRAM` | `Shift (Option in iTerm2, Fn in Terminal.app)`,
two rows | `null` | URL |
| `TERM_PROGRAM=Apple_Terminal` | `Fn` | `null` | URL |
| `TERM_PROGRAM=iTerm.app` | `Option` | `null` | URL |
| `TERM_PROGRAM=xterm` | `Shift` | URL | URL |
- Control checks on the failing capture. When I removed only the hint
rows, `master` returned the URL. A 120×40 PTY window did not change the
result. Thus the hint is the only cause here.
- End-to-end sign-in on macOS with a real Claude account. I ran
`runSetupTokenLogin` from this branch with the same PTY driver, the same
environment, and no `TERM_PROGRAM`, so Claude printed the long two-row
hint. The runner showed the URL after 3 s. I signed in and pasted the
code. The runner then sent the code, captured the token (correct
prefix), and ended with `outcome: "success"` and exit code 0. I did this
twice, with and without `TERM`. Both runs passed.
- Next step, not fixed here. Through the dev server UI, the URL and code
steps passed in both of my attempts. Then Claude exited with code 0, but
the runner reported `credentialDelivered: false`. In the captured stream
the renderer skipped the `i` of "see it again", so
`SETUP_TOKEN_AFTER_ANCHOR` did not match. This is the failure that
#17276 describes. The `#17276` parser (`renderTerminalScreen`) read the
token from that same stream. The result depends on the earlier screen
content, so it is intermittent. A reliable sign-in needs this PR and
#17276.
- Combined check. I applied the #17276 diff on top of this branch in a
local test branch. Its setup-token parser and runner tests passed (99).
Then I did the full onboarding flow in the dev server UI: Connect a
model → Claude → sign-in link → code. The runner delivered the
credential, `POST /ai-connections/local` returned 201, and the activity
log recorded `ai_connection.connected` and `subscription.discovered`.
- Dev server check. With `pnpm dev:once` on this branch, onboarding →
Connect a model → Claude shows the sign-in link and the code field in a
few seconds. On `master`, the parser returns `null` for this output (see
the table above).
- Not run: the full repository `pnpm -r typecheck`, `pnpm test:run`, and
`pnpm build`. CI runs them.
## Risks
- Low risk. The change is in one pure parser function. Any text between
the URL and the prompt that is not a known hint still makes the parser
return `null`.
- A future Claude Code version can add a new key phrase. Then the parser
fails closed, as it does today, and the phrase needs one more entry.
## Model Used
- Claude (Anthropic), model ID `claude-opus-5-5`, in Claude Code with
tool use (shell, file edit). The model helped with the investigation,
the live captures, and the code. I reviewed and ran each step.
## 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
- [ ] 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
- [ ] I will address all Greptile and reviewer comments before
requesting merge
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>