CLI code agent: support inline wpcom auth via STUDIO_WPCOM_TOKEN#3158
Merged
Conversation
If you want a body too (AGENTS.md says focus on why), here's one: CLI code agent: support inline wpcom auth via STUDIO_WPCOM_TOKEN Lets sandbox and CI runs authenticate `studio code` for a single invocation without writing to ~/.studio/config.json. When the env var is set, the wpcom provider uses the inline token and the initial provider is pinned to wpcom, skipping the picker. Falls through to the normal stored-token flow when unset.
sejas
reviewed
Apr 20, 2026
Member
sejas
left a comment
There was a problem hiding this comment.
The code looks good to me. I just left a question about whether the rule in Studio AGENTS.md is necessary.
Collaborator
📊 Performance Test ResultsComparing ffc4dc8 vs trunk app-size
site-editor
site-startup
Results are median values from multiple test runs. Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff) |
sejas
approved these changes
Apr 20, 2026
Member
sejas
left a comment
There was a problem hiding this comment.
Thanks for applying the changes. Looks good! With the env variable, it will be easier to call the Studio Code command with an existing authentication that is not saved in Studio home path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Related issues
How AI was used in this PR
Used Claude Code to brainstorm the shape of the feature, draft the provider changes, and write this PR description. I reviewed the diff myself — it's a small, surgical change to the AI provider plumbing.
Proposed Changes
STUDIO_WPCOM_TOKENenv var for single-invocation auth tostudio code. When set, the wpcom provider uses the inline token and skips~/.studio/config.jsonentirely.wpcomwhen the inline token is present, so the provider picker doesn't block a non-interactive run.AGENTS.md.The motivation: sandbox and CI environments can't really run
auth login, there's no browser and no config file to touch. So here: setSTUDIO_WPCOM_TOKENand the CLI picks it up for that one run. Nothing gets written to disk. If the var is unset, everything works like before — the stored-token flow runs as usual.One important caveat for reviewers: the CLI routes AI requests through
/wpcom/v2/ai-api-proxy, which allowlists Studio'sclient_id=95109. Tokens minted for other clients (e.g., via/oauth2/tokenwith a differentclient_id) will 403 at the gateway. This env var helps anyone who already has a Studio-compatible token, but it does not bypass the proxy's client check.Testing Instructions
npm run cli:buildstudio auth loginonce, then readauthToken.accessTokenfrom~/.studio/config.json.mv ~/.studio/config.json ~/.studio/config.json.bakmv ~/.studio/config.json.bak ~/.studio/config.jsonEdge cases worth checking:
STUDIO_WPCOM_TOKEN=' '→ treated as unset, falls back to stored token.Pre-merge Checklist