Repository navigation
Description
Summary
In Codex Desktop using the Agent Skills / skill-only install route (~/.codex/skills/planning-with-files/SKILL.md), the inline lifecycle hooks can inject an unrelated task's active plan when multiple Codex threads share the same top-level cwd.
This is not plan-file content corruption. Two separate plans remain correct, but the shared .planning/.active_plan selector chooses the wrong plan and re-injects it on every prompt/tool call. Because the injected plan arrives as high-priority context, the agent can abandon the user's current task and start working on an unrelated one.
We reproduced this on planning-with-files v3.7.0. I also checked current master/v3.8.2: the inline skills/planning-with-files/SKILL.md hook commands still resolve only by PLAN_ID -> cwd .planning/.active_plan -> newest plan and do not appear to apply the Codex session-attachment guard.
Impact
In the observed incident, the user was discussing a package-switching implementation in a nested project. A different root-level plan described an unrelated bulk production migration. The wrong plan was injected repeatedly, and the agent began investigating the unrelated migration.
Independent production-safety checks prevented writes, but this failure mode is high risk: a stale or unrelated plan can redirect an active coding/operations thread without an explicit user task switch.
Reproduction
- Install planning-with-files via the Agent Skills / skill-only route so hooks come from
SKILL.md. - Start Codex Desktop with a shared cwd such as
/workspace. - Create Plan A under:
/workspace/.planning/plan-a/task_plan.md/workspace/.planning/.active_plancontainsplan-a
- Create an unrelated Plan B in a nested project:
/workspace/project/.planning/plan-b/task_plan.md/workspace/project/.planning/.active_plancontainsplan-b
- In a Codex thread, discuss and work on Plan B. Tool calls may explicitly use
workdir=/workspace/project. - Invoke planning-with-files or make tool calls covered by its hooks.
Actual behavior
The hook resolves against the Codex thread's shared cwd (/workspace), selects Plan A, and injects Plan A before prompts/tool calls. The nested project's explicitly active Plan B is ignored.
The injection repeats, so a correction from the user competes with the wrong plan again on the next hook event.
Expected behavior
A plan should be bound to the current Codex thread/session or to an explicit project root. An unrelated .active_plan in a shared parent cwd must never silently win.
If the hook cannot unambiguously identify the current thread's plan, it should fail closed (no injection) and emit a warning rather than auto-selecting the newest/shared plan.
Relation to existing issues
- Codex hooks can leak active plan context across sessions in the same cwd #146 fixed Codex cross-session leakage for the legacy
.codex/hookspath using.planning/sessions/<session_id>.attached. - Parallel multi-task workflow feedback on v2.0.0+ hooks #148 added isolated plan directories and the active-plan pointer.
- Stop-hook
decision: block+ cwd attachment still hijack unrelated one-shotcodex execsessions (post-#178, v2.41.0) #195 addedPLANNING_DISABLED=1for unrelated one-shot sessions.
This appears to be a coverage gap: the Agent Skills inline hooks in SKILL.md do not use the session-attachment mechanism that exists in .codex/hooks. PLANNING_DISABLED=1 is not a sufficient workaround here because the affected thread genuinely needs planning-with-files; it just needs the correct plan.
Suggested fixes
- Apply the Codex session-attachment guard to the Agent Skills inline hook route.
- Bind a thread to an absolute plan root, not only a cwd-relative slug.
- Do not fall back to "newest plan" when multiple plans or nested project roots are present.
- Detect parent-cwd vs nested-project active-plan conflicts and inject nothing with a clear warning.
- Add an integration test with two Codex threads sharing a parent cwd but using different nested project plans.
Environment
- Codex Desktop / Codex app
- Linux
- planning-with-files local version: v3.7.0
- upstream master/latest release checked: v3.8.2
- Agent Skills / skill-only install route
Activity
OthmanAdi commentedon Aug 1, 2026
@webwww123 Confirmed on master at b04ffd9 (v3.8.2). Your reading of the resolution chain is correct, and reproducing it turned up two further failures on that install route that are not in your report.
Reproduction
Your tree, built verbatim:
/workspace/.planning/plan-aholding an unrelated bulk migration plan with.active_plannaming it,/workspace/project/.planning/plan-bholding the real task with its own.active_plan, hooks fired with the thread cwd at/workspace.inject-plan.sh, cwd/workspaceinject-plan.sh, cwd/workspace/project.codexSKILL.md inline UserPromptSubmit, cwd/workspace.codexSKILL.md inline PreToolUse, cwd/workspacePLANNING_DISABLED=1, canonicalPLANNING_DISABLED=1,.codexSKILL.md inline.codex/hooks/user-prompt-submit.sh, unattached sessioninject-plan.sh, unattached session.codexSKILL.md inline, unattached sessionPLAN_ID=plan-bset from/workspaceRoot cause
Resolution is cwd relative and has no notion of a thread.
scripts/inject-plan.sh:141-161tries$PLAN_IDagainst.planning/$PLAN_ID, then.planning/.active_plan, then the newest.planning/*/by mtime, then a roottask_plan.md. Every one of those reads is relative to the process cwd. When the Codex thread's cwd is the shared parent, the parent's pointer is the only pointer the hook can see, and the nested project's.active_planis never consulted. Nothing in that path is aware that the work is happening one directory down.The session attachment guard from #146 exists in exactly two places:
.codex/hooks/codex_hook_adapter.py:42-56with its shell twin at.codex/hooks/user-prompt-submit.sh:16-21, and the Pi extension atplan.ts:247-252. No SKILL.md route references.planning/sessionsanywhere, which is the coverage gap you identified.Two things beyond your report:
PLANNING_DISABLED=1does nothing on that route. The opt-out lives atscripts/inject-plan.sh:26, and only the canonical and.agentsSKILL.md files dispatch to that script. The other eleven hook bearing SKILL.md variants,.codexincluded, still carry the pre v3 hook body inlined in the YAML scalar (.codex/skills/planning-with-files/SKILL.md:10). That body predates the dispatcher refactor, so besides missing the opt-out it also lacks the symlink containment guard and still keys its SHA cache under${TMPDIR:-/tmp}/pwf-sha, the world writable location that moved to$XDG_CACHE_HOMEfor security in v3.0.0. So the workaround you correctly judged insufficient is in fact inoperative on the exact route you installed.There is currently no way to point the thread at the right plan.
PLAN_IDis a cwd relative slug, so from/workspaceit can only ever name/workspace/.planning/<id>. Plan B lives under/workspace/project/.planning, and no environment variable in the codebase reaches it.What lands next
.planning/sessionsdirectory present, behavior is unchanged, so existing single session setups are untouched./workspace/projectregardless of where its cwd sits.Your suggestion list matched the actual defect closely enough that it shaped the fix order. Reproduction harness is running against the tree from your reproduction section.
fix: resolve the plan against an explicit root and refuse ambiguous s…
fix: extend the shared-cwd guards to the Codex and Cursor hook routes
fix: dispatch every hook-bearing SKILL.md variant to the versioned sc…
OthmanAdi commentedon Aug 1, 2026
@webwww123 Shipped in v3.9.0.
What changed
An absolute plan-root binding.
PWF_PLAN_ROOTtakes a path rather than a slug, which is what your suggestion 2 asked for and whatPLAN_IDstructurally could not do. From/workspace,PWF_PLAN_ROOT=/workspace/projectnow resolves that project's plan and nothing else. A pin that does not resolve stops injection and says so, rather than falling back to the plan the caller was escaping.Ambiguity fails closed. When the plan was picked by the shared
.active_planpointer, by the newest by mtime fallback, or from a legacy roottask_plan.md, and a project directly below the root carries its own live plan, nothing is injected:Naming the plan explicitly skips the check, so a deliberate parent-level plan still works. A nested pointer that is empty or names a deleted directory does not count as competing, otherwise an abandoned subproject would kill injection at the root forever.
The eleven stale variants moved onto the shared script. That is where the
PLANNING_DISABLEDregression came from, and the reason it was inoperative on your route. Those bodies also predated the symlink containment guard and still cached under the world writable/tmppath. A test now fails the build if a hook bearing SKILL.md drifts back to an inlined body.The
.codex/hooks.jsonroute got the same treatment. Verifying your report surfaced that the two Codex integrations are separate implementations, and OpenAI's hook documentation only describes thehooks.jsonone. Fixing your route alone would have left the same bug live for anyone using that path, so both now share the semantics.One limitation, stated plainly
Suggestion 1 is delivered in mechanism but is weaker than it sounds. The session attachment guard now runs on the SKILL.md route, matching the Codex adapter. But nothing on that route supplies a per thread
PWF_SESSION_ID, so on hosts that do not set it every session is unattached by construction and the guard can only refuse, never bind. It buys parity and a diagnostic, not thread identity. The work that actually fixes your incident is the ambiguity refusal plus the root pin.Related: an early build of this made that guard exit silently. On a host that never sets the variable, a
.planning/sessions/directory left behind by earlier Codex use would have killed injection permanently with no symptom, and.planning/is gitignored so the state is invisible. It now prints one line per turn naming both ways out. Caught by an adversarial pass before release, not in the field.Verification
Your reproduction tree is in the suite, including a two thread case: two session identities against one shared parent cwd with distinct nested plans, asserted together rather than as two separate tests. Suite went from 311 to 411 tests.
You are in CONTRIBUTORS.md. The fix order followed your suggestion list because it matched the actual defect closely, including the part about not falling back to the newest plan.
release: v3.9.0 (plan resolution binds to a root, refusals are never …
webwww123 commentedon Aug 2, 2026
@OthmanAdi Thanks again — I reinstalled v3.9.0 and confirmed that the new ambiguity refusal works on my setup.
While checking the remaining
PWF_SESSION_IDlimitation, I found that Codex already provides the required identity on the affected SKILL.md hook route; the current dispatcher simply discards it.Codex's documented command-hook contract sends a JSON object on stdin for every hook, including
session_id,cwd, andhook_event_name: Hooks / common input fields. The open-source hook runner writes that JSON to the command's stdin, and the hook runtime populatessession_idfrom the Codex session: command_runner.rs, hook_runtime.rs.The existing
.codex/hooks/codex_hook_adapter.pyalready callsload_payload()andsession_id_from_payload(), but the.codex/skills/planning-with-files/SKILL.mdhook scalars invokeinject-plan.shdirectly without consuming stdin. So the immediate Codex-specific fix should not require a host change: route the Skill hooks through a small dispatcher that parses stdin and passessession_idasPWF_SESSION_ID(and uses payloadcwdrather than process-cwd guessing).There is a second limitation beyond making the current
.attachedguard functional:.planning/sessions/<session_id>.attachedis only a boolean. It does not say which plan belongs to the session. Therefore two Codex chats in the exact same repo/cwd can both be "attached" but still follow the same shared.active_plan.I think the complete Codex-native shape is:
plan_rootandplan_id, keyed by hooksession_id. Put the index somewhere independent of cwd (for example plugin data when packaged as a Codex plugin, otherwise user state underCODEX_HOME). Hash the session id for the filename and keep the record as validated JSON rather than sourcing shell text.PWF_PLAN_ROOT/PLAN_IDoverride, session binding, then the existing legacy pointer/newest fallback. A missing, broken, or escaping binding must fail closed.init-sessionandset-active-planatomically create/update the binding for the current Codex task. Codex also injects the concreteCODEX_THREAD_IDinto shell tool processes even under restrictive environment inheritance (exec_env.rs), so that can be used as an initialization aid; hook-stdinsession_idremains the documented lifecycle interface.I prototyped this locally against the v3.9.0
inject-plan.sh: Session A and Session B used the same cwd and same project root, but their binding records selected Plan A and Plan B respectively; an unbound Session C injected nothing. All three behaved as expected.One semantic detail: Codex documents
session_idas the identity shared by a root thread and its descendants. That is useful for subagents inheriting the parent plan. If forked chats must be independently re-bindable, the integration can additionally use the concrete thread id or requestthread_idin the common hook payload. Independent top-level chats—the failure mode here—already have distinct session ids.fix: warn when a parallel session overwrites plan progress (#217)
fix: give the language variants the full script surface (#130)