Repository navigation
feat(connect): reuse a sign-in another CLI already completed - #427
Merged
Merged
Conversation
Forge keeps its own credential store and reads nothing else, so a user
already signed in to codex, opencode or grok on the same machine was still
sent through a second device-code grant in a browser. Nothing about that
second grant is more secure — same account, same OAuth client, same machine
— it is just friction, and it was the one thing that blocked Forge from
starting at all during the four-way benchmark.
forge-connect gains an `import` module that finds those sessions:
~/.codex/auth.json Codex -> openai_codex, openai
~/.local/share/opencode/auth.json OpenCode -> openai_codex, xai,
opencode_go, anthropic
~/.grok/auth.json Grok -> xai
Discovery is read-only and never adopts anything on its own. A route that
has a reusable session shows a `reuse Codex` tag in the existing
right-aligned tag column of the provider picker, and pressing Enter on that
row — which is the consent — imports instead of opening a browser. A failed
import falls through to the ordinary flow rather than stranding the user.
Client ids line up, so imported refresh tokens stay refreshable: Forge's
openai-codex profile already uses the Codex CLI's own public client, and the
Grok store is literally keyed by the same client id `oauth_xai` defaults to.
Two format details that would have caused silent misbehaviour. OpenCode
stores expiries in milliseconds while Forge's parser reads bare digits as
epoch seconds, so passing them through unchanged would have dated every
token ~50,000 years out and it would never have been refreshed. Codex
records `last_refresh` rather than an expiry, so that import leaves
`expires_at` unset — "use until the API rejects it" is the honest reading.
Secrets never reach a log line: `DiscoveredLogin` and `DiscoveredSecret`
have hand-written Debug impls that redact, with a test that asserts it.
Discovery takes its paths as arguments rather than reading XDG_DATA_HOME
internally, so it is a pure function of them and the tests are hermetic
rather than passing by luck on a machine where the var happens to be unset.
Also fixes the other half of the connect contradiction #426 addressed.
ConversationRenderKey carried no field for connection state or model, but
the home splash bakes both into its card — so the card was built once and
frozen, and a freshly connected session still read "not connected" while
the footer said otherwise. Invalidating the credential cache (#426) was
necessary but not sufficient; the render cache had to learn about it too.
Verified end to end: a Forge home containing nothing but a copied
.codex/auth.json reaches `provider OpenAI ● connected` on
openai-codex/gpt-5.6-sol with no browser, and answers a real turn.
Claude-Session: https://claude.ai/code/session_018ihDDc3ahfrxu5AYL9moXs
It passed locally and failed on CI, for a reason worth recording. The fixture sets `provider: "mock"`, and `is_mock_provider` short-circuits `provider_connected_cached` to true — so on CI the card read "connected" before the test had connected anything, and the first assertion failed. It passed on this machine only because `TuiApp::new` restored a real persisted selection (`native` / `xai/grok-3`) over the fixture's mock, which happens to make the connection logic run for real. So the test was asserting against whichever provider the host happened to leave behind. Pin both fields explicitly after construction; neither the fixture nor the host can reach them now. Claude-Session: https://claude.ai/code/session_018ihDDc3ahfrxu5AYL9moXs
mohitranka
added a commit
that referenced
this pull request
Sep 11, 2026
* feat(connect): reuse a sign-in another CLI already completed
Forge keeps its own credential store and reads nothing else, so a user
already signed in to codex, opencode or grok on the same machine was still
sent through a second device-code grant in a browser. Nothing about that
second grant is more secure — same account, same OAuth client, same machine
— it is just friction, and it was the one thing that blocked Forge from
starting at all during the four-way benchmark.
forge-connect gains an `import` module that finds those sessions:
~/.codex/auth.json Codex -> openai_codex, openai
~/.local/share/opencode/auth.json OpenCode -> openai_codex, xai,
opencode_go, anthropic
~/.grok/auth.json Grok -> xai
Discovery is read-only and never adopts anything on its own. A route that
has a reusable session shows a `reuse Codex` tag in the existing
right-aligned tag column of the provider picker, and pressing Enter on that
row — which is the consent — imports instead of opening a browser. A failed
import falls through to the ordinary flow rather than stranding the user.
Client ids line up, so imported refresh tokens stay refreshable: Forge's
openai-codex profile already uses the Codex CLI's own public client, and the
Grok store is literally keyed by the same client id `oauth_xai` defaults to.
Two format details that would have caused silent misbehaviour. OpenCode
stores expiries in milliseconds while Forge's parser reads bare digits as
epoch seconds, so passing them through unchanged would have dated every
token ~50,000 years out and it would never have been refreshed. Codex
records `last_refresh` rather than an expiry, so that import leaves
`expires_at` unset — "use until the API rejects it" is the honest reading.
Secrets never reach a log line: `DiscoveredLogin` and `DiscoveredSecret`
have hand-written Debug impls that redact, with a test that asserts it.
Discovery takes its paths as arguments rather than reading XDG_DATA_HOME
internally, so it is a pure function of them and the tests are hermetic
rather than passing by luck on a machine where the var happens to be unset.
Also fixes the other half of the connect contradiction #426 addressed.
ConversationRenderKey carried no field for connection state or model, but
the home splash bakes both into its card — so the card was built once and
frozen, and a freshly connected session still read "not connected" while
the footer said otherwise. Invalidating the credential cache (#426) was
necessary but not sufficient; the render cache had to learn about it too.
Verified end to end: a Forge home containing nothing but a copied
.codex/auth.json reaches `provider OpenAI ● connected` on
openai-codex/gpt-5.6-sol with no browser, and answers a real turn.
Claude-Session: https://claude.ai/code/session_018ihDDc3ahfrxu5AYL9moXs
* test(tui): pin the route in the home-card repaint test
It passed locally and failed on CI, for a reason worth recording.
The fixture sets `provider: "mock"`, and `is_mock_provider` short-circuits
`provider_connected_cached` to true — so on CI the card read "connected"
before the test had connected anything, and the first assertion failed. It
passed on this machine only because `TuiApp::new` restored a real persisted
selection (`native` / `xai/grok-3`) over the fixture's mock, which happens
to make the connection logic run for real.
So the test was asserting against whichever provider the host happened to
leave behind. Pin both fields explicitly after construction; neither the
fixture nor the host can reach them now.
Claude-Session: https://claude.ai/code/session_018ihDDc3ahfrxu5AYL9moXs
mohitranka
added a commit
that referenced
this pull request
Sep 11, 2026
* feat(connect): reuse a sign-in another CLI already completed
Forge keeps its own credential store and reads nothing else, so a user
already signed in to codex, opencode or grok on the same machine was still
sent through a second device-code grant in a browser. Nothing about that
second grant is more secure — same account, same OAuth client, same machine
— it is just friction, and it was the one thing that blocked Forge from
starting at all during the four-way benchmark.
forge-connect gains an `import` module that finds those sessions:
~/.codex/auth.json Codex -> openai_codex, openai
~/.local/share/opencode/auth.json OpenCode -> openai_codex, xai,
opencode_go, anthropic
~/.grok/auth.json Grok -> xai
Discovery is read-only and never adopts anything on its own. A route that
has a reusable session shows a `reuse Codex` tag in the existing
right-aligned tag column of the provider picker, and pressing Enter on that
row — which is the consent — imports instead of opening a browser. A failed
import falls through to the ordinary flow rather than stranding the user.
Client ids line up, so imported refresh tokens stay refreshable: Forge's
openai-codex profile already uses the Codex CLI's own public client, and the
Grok store is literally keyed by the same client id `oauth_xai` defaults to.
Two format details that would have caused silent misbehaviour. OpenCode
stores expiries in milliseconds while Forge's parser reads bare digits as
epoch seconds, so passing them through unchanged would have dated every
token ~50,000 years out and it would never have been refreshed. Codex
records `last_refresh` rather than an expiry, so that import leaves
`expires_at` unset — "use until the API rejects it" is the honest reading.
Secrets never reach a log line: `DiscoveredLogin` and `DiscoveredSecret`
have hand-written Debug impls that redact, with a test that asserts it.
Discovery takes its paths as arguments rather than reading XDG_DATA_HOME
internally, so it is a pure function of them and the tests are hermetic
rather than passing by luck on a machine where the var happens to be unset.
Also fixes the other half of the connect contradiction #426 addressed.
ConversationRenderKey carried no field for connection state or model, but
the home splash bakes both into its card — so the card was built once and
frozen, and a freshly connected session still read "not connected" while
the footer said otherwise. Invalidating the credential cache (#426) was
necessary but not sufficient; the render cache had to learn about it too.
Verified end to end: a Forge home containing nothing but a copied
.codex/auth.json reaches `provider OpenAI ● connected` on
openai-codex/gpt-5.6-sol with no browser, and answers a real turn.
Claude-Session: https://claude.ai/code/session_018ihDDc3ahfrxu5AYL9moXs
* test(tui): pin the route in the home-card repaint test
It passed locally and failed on CI, for a reason worth recording.
The fixture sets `provider: "mock"`, and `is_mock_provider` short-circuits
`provider_connected_cached` to true — so on CI the card read "connected"
before the test had connected anything, and the first assertion failed. It
passed on this machine only because `TuiApp::new` restored a real persisted
selection (`native` / `xai/grok-3`) over the fixture's mock, which happens
to make the connection logic run for real.
So the test was asserting against whichever provider the host happened to
leave behind. Pin both fields explicitly after construction; neither the
fixture nor the host can reach them now.
Claude-Session: https://claude.ai/code/session_018ihDDc3ahfrxu5AYL9moXs
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.
Forge keeps its own credential store and reads nothing else, so someone already signed in to
codex,opencodeorgrokon the same machine still got sent through a second device-code grant in a browser. Nothing about that second grant is more secure — same account, same OAuth client, same machine. It's friction, and during the four-way benchmark it was the one thing that stopped Forge from starting at all.What it does
forge-connectgains animportmodule that finds existing sessions:~/.codex/auth.jsonopenai_codex,openai~/.local/share/opencode/auth.jsonopenai_codex,xai,opencode_go,anthropic~/.grok/auth.jsonxaiA route with a reusable session shows a
reuse Codextag in the provider picker's existing right-aligned tag column:Pressing Enter on that row is the consent — it imports instead of opening a browser. Discovery itself is read-only and never adopts anything on its own, and a failed import falls through to the ordinary flow rather than stranding you.
Why the tokens actually work
Client ids line up, so imported refresh tokens stay refreshable. Forge's openai-codex profile already uses the Codex CLI's own public client (
oauth_openai_codex.rs:8), and the Grok store is literally keyed by the same client idoauth_xai.rs:21defaults to.Two format traps
last_refresh, not an expiry, so that import leavesexpires_atunset — "use until the API rejects it" is the honest reading. Inventing a lifetime would either refresh needlessly or claim validity we can't know.Handling secrets
DiscoveredLoginandDiscoveredSecrethave hand-writtenDebugimpls that redact, with a test asserting no token material survives a{:?}. Discovery takes its paths as arguments rather than readingXDG_DATA_HOMEinternally, so it's a pure function of them — the first version read the env var inside, which meant that with the var set it ignored its ownhomeargument and read the real user's file, and the tests passed only by luck.Also: the other half of #426
ConversationRenderKeycarried no field for connection state or model, but the home splash bakes both into its card. The card was built once and frozen, so a freshly connected session still readprovider ● not connectedwhile the footer said otherwise. Invalidating the credential cache in #426 was necessary but not sufficient — the render cache had to learn about it too. Caught by running this feature in a PTY, not by reading code.Verification
cargo fmt --all -- --checkclean ·cargo clippy --all-targetsclean ·cargo test --workspace45/45 binaries, 0 failures · 9 discovery tests + 5 wiring tests.End to end, from a Forge home containing nothing but a copied
.codex/auth.json:No browser, and on the profile's declared default model.
https://claude.ai/code/session_018ihDDc3ahfrxu5AYL9moXs