codex_skill_sync.py deletes tables that Codex writes inside Pilot's managed region of config.toml (plugin marketplaces vanish every session)
Environment
Pilot Shell v11.0.9, Codex CLI 0.164.0, macOS.
What happens
When the last thing in ~/.codex/config.toml is Pilot's managed block, Codex inserts any table it adds before the trailing # --- end pilot-shell managed env vars --- comment, so the new table lands inside Pilot's marker region. On the next SessionStart, _merge_env_block() in hooks/codex_skill_sync.py removes every line between the markers and re-emits only [shell_environment_policy.set]. The table Codex wrote is deleted.
For us this made codex plugin marketplace add / codex plugin add look flaky for months: the plugin installed, worked for one session, and was gone from config.toml at the next one, leaving the downloaded snapshot behind (marketplace add then fails with "already added from a different source").
Minimal reproduction
Uses only Codex's own command and Pilot's unmodified hook. Run with a scratch CODEX_HOME.
-
config.toml:model = "gpt-5" # --- pilot-shell managed env vars --- [shell_environment_policy.set] PILOT_PLAN_APPROVAL_ENABLED = "true" # --- end pilot-shell managed env vars --- -
codex plugin marketplace add <any local marketplace directory>. The file becomes:# --- pilot-shell managed env vars --- [shell_environment_policy.set] PILOT_PLAN_APPROVAL_ENABLED = "true" [marketplaces.example] source_type = "local" source = "/path/to/marketplace" # --- end pilot-shell managed env vars --- -
uv run --no-project --python python3 python ~/.pilot/hooks/codex_skill_sync.py -
[marketplaces.example]is gone andcodex plugin marketplace listno longer shows it.
Disabling hooks for a session (codex exec --disable hooks) kept the table in our real profile, and making config.toml immutable during a session made exactly one SessionStart hook report a failure.
Cause
_merge_env_block() treats everything between _ENV_MARKER_START and _ENV_MARKER_END as owned by Pilot and drops it, including tables Pilot did not write. Codex appends new tables ahead of the trailing end-marker comment, so the region does not stay confined to Pilot's own table.
Suggested change
- When removing a managed region, keep any table header other than
[shell_environment_policy.set]that falls inside it (re-emit it after the end marker), or - Stop using a trailing comment as the end marker: put the markers around the keys only, so tables Codex appends land after them.
- Independently, avoid rewriting the file when the managed keys are already correct, and re-read just before
os.replacesince Codex edits the same file.
Separate finding, out of scope for this issue: a PreToolUse hook returns suppressOutput, and Codex rejects it.
What I saw. Codex CLI 0.164.0 with QualityLayer 12.3.0 hooks installed under ~/.pilot/hooks. During a Codex session that ran ordinary shell commands, the transcript showed:
Hook failed
└ PreToolUse hook returned unsupported suppressOutput
The commands still ran. The effect is a failed-hook line in the transcript and the loss of whatever that hook returned.
Where the field comes from. pre_tool_use_context in hooks/_lib/util.py builds this JSON:
{
"continue": true,
"suppressOutput": true,
"hookSpecificOutput": {
"hookEventName": "PreToolUse",
"additionalContext": "..."
}
}
Two hooks use that helper: tool_redirect.py, which Codex's hooks.json registers for Bash PreToolUse with CLAUDE_PROJECT_PLATFORM=codex, and plan_mode_tracker.py. tool_redirect.py calls it for its nudges (the shell file-edit nudge, the native-file-tools nudge, the search nudge and the web-tool nudges).
What I did not establish. I do not know which hook produced the failure in the live session. Running tool_redirect.py by hand with a Codex-style payload printed nothing for the commands I tried, so I could not reproduce it outside the session, and Codex's local logs do not record the failure text. The helper is the only code in the install that writes this field into PreToolUse output, which makes it the likely source, not a confirmed one.
Suggested direction, for you to judge. When the platform is Codex, omit suppressOutput from PreToolUse output, or check the Codex hooks schema for the fields PreToolUse accepts.
I added this as a comment because I found it in the same session as this issue. I can split it into its own issue if you prefer.
Thanks for reporting both problems. They are fixed in Pilot Shell 11.0.11.
If your older updater points to QualityLayer, install the pinned maintenance update:
curl -fsSL https://raw.githubusercontent.com/maxritter/qualitylayer/v11.0.11/install.sh | VERSION=11.0.11 bash
The update preserves existing Codex configuration entries. Entries already removed by an older version need to be added again.