feat: ship Agent Foundry as a Codex plugin #271

Merged
claudiomaradonna merged 3 commits from feat/codex-plugin into main 2026-12-02 21:49:45 +01:00
Collaborator

Why

#269 and #270 gave OpenCode and Claude Code a form of Agent Foundry loaded from outside the repository, so a newer source reaches every repository without a foundry-upgrade in each one. This adds the same for Codex. Codex differs in ways that matter:

  • a Codex plugin carries skills and hooks but no subagents and no instructions;
  • each hook's added context is capped at about 2,500 tokens;
  • Codex runs a plugin's hooks only once the user trusts them.

Codex can read the Claude Code plugin's files, but only through a path it calls legacy-compatible, so Codex gets a target and a branch of its own, in its native layout.

Refs #268

What changed

scripts/build-form.sh codex <commit> <folder> builds a Codex marketplace, dumbledore, in Codex's native layout:

  • .agents/plugins/marketplace.json;
  • the plugin dumbledore with .codex-plugin/plugin.json, whose version is the commit;
  • the same shared part as the other targets;
  • hooks/hooks.json, wiring the main-checkout guard and the shell check on apply_patch, and one SessionStart hook with additionalContextLimit: 0.

The SessionStart hook hands over the whole policy in one message, with where the plugin sits and how Codex names its skills (dumbledore:<name>). Codex runs it again after a compaction.

