Skip to content

docs: add optional Codex SessionStart hook setup - #1018

Closed
gustavofondaik wants to merge 27 commits into
obra:devfrom
gustavofondaik:codex-sessionstart-docs-dev
Closed

gustavofondaik wants to merge 27 commits into
obra:devfrom
gustavofondaik:codex-sessionstart-docs-dev

Conversation

@gustavofondaik

Copy link
Copy Markdown

Related issue: #898
This PR implements the optional Codex SessionStart docs/examples proposed there.

What problem are you trying to solve?

Codex already discovers Superpowers skills natively, so the existing docs are correct for basic installation.

However, some users may want a more deterministic first-turn bootstrap that more closely mirrors the existing Superpowers startup flow. I manually validated in WSL that Codex supports SessionStart hooks for startup and resume, and this PR adds a small Codex-specific Unix hook example for Linux/macOS/WSL that delegates the same startup content that Superpowers uses for Claude.

What does this PR change?

Adds an optional Codex documentation section describing how to configure SessionStart hooks, including:

  • the Codex-specific event mapping
  • a note about features.codex_hooks
  • reusable example files in hooks/ for Linux/macOS/WSL
  • an explicit note that Windows native lifecycle hooks are not currently supported

Is this change appropriate for the core library?

I believe yes, because this is not a third-party integration or a project-specific workflow. It is a small optional documentation improvement for an already documented platform: Codex.

What alternatives did you consider?

Leaving the docs as-is. That is fine for baseline usage, but it does not document the optional startup bootstrap path for users who want stricter first-turn behavior.

Does this PR contain multiple unrelated changes?

No.

Existing PRs

  • I have reviewed all open AND closed PRs for duplicates or prior art
  • Related PRs: none found

Environment tested

Harness (e.g. Claude Code, Cursor) Harness version Model Model version/ID
Codex CLI (WSL) 0.117.0 GPT-5.4 gpt-5.4

Evaluation

  • Initial prompt used in validation sessions: Ok, Hi!
  • Eval sessions run after the change: codex "Reply with exactly: OK" with SessionStart enabled
  • Validation performed in WSL: the example SessionStart hook executed successfully, returned valid Codex hook output, and provided additionalContext to the model

Rigor

  • This change was tested adversarially, not just on the happy path
  • I did not modify carefully-tuned content (Red Flags table, rationalizations, "human partner" language) without extensive evals showing the change is an improvement

Human review

  • A human has reviewed the COMPLETE proposed diff before submission

Drew Ritter and others added 27 commits March 23, 2026 17:37
Design for making using-git-worktrees, finishing-a-development-branch,
and subagent-driven-development skills work in the Codex App's sandboxed
worktree environment. Read-only environment detection via git-dir vs
git-common-dir comparison, ~48 lines across 4 files, zero breaking changes.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Fix three Important issues from spec review:
- Clarify Step 1.5 placement relative to existing Steps 2/3
- Re-derive environment state at cleanup time instead of relying on
  earlier skill output
- Acknowledge pre-existing Step 5 cleanup inconsistency

Also: precise step references, exact codex-tools.md content, clearer
Integration section update instructions.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- Add commit SHA + data loss warning to handoff payload (HIGH)
- Add explicit commit step before handoff (HIGH)
- Remove misleading "mark as externally managed" from Path B
- Add executing-plans 1-line edit (was missing)
- Add branch name derivation rules
- Add conditional UI language for non-App environments
- Add sandbox fallback for permission errors
- Add STOP directive after Step 0 reporting

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…spec

Both tests address real risk scenarios:
- #5: cleanup guard bug would delete Codex App's own worktree (data loss)
- #10: Local thread sandbox fallback needs manual Codex App validation

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
8 tasks covering: environment detection in using-git-worktrees,
Step 1.5 + cleanup guard in finishing-a-development-branch,
Integration line updates, codex-tools.md docs, automated tests,
and final verification.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
The subagent review loop (dispatching a fresh agent to review plans/specs)
doubled execution time (~25 min overhead) without measurably improving plan
quality. Regression testing across 5 versions (v3.6.0 through v5.0.4) with
5 trials each showed identical plan sizes, task counts, and quality scores
regardless of whether the review loop ran.

Changes:
- writing-plans: Replace subagent Plan Review Loop with inline Self-Review
  checklist (spec coverage, placeholder scan, type consistency)
- writing-plans: Add explicit "No Placeholders" section listing plan failures
  (TBD, vague descriptions, undefined references, "similar to Task N")
- brainstorming: Replace subagent Spec Review Loop with inline Spec Self-Review
  (placeholder scan, internal consistency, scope check, ambiguity check)
- Both skills now use "look at it with fresh eyes" framing

Testing: 5 trials with the new skill show self-review catches 3-5 real bugs
per run (spawn positions, API mismatches, seed bugs, grid indexing) in ~30s
instead of ~25 min. Remaining defects are comparable to the subagent approach.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Metadata files (.server-info, .events, .server.pid, .server.log,
.server-stopped) were stored in the same directory served over HTTP,
making them accessible via the /files/ route. They now live in a .meta/
subdirectory that is not web-accessible.

