Add login: codexPlanLogin() to the Codex provider in providerKeys. Then /connect:codex signs the user in with their own ChatGPT plan, and the Codex adapter runs with that login and no API key. Grok Build works the same way with grokBuildPlanLogin() and a SuperGrok plan.
Use this for a harness that runs on the computer of the user: a CLI or a desktop app. The login belongs to the machine, so it is not for a hosted app with many users.
npm i @tanstack/ai-harness @tanstack/ai-persistence @tanstack/ai-openai @tanstack/ai-sandbox @tanstack/ai-sandbox-local-process @tanstack/ai-codex @tanstack/ai-grok-buildpnpm add @tanstack/ai-harness @tanstack/ai-persistence @tanstack/ai-openai @tanstack/ai-sandbox @tanstack/ai-sandbox-local-process @tanstack/ai-codex @tanstack/ai-grok-buildyarn add @tanstack/ai-harness @tanstack/ai-persistence @tanstack/ai-openai @tanstack/ai-sandbox @tanstack/ai-sandbox-local-process @tanstack/ai-codex @tanstack/ai-grok-buildbun add @tanstack/ai-harness @tanstack/ai-persistence @tanstack/ai-openai @tanstack/ai-sandbox @tanstack/ai-sandbox-local-process @tanstack/ai-codex @tanstack/ai-grok-buildGive each provider a login, and give each adapter authMode: 'host':
import { defineHarness } from '@tanstack/ai-harness'
import { providerKeys } from '@tanstack/ai-harness/plugins'
import { codexPlanLogin, codexText } from '@tanstack/ai-codex'
import { codexByok } from '@tanstack/ai-codex/byok'
import { grokBuildPlanLogin, grokBuildText } from '@tanstack/ai-grok-build'
import { grokBuildByok } from '@tanstack/ai-grok-build/byok'
import { openaiText } from '@tanstack/ai-openai'
import { defineSandbox, defineWorkspace, localSource } from '@tanstack/ai-sandbox'
import { codingAgents } from '@tanstack/ai-sandbox/harness'
import { localProcessSandbox } from '@tanstack/ai-sandbox-local-process'
const repo = '/path/to/your/repo'
export const lead = defineHarness({
name: 'acme/lead',
adapter: openaiText('gpt-6.1-sol'),
expose: {
commands: ['connect:codex', 'disconnect:codex', 'connect:grok-build', 'disconnect:grok-build', 'keys'],
},
plugins: () => [
providerKeys({
providers: [
{ ...codexByok, login: codexPlanLogin() },
{ ...grokBuildByok, login: grokBuildPlanLogin() },
],
}),
codingAgents({
sandbox: defineSandbox({
id: 'repo',
provider: localProcessSandbox({ dir: repo }),
workspace: defineWorkspace({ source: localSource(repo) }),
}),
agents: {
codex: {
adapter: codexText('gpt-6.1-sol', { authMode: 'host' }),
description: 'Quick fixes and tests',
},
grok: {
adapter: grokBuildText('grok-4.7-build-fast', { authMode: 'host' }),
description: 'Larger changes and refactors',
},
},
}),
],
})For more about codingAgents, see Delegate to coding agents.
If the user cancels the command, the harness stops the CLI.
A CLI from runCli shows them for you:
Sign in to codex. Open https://auth.example.com/device and enter the code ABCD-1234.For your own UI, first serve the harness. Mount the handler on /api/harness:
import { createHarnessHost, membersOnly } from '@tanstack/ai-harness'
import { createHarnessHandler } from '@tanstack/ai-harness/server'
import { memoryPersistence } from '@tanstack/ai-persistence'
// A long random secret. The UI sends the same one.
const token = process.env.HARNESS_TOKEN
const host = createHarnessHost({
persistence: memoryPersistence(),
access: {
// With no token set, nobody gets in.
getUser: ({ request }) =>
token && request.headers.get('authorization') === `Bearer ${token}`
? { id: 'me' }
: null,
rules: membersOnly(),
},
})
export const handler = createHarnessHandler({ host, harness: lead })The plan login belongs to the machine, so let only the user of the machine in. Set HARNESS_TOKEN on the server, and give the UI the same value. See Access and tenants.
Then listen for signIn on the session view, and run the exposed command:
import { createHarnessClient } from '@tanstack/ai-harness/client'
import { createSessionView } from '@tanstack/ai-harness/view'
const view = createSessionView(
createHarnessClient({
url: '/api/harness',
threadId: 'ada-chat',
headers: { authorization: 'Bearer my-token' },
}),
)
view.on('signIn', ({ connector, url, userCode }) => {
if (!url) return
console.log(`Sign in to ${connector}: open ${url}`)
if (userCode) console.log(`Enter this code on that page: ${userCode}`)
})
export const connectCodex = () => view.runCommand({ name: 'connect:codex' })The client gets only the page and the code. The tokens stay in the login file of the CLI on the machine. The harness keeps no copy of them.
/keys shows the plan:
Codex: signed in with your ChatGPT plan
Grok Build: missing. Run /connect grok-build.For each provider, /keys uses the first of these that it finds:
In your own UI, the plan sign-in has state: 'plan' in session.snapshot().plugins['tanstack/provider-keys'].providers.
The CLI keeps the login in its own file:
The machine has one login for each CLI, and the terminal of the user shares it. So:
Codex can keep its login in the OS keyring, with cli_auth_credentials_store = "keyring" or "auto" in ~/.codex/config.toml. Then there is no auth.json, and the harness cannot see the login:
To fix it, keep the login in a file. Set this in ~/.codex/config.toml, then run /connect:codex again:
cli_auth_credentials_store = "file"The sample above uses a local-process sandbox, so the CLI reads the login file of the machine. Docker and cloud sandboxes also work: the adapter copies the login file into the sandbox for each run, and deletes it after the run. See Use the host login in Docker or a cloud sandbox.
Each vendor has its own terms for a plan login. Read them before you ship:
Claude plans have no sign-in here. Anthropic does not let third-party apps offer Claude.ai login. See Legal and compliance. Claude Code users sign in with an Anthropic API key.