Beside the plugin, codex-agents/*.toml holds the seven subagents, each with its brief inlined, for the operator to copy into ~/.codex/agents/:

  • Only the three implementers' files turn features.plugins on, so the guard and the shell check run in them. The reviewers keep plugins off, which keeps them away from other plugins' tools while they read untrusted text.
  • Each file carries a sha256 fingerprint of what the build writes. When the installed copies differ, the SessionStart hook adds a warning asking the model to tell the user to copy them again.

scripts/publish-form.sh now takes the target, and the Maintenance workflow's publish job publishes claude-plugin, then codex-plugin. The section "Plugin for Codex" of docs/INSTALL.md covers installing, trusting, copying the subagents, updating, and checking the plugin.

How to verify

Needs Codex 0.173.0 (npm install -g @openai/codex@0.173.0), signed in, plus jq and sha256sum. Branch tip 7d92842, base main at 1e6bc53.

  1. In a scratch repository holding only a README and a git-ignored AGENTS.local.md with a Test command, run:

    scripts/build-form.sh codex HEAD /tmp/example/build
    codex plugin marketplace add /tmp/example/build
    codex plugin add dumbledore@dumbledore
    cp /tmp/example/build/codex-agents/*.toml ~/.codex/agents/
    

    Then trust the three hooks in /hooks and start a new session.

  2. Ask "Without running any command, quote the first bullet of the section Working with the user." The answer starts "Material decisions, such as product, architecture, and stack choices".

Run on 2026-12-02 with Codex 0.173.0, signed in with ChatGPT, in a scratch CODEX_HOME, these gave the expected results:

  • the policy came whole, again after three forced compactions;
  • 27 skills were listed as dumbledore:<name>, without foundry-upgrade;
  • all seven subagents spawned with their briefs;
  • the guard refused an apply_patch in the main checkout;
  • an implementer subagent's edit adding echo $2 showed ShellCheck's SC2086;
  • the session answered the Test command from AGENTS.local.md;
  • changing an installed file's fingerprint brought the warning;
  • codex plugin marketplace upgrade updated a Git marketplace served from a local bare repository, and a second codex plugin add updated a local one.

On the tip, tests/verify-agent-config.sh passed 427 tests:

  • build-form.sh 53, with new tests for the codex target;
  • publish-form.sh 12, with new tests for codex-plugin.

tests/check-work-folder.sh passed 46, and ShellCheck, prettier, the static validator, and git diff --check main also pass. The new tests fail on main at the codex target name, or at the target argument of publish-form.sh, both of which this branch adds.

Considerations

  • Codex counts every file of the plugin in each hook's trust, so after any update the hooks need trusting again in /hooks. Until then a session runs without the policy, the guard, and the shell check. docs/INSTALL.md says so.
  • An installed subagent file is a copy that lags the plugin until the operator copies it again; the warning shows only when the content differs.
  • The publish job has not run with the codex target on the forge yet; its first push to main after the merge creates codex-plugin.
  • The sandbox question from the Claude Code work stays open.

https://claude.ai/code/session_012wUN2eKSj9s2vRHJdFPNk3

## Why #269 and #270 gave OpenCode and Claude Code a form of Agent Foundry loaded from outside the repository, so a newer source reaches every repository without a `foundry-upgrade` in each one. This adds the same for Codex. Codex differs in ways that matter: - a Codex plugin carries skills and hooks but no subagents and no instructions; - each hook's added context is capped at about 2,500 tokens; - Codex runs a plugin's hooks only once the user trusts them. Codex can read the Claude Code plugin's files, but only through a path it calls legacy-compatible, so Codex gets a target and a branch of its own, in its native layout. Refs #268 ## What changed `scripts/build-form.sh codex <commit> <folder>` builds a Codex marketplace, `dumbledore`, in Codex's native layout: - `.agents/plugins/marketplace.json`; - the plugin `dumbledore` with `.codex-plugin/plugin.json`, whose `version` is the commit; - the same shared part as the other targets; - `hooks/hooks.json`, wiring the main-checkout guard and the shell check on `apply_patch`, and one SessionStart hook with `additionalContextLimit: 0`. The SessionStart hook hands over the whole policy in one message, with where the plugin sits and how Codex names its skills (`dumbledore:<name>`). Codex runs it again after a compaction. Beside the plugin, `codex-agents/*.toml` holds the seven subagents, each with its brief inlined, for the operator to copy into `~/.codex/agents/`: - Only the three implementers' files turn `features.plugins` on, so the guard and the shell check run in them. The reviewers keep plugins off, which keeps them away from other plugins' tools while they read untrusted text. - Each file carries a sha256 fingerprint of what the build writes. When the installed copies differ, the SessionStart hook adds a warning asking the model to tell the user to copy them again. `scripts/publish-form.sh` now takes the target, and the Maintenance workflow's `publish` job publishes `claude-plugin`, then `codex-plugin`. The section "Plugin for Codex" of `docs/INSTALL.md` covers installing, trusting, copying the subagents, updating, and checking the plugin. ## How to verify Needs Codex 0.173.0 (`npm install -g @openai/codex@0.173.0`), signed in, plus `jq` and `sha256sum`. Branch tip `7d92842`, base `main` at `1e6bc53`. 1. In a scratch repository holding only a README and a git-ignored `AGENTS.local.md` with a Test command, run: ```sh scripts/build-form.sh codex HEAD /tmp/example/build codex plugin marketplace add /tmp/example/build codex plugin add dumbledore@dumbledore cp /tmp/example/build/codex-agents/*.toml ~/.codex/agents/ ``` Then trust the three hooks in `/hooks` and start a new session. 2. Ask "Without running any command, quote the first bullet of the section Working with the user." The answer starts "Material decisions, such as product, architecture, and stack choices". Run on 2026-12-02 with Codex 0.173.0, signed in with ChatGPT, in a scratch `CODEX_HOME`, these gave the expected results: - the policy came whole, again after three forced compactions; - 27 skills were listed as `dumbledore:<name>`, without `foundry-upgrade`; - all seven subagents spawned with their briefs; - the guard refused an `apply_patch` in the main checkout; - an implementer subagent's edit adding `echo $2` showed ShellCheck's SC2086; - the session answered the Test command from `AGENTS.local.md`; - changing an installed file's fingerprint brought the warning; - `codex plugin marketplace upgrade` updated a Git marketplace served from a local bare repository, and a second `codex plugin add` updated a local one. On the tip, `tests/verify-agent-config.sh` passed 427 tests: - `build-form.sh` 53, with new tests for the `codex` target; - `publish-form.sh` 12, with new tests for `codex-plugin`. `tests/check-work-folder.sh` passed 46, and ShellCheck, prettier, the static validator, and `git diff --check main` also pass. The new tests fail on `main` at the `codex` target name, or at the target argument of `publish-form.sh`, both of which this branch adds. ## Considerations - Codex counts every file of the plugin in each hook's trust, so after any update the hooks need trusting again in `/hooks`. Until then a session runs without the policy, the guard, and the shell check. `docs/INSTALL.md` says so. - An installed subagent file is a copy that lags the plugin until the operator copies it again; the warning shows only when the content differs. - The `publish` job has not run with the `codex` target on the forge yet; its first push to `main` after the merge creates `codex-plugin`. - The sandbox question from the Claude Code work stays open. https://claude.ai/code/session_012wUN2eKSj9s2vRHJdFPNk3
The target codex builds a Codex marketplace in Codex's own layout, so a
repository with no foundry file gets the policy, skills, and hooks in
Codex, and the subagents as files the operator copies into
~/.codex/agents/. The implementers' files turn plugins on, since Codex
runs a plugin's hooks in a subagent only then, and each file carries a
fingerprint of what the build writes, so the session warns only when
the installed copies differ.

The manifest sits at .codex-plugin/plugin.json: Codex 0.173.0 installs
a plugin with a root Agent Plugins plugin.json but lists none of its
hooks, while it lists all three from .codex-plugin/.
docs(install): describe the Codex plugin
Some checks failed
Maintenance / checks (pull_request) Failing after 3m55s
Maintenance / checks (push) Failing after 4m2s
Maintenance / publish (pull_request) Has been skipped
Maintenance / publish (push) Has been skipped
7d928428fd
claudiomaradonna deleted branch feat/codex-plugin 2026-12-02 21:49:56 +01:00
motoko referenced this pull request from a commit 2026-12-02 22:20:26 +01:00
Sign in to join this conversation.
No description provided.