Also fixes a stale test assertion ("Waiting for Claude" → "Waiting for
the agent").

Reported-By: 吉田仁
The session directory now contains two peers: content/ (HTML served to
the browser) and state/ (events, server-info, pid, log). Previously
all files shared a single directory, making server state and user
interaction data accessible over the /files/ HTTP route.

Also fixes stale test assertion ("Waiting for Claude" → "Waiting for
the agent").

Reported-By: 吉田仁
ownerAlive() treated EPERM (permission denied) the same as ESRCH
(process not found), causing the server to self-terminate within 60s
whenever the owner process ran as a different user. This affected WSL
(owner is a Windows process), Tailscale SSH, and any cross-user
scenario.

The fix: `return e.code === 'EPERM'` — if we get permission denied,
the process is alive; we just can't signal it.

Tested on Linux via Tailscale SSH with a root-owned grandparent PID:
- Server survives past the 60s lifecycle check (EPERM = alive)
- Server still shuts down when owner genuinely dies (ESRCH = dead)

Fixes #879
Two bugs caused the brainstorm server to self-terminate within 60s:

1. ownerAlive() treated EPERM (permission denied) as "process dead".
   When the owner PID belongs to a different user (Tailscale SSH,
   system daemons), process.kill(pid, 0) throws EPERM — but the
   process IS alive. Fixed: return e.code === 'EPERM'.

2. On WSL, the grandparent PID resolves to a short-lived subprocess
   that exits before the first 60s lifecycle check. The PID is
   genuinely dead (ESRCH), so the EPERM fix alone doesn't help.
   Fixed: validate the owner PID at server startup — if it's already
   dead, it was a bad resolution, so disable monitoring and rely on
   the 30-minute idle timeout.

This also removes the Windows/MSYS2-specific OWNER_PID="" carve-out
from start-server.sh, since the server now handles invalid PIDs
generically at startup regardless of platform.

Tested on Linux (magic-kingdom) via Tailscale SSH:
- Root-owned owner PID (EPERM): server survives ✓
- Dead owner PID at startup (WSL sim): monitoring disabled, survives ✓
- Valid owner that dies: server shuts down within 60s ✓

Fixes #879
…ction

Copilot CLI v1.0.11 reads `additionalContext` from sessionStart hook
output, but the session-start script only emits the Claude Code-specific
nested format. Add COPILOT_CLI env var detection so Copilot CLI gets the
SDK-standard top-level `additionalContext` while Claude Code continues
getting `hookSpecificOutput`.

Based on PR #910 by @culinablaz.
- Add references/copilot-tools.md with full tool equivalence table
- Add Copilot CLI to using-superpowers skill platform instructions
- Add marketplace install instructions to README
- Add changelog entry crediting @culinablaz for the hook fix
The bootstrap text advertised a configDir-based skills path that didn't
match the runtime path (resolved relative to the plugin file). Tests
used yet another hardcoded path and referenced a nonexistent lib/ dir.

- Remove misleading skills path from bootstrap text; the agent should
  use the native skill tool, not read files by path
- Fix test setup to create a consistent layout matching the plugin's
  ../../skills resolution
- Export SUPERPOWERS_SKILLS_DIR from setup.sh so tests use a single
  source of truth
- Add regression test that bootstrap doesn't advertise the old path
- Remove broken cp of nonexistent lib/ directory

Fixes #847
…sage

Move bootstrap injection from experimental.chat.system.transform to
experimental.chat.messages.transform, prepending to the first user
message instead of adding a system message.

This avoids two issues:
- System messages repeated every turn inflate token usage (#750)
- Multiple system messages break Qwen and other models (#894)

Tested on OpenCode 1.3.2 with Claude Sonnet 4.5 — brainstorming skill
fires correctly on "Let's make a React to do list" prompt.
@obra

obra commented Apr 1, 2026

Copy link
Copy Markdown
Owner

I'd very much like to have that codex hook, but until they support some sort of "plug-in root" environment variable, doing it is gonna be too hacky to pull off, I think :/

@gustavofondaik

Copy link
Copy Markdown
Author

I'd very much like to have that codex hook, but until they support some sort of "plug-in root" environment variable, doing it is gonna be too hacky to pull off, I think :/

I took another pass through the Codex hooks docs and plugin code, and I agree with your concern: while Codex seems to have an internal notion of plugin root, I couldn’t find any official way to expose that to hook scripts like CLAUDE_PLUGIN_ROOT.

So without a first-class plugin-root (or equivalent), this would be too hacky. Happy to revisit it later if Codex adds a cleaner way to resolve plugin assets.

Thanks a lot for the review, I really appreciate it — this was actually my first contribution attempt on GitHub.

obra commented Apr 1, 2026

Copy link
Copy Markdown
Owner

Thank you so much for contributing. I'd love to get this figured out.

@gustavofondaik

Copy link
Copy Markdown
Author

Thanks again, I really appreciate it.

I opened a Codex feature request for this exact blocker: openai/codex#16466

If Codex adds a clean way for hook scripts to resolve bundled assets, I’d be happy to revisit this PR.

@obra obra added documentation Improvements or additions to documentation hooks Hook system (SessionStart, Stop, etc.) codex Issues related to OpenAI Codex support labels Apr 27, 2026
@obra

obra commented May 5, 2026

Copy link
Copy Markdown
Owner

I'm gonna close this out for now. We're in contact with the codex team and are waiting on them for hooks for plugins

@obra obra closed this May 5, 2026
@gustavofondaik
gustavofondaik deleted the codex-sessionstart-docs-dev branch May 7, 2026 17:56
@arittr arittr mentioned this pull request May 13, 2026
3 of 5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codex Issues related to OpenAI Codex support documentation Improvements or additions to documentation hooks Hook system (SessionStart, Stop, etc.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants