Using planning-with-files with OpenAI Codex.
Codex discovers repository skills from .agents/skills/ and personal skills from ~/.agents/skills/. It discovers standalone hooks from .codex/hooks.json or ~/.codex/hooks.json.
This integration includes both:
.agents/skills/planning-with-files/for the canonical standalone skill.codex/hooks.jsonplus.codex/hooks/for lifecycle automation.codex-plugin/plugin.jsonplushooks/codex-hooks.jsonfor a cache-safe plugin package
The hook behavior reuses the same shell scripts as the Cursor integration, with a thin Codex adapter layer for the differences in hook protocol. The three shell-backed context events run through run_sh.py on every platform so their output is serialized as event-appropriate JSON. On Windows the adapter also resolves Git Bash automatically (see Windows Support).
Hooks are enabled by default in current Codex. A user or administrator can explicitly disable them with [features] hooks = false. New or changed non-managed hooks must still be reviewed and trusted through /hooks.
Share the canonical skill and standalone hooks with your team by committing .agents/skills/planning-with-files/, the team-safe planning-with-files registrations in .codex/hooks.json, and the planning-with-files hook scripts to your repository:
# In your project repository
git clone https://github.com/OthmanAdi/planning-with-files.git /tmp/planning-with-files
# Copy the canonical skill
mkdir -p .agents/skills
cp -r /tmp/planning-with-files/.agents/skills/planning-with-files .agents/skills/
# Copy the hook scripts into .codex/hooks/
mkdir -p .codex/hooks
cp -r /tmp/planning-with-files/.codex/hooks/. .codex/hooks/
# Copy hooks.json, or keep an existing one and merge into it
if [ -e .codex/hooks.json ]; then
echo "Kept the existing .codex/hooks.json. Merge the planning-with-files entries into it."
else
cp /tmp/planning-with-files/.codex/hooks.json .codex/hooks.json
fiThe scripts land directly in .codex/hooks/, where .codex/hooks.json points,
whether or not the directory already exists. Do not use
cp -r /tmp/planning-with-files/.codex/hooks .codex/hooks. When .codex/hooks
already exists, cp copies into it and creates .codex/hooks/hooks/, where the
registered commands do not look. Other scripts in .codex/hooks/ stay as they
are, and running the commands again updates the planning-with-files scripts in
place. A script of yours with the same name as one of ours (for example
stop.py) is overwritten, so rename it first.
The commands never overwrite an existing hooks.json. If they printed the
"Kept the existing" message, merge the entries now, as described in
Existing hooks.json. Before committing, inspect the
whole change. The existing hook file and directory may contain personal
registrations or scripts; preserve those locally, but do not include them in a
team commit. Keep credentials, tokens, and other secrets out of the repository.
Only commit a hooks.json that contains registrations intended for everyone on
the team. If your merged file also has local-only registrations, move those to
your personal ~/.codex/hooks.json and leave them out of the team version.
Stage the planning-with-files scripts by name, not the whole hooks directory, so unrelated local scripts are not added:
# Review all changes before staging
git status --short
git diff -- .codex/hooks.json .codex/hooks
# Stage the skill, the team-safe merged registrations, and shipped scripts
git add .agents/skills/planning-with-files .codex/hooks.json \
.codex/hooks/context_frame.py .codex/hooks/codex_hook_adapter.py \
.codex/hooks/permission_request.py .codex/hooks/plugin_dispatch.py \
.codex/hooks/post_tool_use.py .codex/hooks/pre_tool_use.py \
.codex/hooks/pwf-hook.cmd .codex/hooks/resolve-plan-dir.sh \
.codex/hooks/run_sh.py .codex/hooks/session-start.sh \
.codex/hooks/stop.py .codex/hooks/stop.sh \
.codex/hooks/user-prompt-submit.sh .codex/hooks/pre-compact.sh \
.codex/hooks/pre-tool-use.sh .codex/hooks/post-tool-use.sh
# Inspect exactly what will be committed; unstage anything local or private
git diff --cached -- .agents/skills/planning-with-files .codex/hooks.json .codex/hooks
git status --short
# Commit to share with team
git commit -m "Add planning-with-files skill for Codex"
git push
# Clean up
rm -rf /tmp/planning-with-filesInstall just for yourself:
# Clone the repo
git clone https://github.com/OthmanAdi/planning-with-files.git /tmp/planning-with-files
# Copy the canonical skill
mkdir -p ~/.agents/skills
cp -r /tmp/planning-with-files/.agents/skills/planning-with-files ~/.agents/skills/
# Copy the hook scripts into ~/.codex/hooks/
mkdir -p ~/.codex/hooks
cp -r /tmp/planning-with-files/.codex/hooks/* ~/.codex/hooks/
# Copy hooks.json, or keep an existing one and merge into it
if [ -e ~/.codex/hooks.json ]; then
echo "Kept the existing ~/.codex/hooks.json. Merge the planning-with-files entries into it."
else
cp /tmp/planning-with-files/.codex/hooks.json ~/.codex/hooks.json
fiIf you already have a ~/.codex/hooks.json, the commands keep it. Merge the
planning-with-files entries into it as described in
Existing hooks.json, then clean up:
rm -rf /tmp/planning-with-filesIf .codex/hooks.json (or ~/.codex/hooks.json) already exists, keep it and
add the planning-with-files registrations to it:
/tmp/planning-with-files/.codex/hooks.jsonhas one entry under each of seven events:SessionStart,UserPromptSubmit,PreToolUse,PermissionRequest,PostToolUse,PreCompact, andStop. Append each entry, unchanged, to the array with the same event name under"hooks"in your file. Create the array if your file has no such event.- Leave your existing entries and other events as they are.
For example, a project that already registered its own SessionStart hook ends
up with both entries in that array, followed by the other six events copied
from /tmp/planning-with-files/.codex/hooks.json:
{
"hooks": {
"SessionStart": [
{
"hooks": [
{ "type": "command", "command": "echo KEEP_EXISTING_HOOK" }
]
},
{
"matcher": "startup|resume|clear|compact",
"hooks": [
{
"type": "command",
"command": "python3 .codex/hooks/run_sh.py session-start.sh 2>/dev/null || python3 \"$HOME/.codex/hooks/run_sh.py\" session-start.sh 2>/dev/null || true",
"commandWindows": "cmd /c .codex\\hooks\\pwf-hook.cmd run_sh.py session-start.sh",
"statusMessage": "Loading planning context"
}
]
}
],
"UserPromptSubmit": [ ... ],
"PreToolUse": [ ... ],
"PermissionRequest": [ ... ],
"PostToolUse": [ ... ],
"PreCompact": [ ... ],
"Stop": [ ... ]
}
}If the seven entries are already there from an earlier install, replace them
with the current entries from /tmp/planning-with-files/.codex/hooks.json so
that changed command definitions take effect, then review them with /hooks.
The repository also ships a Codex plugin package. Its manifest selects hooks/codex-hooks.json, so cached plugin commands resolve only through ${PLUGIN_ROOT}. Plugin mode and standalone .codex/hooks.json mode are alternatives. Do not enable both for the same installation because Codex runs every matching hook from every active source.
codex --version
ls -la ~/.agents/skills/planning-with-files/SKILL.md
ls -la ~/.codex/hooks.json ~/.codex/hooks/Use /hooks to review the source, matcher, and resolved command for each loaded hook.
Codex reads hooks from:
.codex/hooks.jsonin your project root~/.codex/hooks.jsonfor your global install
This integration includes the Codex lifecycle hooks used by the adapter:
| Hook | What It Does |
|---|---|
| SessionStart | Reads project planning state and injects selected active-plan context; it does not inspect Codex session stores |
| UserPromptSubmit | Re-injects plan and recent progress on every user message |
| PreToolUse | Refreshes plan context before Bash and direct edit paths |
| PermissionRequest | Adds bounded plan context when Codex is about to request approval |
| PostToolUse | Reminds the agent to update progress.md after Bash or direct edits |
| PreCompact | Reminds the agent to flush progress.md and task_plan.md before compaction |
| Stop | Continues once when every opt-in gated-mode condition passes; otherwise emits advisory status and allows the stop |
Local Codex session history is not part of the automatic hook path. Explicit session-catchup.py --metadata <project> reads same-project local session records and emits aggregate counts only. Use --replay for bounded nonce-framed excerpts. The catchup path contains no network request or upload operation.
Once activated, the skill creates and maintains:
| File | Purpose | Location |
|---|---|---|
task_plan.md |
Phases, progress, decisions | Your project root |
findings.md |
Research, discoveries | Your project root |
progress.md |
Session log, test results | Your project root |
A one-shot session that shares a working directory with an active plan gets the
plan context injected even though it never opted in: a CI review bot, a
read-only research agent, or a nested orchestrator can end up "reconciling the
plan" instead of doing its own job, and may mutate task_plan.md and
progress.md that belong to another session (issue #195).
Set PLANNING_DISABLED=1 to disable all planning-with-files hooks for that
invocation only:
PLANNING_DISABLED=1 codex exec -o review.md '$code-review review this branch'
PLANNING_DISABLED=1 codex exec -C <repo> -s read-only '<research prompt>'With the variable set, every hook (SessionStart, UserPromptSubmit, PreToolUse,
PermissionRequest, PostToolUse, PreCompact, Stop) exits before reading the plan: no context
injection, no follow-up messages, no plan-file writes. PreToolUse exits silently
without adding planning context or a permission decision; Codex's normal permission
handling remains unchanged. Interactive sessions in
the same directory are unaffected. The same variable is honored by the
canonical Claude Code dispatchers (inject-plan.sh, gate-stop.sh,
check-complete.sh/.ps1), so it works for CI automation on any platform
whose hooks route through those scripts.
With workspace installation (.codex/ committed to your repo):
- Everyone on the team gets the same skill and hooks
- The Codex setup is version controlled with the project
- Updates ship through normal git review
With personal installation (~/.codex/):
- You can use the skill across all projects
- You keep your setup even if you change repositories
- Existing global hooks may need manual merging
- Check that neither user nor managed configuration explicitly sets
[features] hooks = false. - Verify
.codex/hooks.json,~/.codex/hooks.json, or an enabled plugin descriptor exists. - Restart Codex after adding or changing hooks.
- Review and trust new or changed definitions through
/hooks.
That is fine, but do not overwrite your existing ~/.codex/hooks.json. Merge the planning-with-files entries instead.
Avoid installing the same planning-with-files hooks in both places at once:
- workspace
.codex/hooks.json - global
~/.codex/hooks.json - the planning-with-files Codex plugin
If you enable both, Codex may run both sets of hooks and duplicate the reminders.
The POSIX hook commands require python3 and sh on PATH. The other Codex Python hooks already use python3, so a working Python 3 installation is required for the full integration.
Upgrading from v3.10.0 or earlier changes three command definitions in .codex/hooks.json. Review and trust the updated definitions with /hooks before expecting SessionStart, UserPromptSubmit, or PreCompact to run.
Hooks run on Windows. Codex reads a per-hook commandWindows override from .codex/hooks.json on Windows and the POSIX command everywhere else. The three shell-backed context events use run_sh.py on every platform so Codex receives event-appropriate JSON.
On Windows every hook routes through .codex\hooks\pwf-hook.cmd, which finds a real Python (py -3, falling back to python) and never the Microsoft Store python3 alias. Plugin installs use a quote-free PowerShell entry command before that launcher so cache paths containing spaces work with Codex's Windows hook runner. The four Python hooks run their .py entry point directly. The three shell hooks (SessionStart, UserPromptSubmit, PreCompact) route through run_sh.py, which locates the Git for Windows sh.exe and runs the same shell scripts the macOS/Linux hooks use.
Requirements on Windows:
- Hooks must not be explicitly disabled in user or managed configuration.
- Python reachable through the
pylauncher (installed by the python.org installer) or on PATH aspython. If you only havepython, the launcher falls back to it automatically. The Microsoft Storepython3alias is skipped on purpose. - Git for Windows installed, for the three shell-backed hooks. The launcher finds
sh.exeeven when Git'susr\binis not on your PATH, which is the default install layout. Without Git for Windows those three hooks stay silent and the four Python hooks still work.
Use the workspace install (Method 1) on Windows: the commandWindows entries use relative .codex\... paths resolved against your project directory. A global ~/.codex install needs absolute paths in commandWindows.
- GitHub Issues: https://github.com/OthmanAdi/planning-with-files/issues
- OpenAI Codex Hooks Docs: https://developers.openai.com/codex/hooks
- OpenAI Codex Skills Docs: https://developers.openai.com/codex/skills
As of v3.17.1, a project with more than one live named plan requires PLAN_ID for each Codex session, whether or not .planning/sessions/ exists. Set the pin in the environment that launches the host. Exporting it inside a tool subprocess cannot change an already-running host. A shared .planning/.active_plan pointer cannot select a plan for that session.
When no pin is available, UserPromptSubmit explains the ambiguity and injects no plan. Per-tool and PreCompact hooks remain quiet, and Stop allows the session to end without evaluating a guessed plan. Explicit pins, single named plans and legacy root plans remain supported.