Right now everyone who uses this app is using my tokens from my api. How can I allow people to bring their own tokens from their Claude account?
Bring your own tokens
Where your key is spent today: lib/agent/launch.ts copies the server's ANTHROPIC_API_KEY into every sandbox, and lib/agent/runner.mjs (Agent SDK) just reads it from env. That's ~all the spend; the only other callers are the Haiku decider (lib/decide.ts, triage/rerank) and the rolling thread summary (finish.ts) — tiny, and they'll stay on the server key.
Plan — per-user Anthropic credentials, resolved at launch
- Store:
users.anthropic_key(AES-256-GCM encrypted at rest with a key derived fromCREDENTIALS_SECRET??AUTH_SECRET), plus a…_hint(last 4 chars) and timestamp. Migrationdrizzle/0011. - Settings page
/settings(new; link in the header user menu): paste a key, we verify it againstGET /v1/modelsbefore saving, show "sk-…abcd, added <date>", one-tap remove. Accepts a Console API key (sk-ant-api…) and a Claude Code OAuth token fromclaude setup-token(sk-ant-oat01-…) — the latter maps toCLAUDE_CODE_OAUTH_TOKENin the sandbox. ⚠️ Anthropic's terms say Pro/Max subscription tokens are for Claude Code itself, not third-party products via the Agent SDK — I'll support the mechanism but flag it in the UI; you can disable it if you'd rather be strict. - Resolution order per run (new
lib/anthropic-keys.ts, used bylaunch.tsand the localworker/index.ts): the person who triggered the run → the workspace owner → the server'sANTHROPIC_API_KEY. The job log records which one was used ("billing: @mira's key"). Guest-triggered runs can only land on owner/server. - Opt-out of the shared key: env
REQUIRE_OWN_ANTHROPIC_KEY=1drops step 3's server fallback; Ask Claude / run / fork then 403 with "add your Anthropic key in Settings" instead of launching a run that would crash. - Composer shows a small note under Ask Claude saying whose key the run will use, so nobody is surprised.
Not doing: per-run spend tracking, key rotation UI, keys for the decider/summaries.
threadide@8efad4cAnswer: the only place your key was being spent on other people was lib/agent/launch.ts, which copied the server's ANTHROPIC_API_KEY into every sandbox. Now each run resolves whose key to use, and users can add their own.
What shipped (8efad4c, pushed to thread/9cb287a5)
/settings(link next to your name in the header): paste an Anthropic key. API keys are verified withGET /v1/models(no tokens spent) before saving, stored AES-256-GCM encrypted underCREDENTIALS_SECRET ?? AUTH_SECRET, and only ever shown back assk-ant-api03…k9Qz. Two-tap remove.- Per run (
lib/anthropic-keys.ts): person who asked → workspace owner → serverANTHROPIC_API_KEY. The job log gets a line likebilling: API key of @mira (who asked)so any bill is traceable. Same in the local worker. - Composer shows "Runs on your Anthropic key." / "Runs on @osebo's key (workspace owner) — add your own in Settings" under the row while Ask Claude is ticked.
- Fail early: Ask Claude / Run / Fork / new thread return 403 "add your key in Settings" when there's nothing to bill, instead of launching a sandbox that crashes.
- Migration
drizzle/0011(3 nullable columns onusers) runs on the next prod build.
Two decisions for you, osebo
- Is the server key still lent out? Default: yes, as the last fallback — so nothing changes for anyone until they add a key. Set
REQUIRE_OWN_ANTHROPIC_KEY=1on Vercel and your key is only used for the Haiku decider + thread summaries (cents); everyone else must bring their own or be in a workspace whose owner has one. - Claude Code subscription tokens.
claude setup-tokengives ask-ant-oat01-…token; the form accepts it and the sandbox gets it asCLAUDE_CODE_OAUTH_TOKEN, which the Agent SDK honours. But Anthropic's terms say Pro/Max tokens are for Claude Code itself, not third-party products, so the form warns inline. If you'd rather be strict, delete theoauthbranch inclassifyKey— one line.
Verified / not verified
tscclean;seal/openround-trip + wrong secret + tampering, and key classification exercised with a tsx script.- UI from static mockups over the real CSS (screenshot attached); the app can't run in the sandbox, so the end-to-end save → run path is untested until the preview deploy.
How can we allow people to just use their Claude subscription?
Short answer: the mechanism for subscriptions already shipped in 8efad4c — a user runs claude setup-token in their terminal (needs Claude Code installed and logged in with their Pro/Max account), gets an sk-ant-oat01-… token, pastes it on /settings, and their runs go out with CLAUDE_CODE_OAUTH_TOKEN instead of an API key. The Agent SDK honours it, so the sandbox bills their subscription.
What we can't do: a browser "Sign in with Claude" button. Anthropic has no public OAuth client for third-party apps to bill a claude.ai subscription; the only client is Claude Code's own, and reusing its client id in another product is against the consumer terms (Anthropic has actively cut off tools that did that). So the paste-a-token route is the only one available, and even it sits in a grey area that the UI should state plainly rather than hide behind a warning that appears only after pasting.
What I'll change now (small):
/settingsgets two explicit tabs/sections — API key (Console, pay-as-you-go) and Claude subscription (step-by-step: install Claude Code →claude setup-token→ paste) — instead of one field with a post-hoc warning. Same storage, samePUT /api/me/anthropic-key.- Status line says "Claude subscription token" and the composer note says "Runs on your Claude subscription" when that's what's saved.
- README gains a "Using a Claude subscription" paragraph with the caveat.
Then push + refresh the PR description. I'll also merge main (sticky header) into the branch so the PR stays mergeable.
threadide@1bc941cHow people use their Claude subscription
It already works on this branch — the gap was that nobody could tell. Here's the whole picture:
The only route Anthropic leaves open
- User installs Claude Code (
npm i -g @anthropic-ai/claude-code), runsclaudeonce and signs in with their claude.ai (Pro/Max) account. - Runs
claude setup-token→ browser approval → it prints a long-lived tokensk-ant-oat01-…. - Pastes it on /settings. We store it encrypted; the sandbox gets it as
CLAUDE_CODE_OAUTH_TOKEN, which the Agent SDK uses instead of an API key, so the run bills their subscription.
What we can't build: a "Sign in with Claude" button
There is no OAuth client Anthropic gives to third-party apps for claude.ai subscriptions. The only client id that works is Claude Code's own, and using it from another product is a violation of the consumer terms — Anthropic has cut off tools that did exactly that. So a browser flow would be both unofficial and fragile. The paste-a-token route is the honest version of the same thing, and it still sits in a grey area: the terms say subscription access is for Claude Code itself. The settings page now says so plainly and lets people choose.
If you'd rather not allow subscriptions at all: delete the oauth branch in classifyKey (lib/anthropic-keys.ts) — one line, and the form will refuse those tokens.
What changed in 1bc941c
/settingshas an API key | Claude subscription switch. The subscription side shows the three steps above plus the caveat, instead of a warning that only appeared after pasting. The switch is cosmetic: whatever you paste is classified by prefix, and a mismatch is flagged, not refused.- Status line, composer note ("Runs on your Claude subscription." / "Runs on @osebo's Claude subscription (workspace owner)…") and the job log line all say "Claude subscription" for these tokens (new
credentialKind()helper). - README documents the route and the caveat.
- Merged
main(sticky header) into the branch so the PR stays clean.
Verified / not verified
tscclean; layout checked on a static mockup over the real CSS (attached). The app can't run in the sandbox, so the subscription-token path through the Agent SDK is untested end-to-end — the first run with asetup-tokentoken on the preview deploy is the real test. If it fails, the run log will show the SDK's auth error right after thebilling: Claude subscription token of @…line.- Subscription tokens can't be verified on save (no cheap endpoint accepts them); a bad token surfaces as a failed run, and the form says so.

