The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
Harness Team account: Codex on the owner's relay as a ChatGPT sign-in, so it has the owner's models
bitcoinbuilder7a043fa4060d
diff --git a/cli/src/lib/engineAccount.ts b/cli/src/lib/engineAccount.tsindex 00140b78a..96395692c 100644--- a/cli/src/lib/engineAccount.ts+++ b/cli/src/lib/engineAccount.ts@@ -16,6 +16,7 @@* every launch (`~/.claude.json`, which Harness's own folder trust writes too) would not say which* engine the person works in.*/+import { isCodexRelayAuth } from './subscriptionRelay.js'import { createHash } from 'node:crypto'import { execFile } from 'node:child_process'import { readdir, readFile, stat } from 'node:fs/promises'@@ -107,6 +108,8 @@ export async function engineAccount(engine: AgentEngine, deps: EngineAccountDepsconst lastUsedAt = deps.lastUsed === false ? null : await newestDay(join(dir, 'sessions'))if (env.OPENAI_API_KEY) return { signedIn: true, lastUsedAt }const auth = await readJson(join(dir, 'auth.json'))+ // The owner relay's sign-in (lib/subscriptionRelay.ts codexRelayAuth) is the relay's, not this account's own.+ if (isCodexRelayAuth(auth)) return { signedIn: false, lastUsedAt }const tokens = auth?.tokens as Record<string, unknown> | null | undefinedif (auth && (auth.OPENAI_API_KEY || (tokens && (tokens.access_token || tokens.refresh_token)))) {return { signedIn: true, lastUsedAt }diff --git a/cli/src/lib/subscriptionRelay.ts b/cli/src/lib/subscriptionRelay.tsindex 577ce1cd1..0d00efdc0 100644--- a/cli/src/lib/subscriptionRelay.ts+++ b/cli/src/lib/subscriptionRelay.ts@@ -279,3 +279,45 @@ export function codexRelayArgs(relayUrl: string): string[] {export function codexRelayEnv(token: string): Record<string, string> {return { [RELAY_TOKEN_VAR]: token }}++/**+ * Codex on the relay as a ChatGPT sign-in, not an API key: the provider asks for the sign-in in `auth.json`, which holds+ * [codexRelayAuth] (the relay token, nothing of the owner's). Through an API-key provider Codex never reads the+ * account's model list, so its `/model` picker offered only its built-in models and the agent stayed on `gpt-5.5`,+ * which ChatGPT refuses for an account it does not offer to ("The 'gpt-5.5' model is not supported when using Codex+ * with a ChatGPT account": every Codex start in a Harness Team account, 2026-10-29). As a sign-in, Codex reads the+ * owner's list through the relay (`/models`, kept in `models_cache.json`), and the model a start asks for is there.+ */+export function codexRelaySignInArgs(relayUrl: string): string[] {+ const p = OWNER_CODEX_PROVIDER+ return [+ '-c', `model_provider="${p}"`,+ '-c', `model_providers.${p}.name="Owner subscription"`,+ '-c', `model_providers.${p}.base_url="${relayUrl.replace(/\/$/, '')}/codex"`,+ '-c', `model_providers.${p}.requires_openai_auth=true`,+ '-c', `model_providers.${p}.wire_api="responses"`,+ '-c', `model_providers.${p}.supports_websockets=false`,+ ]+}++/** The account id a relay sign-in names: what tells it apart from a sign-in of the account's own (`isCodexRelayAuth`).+ * The relay puts the owner's own account id on every request in its place. */+export const CODEX_RELAY_ACCOUNT = 'harness-relay'++/**+ * The `auth.json` Codex reads for [codexRelaySignInArgs]: the relay token as its access token, and an id token that is+ * no secret (unsigned, no expiry: Codex reads only its plan from it). `last_refresh` is now, and written again at each+ * launch, so Codex never asks OpenAI to refresh it: the owner's daemon refreshes the owner's own sign-in.+ */+export function codexRelayAuth(token: string, now: number): string {+ const part = (value: unknown) => Buffer.from(JSON.stringify(value)).toString('base64url')+ const idToken = `${part({ alg: 'none', typ: 'JWT' })}.${part({ 'https://api.openai.com/auth': { chatgpt_plan_type: 'plus', chatgpt_account_id: CODEX_RELAY_ACCOUNT } })}.relay`+ return `${JSON.stringify({ OPENAI_API_KEY: null, tokens: { id_token: idToken, access_token: token, refresh_token: CODEX_RELAY_ACCOUNT,+ account_id: CODEX_RELAY_ACCOUNT }, last_refresh: new Date(now).toISOString() }, null, 2)}\n`+}++/** Whether a parsed `auth.json` is [codexRelayAuth]'s: the relay's, not a sign-in of the account's own. */+export function isCodexRelayAuth(auth: unknown): boolean {+ const tokens = auth && typeof auth === 'object' ? (auth as { tokens?: unknown }).tokens : null+ return !!tokens && typeof tokens === 'object' && (tokens as { account_id?: unknown }).account_id === CODEX_RELAY_ACCOUNT+}diff --git a/cli/src/team/relay.spec.ts b/cli/src/team/relay.spec.tsindex e61fb9a8a..b4d116412 100644--- a/cli/src/team/relay.spec.ts+++ b/cli/src/team/relay.spec.ts@@ -1,11 +1,12 @@-import { mkdtempSync, readFileSync, rmSync, statSync } from 'node:fs'+import { mkdirSync, mkdtempSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs'import { tmpdir } from 'node:os'import { join } from 'node:path'-import { afterEach, describe, expect, it, vi } from 'vitest'-import type { SubscriptionRelay } from '../lib/subscriptionRelay.js'+import { afterEach, describe, expect, it, onTestFinished, vi } from 'vitest'+import { CODEX_RELAY_ACCOUNT, codexRelayAuth, isCodexRelayAuth, type SubscriptionRelay } from '../lib/subscriptionRelay.js'+import { engineAccount } from '../lib/engineAccount.js'import type { TeamConfig } from './config.js'import {- publishTeamRelay, readTeamRelay, TEAM_RELAY_GUEST, teamRelayDir, teamRelayFile, teamRelayLaunch, teamRelayPublished, TeamRelayPublisher,+ publishTeamRelay, readTeamRelay, TEAM_RELAY_GUEST, teamRelayDir, teamRelayFile, teamRelayLaunch, teamRelayPublished, TeamRelayPublisher, writeCodexRelaySignIn,type TeamRelayLaunchDeps, type TeamRelayPublisherDeps, type TeamRelayReadDeps,} from './relay.js'@@ -148,7 +149,7 @@ describe('the team daemon, reading its owner\'s relay', () => {describe('a launch in the team account', () => {const grant = { url: 'http://127.0.0.1:9', token: TOKEN }const launchDeps = (over: Partial<TeamRelayLaunchDeps> = {}): TeamRelayLaunchDeps => ({- team: () => true, config: () => config, signedIn: async () => false, read: () => grant, onboarded: vi.fn(), ...over,+ team: () => true, config: () => config, signedIn: async () => false, read: () => grant, onboarded: vi.fn(), codexSignIn: vi.fn(() => true), ...over,})it('spends the owner\'s subscription for an engine it has not signed in itself', async () => {@@ -158,6 +159,15 @@ describe('a launch in the team account', () => {const codex = await teamRelayLaunch('codex', deps)expect(codex?.env).toEqual({ HARNESS_RELAY_TOKEN: TOKEN })expect(codex?.args).toContain('model_provider="harness_owner"')+ // As a ChatGPT sign-in through the relay, so Codex has the owner's models (2026-10-29: every start stayed on gpt-5.5).+ expect(deps.codexSignIn).toHaveBeenCalledWith(TOKEN)+ expect(codex?.args).toContain('model_providers.harness_owner.requires_openai_auth=true')+ expect(codex?.args.join(' ')).not.toContain('env_key')+ // A sign-in it could not write leaves Codex on the relay as an API key, as before.+ for (const codexSignIn of [() => false, () => { throw new Error('read-only') }]) {+ const fallback = await teamRelayLaunch('codex', launchDeps({ codexSignIn }))+ expect(fallback?.args).toContain('model_providers.harness_owner.env_key="HARNESS_RELAY_TOKEN"')+ }// A first-run screen that cannot be recorded is left for the engine to ask.expect(await teamRelayLaunch('claude', launchDeps({ onboarded: () => { throw new Error('read-only') } }))).not.toBeNull()expect(await teamRelayLaunch('codex', launchDeps({ signedIn: async () => { throw new Error('keychain') } }))).not.toBeNull()@@ -171,3 +181,33 @@ describe('a launch in the team account', () => {expect(await teamRelayLaunch('claude', launchDeps({ read: () => null }))).toBeNull()})})++describe('Codex\'s sign-in for the relay', () => {+ const home = () => { const dir = mkdtempSync(join(tmpdir(), 'team-codex-')); onTestFinished(() => rmSync(dir, { recursive: true, force: true })); return dir }++ it('writes the relay token as a ChatGPT sign-in, private to the account, and again at each launch', () => {+ const dir = join(home(), '.codex')+ expect(writeCodexRelaySignIn(dir, TOKEN, Date.parse('2026-10-29T04:00:00Z'))).toBe(true)+ const auth = JSON.parse(readFileSync(join(dir, 'auth.json'), 'utf8'))+ expect(auth.tokens).toMatchObject({ access_token: TOKEN, account_id: CODEX_RELAY_ACCOUNT })+ expect(auth.last_refresh).toBe('2026-10-29T04:00:00.000Z')+ expect(isCodexRelayAuth(auth)).toBe(true)+ expect(statSync(join(dir, 'auth.json')).mode & 0o777).toBe(0o600)+ // Codex reads its plan from the id token: three parts, the claims base64url JSON.+ const claims = JSON.parse(Buffer.from(auth.tokens.id_token.split('.')[1], 'base64url').toString())+ expect(claims['https://api.openai.com/auth']).toMatchObject({ chatgpt_account_id: CODEX_RELAY_ACCOUNT })+ expect(writeCodexRelaySignIn(dir, `${TOKEN}x`, Date.parse('2026-10-30T04:00:00Z'))).toBe(true)+ expect(JSON.parse(readFileSync(join(dir, 'auth.json'), 'utf8')).tokens.access_token).toBe(`${TOKEN}x`)+ })++ it('never replaces a sign-in of the account\'s own, which is read as signed in while the relay\'s is not', async () => {+ const root = home(), dir = join(root, '.codex')+ mkdirSync(dir)+ writeFileSync(join(dir, 'auth.json'), JSON.stringify({ tokens: { access_token: 'own', refresh_token: 'own', account_id: 'acct-1' } }))+ expect(writeCodexRelaySignIn(dir, TOKEN, 0)).toBe(false)+ expect(JSON.parse(readFileSync(join(dir, 'auth.json'), 'utf8')).tokens.account_id).toBe('acct-1')+ expect((await engineAccount('codex', { home: root, env: {}, lastUsed: false })).signedIn).toBe(true)+ writeFileSync(join(dir, 'auth.json'), codexRelayAuth(TOKEN, 0))+ expect((await engineAccount('codex', { home: root, env: {}, lastUsed: false })).signedIn).toBe(false)+ })+})diff --git a/cli/src/team/relay.ts b/cli/src/team/relay.tsindex 96b7791f9..76f052888 100644--- a/cli/src/team/relay.ts+++ b/cli/src/team/relay.ts@@ -18,14 +18,14 @@* ⚠️ The token is never logged, and lives only in the file and in the launched engine's environment.*/import { execFile } from 'node:child_process'-import { chmodSync, closeSync, constants, fstatSync, lstatSync, mkdirSync, openSync, readSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs'+import { chmodSync, closeSync, constants, fstatSync, lstatSync, mkdirSync, openSync, readFileSync, readSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs'import { homedir, userInfo } from 'node:os'import { join } from 'node:path'import type { AgentEngine } from '../engines/types.js'import { recordAcceptanceIn } from '../engines/kit/folderTrust.js'import { readAuthSession } from '../lib/authSession.js'import { engineAccount } from '../lib/engineAccount.js'-import { claudeRelayEnv, codexRelayArgs, codexRelayEnv, type SubscriptionRelay } from '../lib/subscriptionRelay.js'+import { claudeRelayEnv, codexRelayArgs, codexRelayEnv, codexRelayAuth, codexRelaySignInArgs, isCodexRelayAuth, type SubscriptionRelay } from '../lib/subscriptionRelay.js'import { readTeamConfig, type TeamConfig } from './config.js'/** The owner's folder for the hand-off, per owner so two people's Macs never share one. */@@ -219,6 +219,9 @@ export interface TeamRelayLaunchDeps {/** Claude Code that never ran in the team account opens on its first-run screens, which nobody is there to answer:* recorded as done, in the team account's own home, before the first launch on the relay. */onboarded(engine: 'claude' | 'codex'): void+ /** Codex's sign-in for the relay (lib/subscriptionRelay.ts codexRelayAuth), in the team account's own Codex home;+ * false when it could not be written. */+ codexSignIn(token: string): boolean}/** In the team daemon, for an engine it has not signed in itself: the owner's relay, when there is one. */@@ -231,9 +234,25 @@ export async function teamRelayLaunch(engine: AgentEngine, deps: TeamRelayLaunchconst grant = deps.read(config)if (!grant) return nulltry { deps.onboarded(engine) } catch { /* The engine asks on its screen, as it would have. */ }- return engine === 'claude'- ? { env: claudeRelayEnv(grant.url, grant.token), args: [] }- : { env: codexRelayEnv(grant.token), args: codexRelayArgs(grant.url) }+ if (engine === 'claude') return { env: claudeRelayEnv(grant.url, grant.token), args: [] }+ // As a ChatGPT sign-in, so Codex has the owner's models (codexRelaySignInArgs); as an API key, as before, when the+ // sign-in could not be written.+ let signIn = false+ try { signIn = deps.codexSignIn(grant.token) } catch { signIn = false }+ return { env: codexRelayEnv(grant.token), args: signIn ? codexRelaySignInArgs(grant.url) : codexRelayArgs(grant.url) }+}++/** Writes the relay's sign-in to [dir]/auth.json, unless a sign-in of the account's own is there. Private to the account. */+export function writeCodexRelaySignIn(dir: string, token: string, now: number): boolean {+ const file = join(dir, 'auth.json')+ let existing: unknown = null+ try { existing = JSON.parse(readFileSync(file, 'utf8')) } catch { existing = null }+ if (existing && !isCodexRelayAuth(existing)) return false+ mkdirSync(dir, { recursive: true, mode: 0o700 })+ const next = `${file}.harness-relay-${process.pid}`+ writeFileSync(next, codexRelayAuth(token, now), { mode: 0o600 })+ renameSync(next, file)+ return true}/** The team daemon's own: its sign-in, the root-owned config, its engines' sign-ins in its own home. */@@ -244,6 +263,7 @@ export const realTeamRelayLaunch = (engine: AgentEngine) => teamRelayLaunch(engisignedIn: async (e) => (await engineAccount(e, { home: homedir(), env: process.env, lastUsed: false })).signedIn === true,read: (config) => readTeamRelay(config),onboarded: (e) => { if (e === 'claude') recordAcceptanceIn(join(homedir(), '.claude.json'), 'hasCompletedOnboarding') },+ codexSignIn: (token) => writeCodexRelaySignIn(process.env.CODEX_HOME || join(homedir(), '.codex'), token, Date.now()),})/** In the team daemon: whether the owner's relay is there for its engines (superTabs/machines.ts readiness). */