feat(context-guard): support Codex Stop/SubagentStop hooks (2.1.0) - #44
Merged
Merged
Conversation
The Stop guard was inert on Codex: it only understood Claude transcript records. Host detection now peeks the transcript's first JSONL record (type == "session_meta" -> Codex reader, anything else -> the pre-existing Claude path, byte-identical) and dispatches to two new sibling modules, transcript_codex.py (Codex line predicates) and host_detect.py, via a third, usage_reader.py, which extracts the two transcript reads' I/O out of stop-context-guard.py so that file shrinks instead of growing past its 500-line budget. Every fact this integration relies on -- the Stop/SubagentStop payload schema, the block/reason output contract, token semantics (cached_input_ tokens is a subset, not additive; turn/thread_token_usage are cumulative cost counters, not context size), the activity-gate predicate, and the gpt-6-astra context window -- is cited at its primary source (the codex binary's own embedded JSON Schemas, extracted via strings; a real ~/.codex/sessions/**/*.jsonl rollout) in plugins/context-guard/README.md's new "Codex support" table, not assumed from documentation. Verified: existing 84+ Claude-path tests unchanged and green; the installed hook (via a temp CODEX_HOME marketplace/plugin install) fires a decision: block payload against a Codex-shaped Stop input; codex exec itself does not invoke the hook lifecycle (empirically confirmed, documented) so the plugin is tested via direct subprocess invocation, the same shape codex uses. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The context guard now supports Codex sessions. Stop hooks read current context occupancy from Codex rollouts and ask the parent agent to persist the checkpoint. SubagentStop reads each child transcript and reports cumulative billed tokens without counting cached input twice. Codex dollar cost remains unavailable until a verified tariff is supplied.
The bundled thresholds include Astra at 180K WARN / 220K hard. Existing unchanged bundled tables receive that row; custom model rows and defaults remain authoritative. Codex installation instructions include hook trust, which is required for execution.
Validation on codex-cli 0.157.1:
The README documents primary evidence and native reproduction steps. No private transcripts are included.