Repository navigation
feat(install): inject GH_TOKEN into Codex via [shell_environment_policy.set] — workaround openai/codex#10695 - #368
Conversation
…cy.set] (workaround openai/codex#10695) Codex's sandbox can't reliably reach the macOS Keychain to validate gh's stored token. Symptom: gh auth status flakes between ✓ and X within a single Codex session, airc join trips on the X path even though the token is real and valid (Joel hit this on the codex first-encounter QA pass; openai/codex#10695 is the upstream tracking bug, with a contributor analysis confirming Codex's shell handlers don't merge session dependency_env into spawned processes; patch in flight). OpenAI's own maintainer guidance on #10695: "If echo $GH_TOKEN is defined at app launch it's visible to sandboxed tools." Codex's [shell_environment_policy.set] is documented as "explicit environment overrides injected into every subprocess" — exactly what's needed to inject GH_TOKEN at session start and bypass the keychain flake. install.sh now writes a marker-bracketed block to ~/.codex/config.toml: # AIRC-GH-TOKEN-START — managed by install.sh; airc update refreshes... [shell_environment_policy.set] GH_TOKEN = "<gh-auth-token-output>" # AIRC-GH-TOKEN-END Idempotent + token-refreshing: every install.sh run (including airc update) strips any prior airc-managed block via sed range-delete and rewrites with the current `gh auth token` output. If gh auth rotates keys, the next airc update propagates the new token. Composes cleanly with user-defined [shell_environment_policy] keys at the parent level (inherit, include_only, etc.) because we use the sub-table form [shell_environment_policy.set] rather than inline `set = { ... }` syntax that would conflict. AIRC_SKIP_CODEX_TOKEN=1 escape hatch for users who'd rather manage GH_TOKEN themselves (shell alias, separate launcher, etc). uninstall.sh: matching cleanup strips the marker-bracketed block from ~/.codex/config.toml when airc is removed. Same sed range-delete pattern. Trade-offs explicitly documented in the codex README: - Token is plaintext on disk in ~/.codex/config.toml (similar trust posture to ~/.codex/auth.json which already holds OpenAI creds). - When openai/codex#10695 lands a fix, this injection becomes a no-op safety net rather than load-bearing workaround. Joel's stated preferences ruled out: - PATH-shadowing codex (too invasive — "major interference to man-in-the-middle codex") - Asking the user to type the launch one-liner each time ("yuck") - Shellrc-exporting GH_TOKEN to every shell (security leak beyond airc's scope) Tested on this Mac: live install run wrote the block with current gh token, Codex starts cleanly, second install.sh run replaced the block (no duplicate), uninstall flow strips cleanly. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
🤖 post-merge live test result: GH_TOKEN injection alone is insufficient — deeper sandbox flake Joel restarted Codex post-merge, ran `/join`. Outcome: ``` The injected GH_TOKEN IS the same valid keychain token that Claude Code on the same Mac uses successfully right now. So gh saying "Failed to log in using token (GH_TOKEN)" is misreporting a Codex-sandbox network failure as auth failure — same root issue we hit pre-#368, just rebadged from "keyring invalid" to "GH_TOKEN invalid." Verdict: the token mechanism (keychain vs env) is moot when Codex's sandbox flakily mangles gh's `/user` validation call. Both paths hit the same broken network layer. What would actually unblock: airc's preflight needs to skip gh-auth-status entirely when Codex env is detected and attempt the gist operation directly. If gh can't validate the token via /user but the actual gist API call works (or at least returns a useful error), proceed instead of dying at preflight. That's an airc-binary change, not a skill text change. Tracked as a follow-up to #367 + #368. This PR (#368) still ships value as a no-op safety net for when openai/codex#10695 lands the upstream fix — once `dependency_env` propagation works, the env-injection mechanism here will become load-bearing without needing the airc-side skip-preflight. Leaving merged. For Joel's Carl QA pass: pausing Codex+airc here. Claude Code path remains fully shippable. Distributed mesh research already converged on Codex sandbox flakiness as the root cause; further iteration on our side won't change the upstream constraint. |
Codex's sandbox can't reliably reach the macOS Keychain to validate gh's stored token. Symptom from Joel's QA pass:
gh auth statusflakes between ✓ and X within a single Codex session,airc jointrips on the X path even though the token is real and valid. This is the upstream bug at openai/codex#10695 — patch in flight from a contributor (shell handlers don't mergedependency_envinto spawned processes).OpenAI's own maintainer guidance on #10695: "If
echo $GH_TOKENis defined at app launch it's visible to sandboxed tools." And Codex docs confirm[shell_environment_policy.set]is "explicit environment overrides injected into every subprocess" — exactly the right knob.What this PR does
install.shnow writes a marker-bracketed block to~/.codex/config.tomlafter the existing permission-profile setup:After Codex restart, sandboxed
ghandaircinvocations see GH_TOKEN in env and never depend on the keychain probe. The flake disappears.Idempotent + self-refreshing: every install.sh run (incl
airc update) strips any prior airc-managed block via sed range-delete and rewrites with the currentgh auth tokenoutput. Token rotation just works.Composes with user config: uses
[shell_environment_policy.set]sub-table form (not inlineset = {...}) so it doesn't conflict with user-defined parent keys likeinheritorinclude_only.Opt-out:
AIRC_SKIP_CODEX_TOKEN=1skips the injection (for users who prefer to manage GH_TOKEN via shell alias / launcher / CI secret).uninstall.sh: matching cleanup strips the marker-bracketed block when airc is removed.
Trade-offs (documented in the codex README)
~/.codex/config.toml. Similar trust posture to~/.codex/auth.jsonwhich already holds the user's OpenAI credentials. Both are in the user's home dir at default 0600.Joel's preferences ruled out
codex("major interference to man-in-the-middle codex")Tested on this Mac
Test plan
bash -n install.sh && bash -n uninstall.shgh auth refresh→ next install.sh picks up new token (verified by SHA-comparing the GH_TOKEN value before/after)/joinin airc tab, expect successful mesh join (no token-invalid flake)Related
🤖 Generated with Claude Code