CM-62984: Add Codex CLI support to ai-guardrails#436
Open
MaorDavidzon wants to merge 2 commits intomainfrom
Open
CM-62984: Add Codex CLI support to ai-guardrails#436MaorDavidzon wants to merge 2 commits intomainfrom
MaorDavidzon wants to merge 2 commits intomainfrom
Conversation
Extend ai-guardrails hooks to cover OpenAI Codex CLI alongside Cursor and Claude Code. Installs ~/.codex/hooks.json for UserPromptSubmit, SessionStart, and PreToolUse:Bash events, and merges `[features] codex_hooks = true` into ~/.codex/config.toml while preserving existing keys. Adds a new canonical CommandExec event for Bash command scanning since Codex's PreToolUse only intercepts Bash today. CodexResponseBuilder reuses the Claude Code response shapes (Codex accepts them verbatim). Adds tomli-w (and tomli on py<3.11) as direct deps to manage the Codex TOML config safely. Co-Authored-By: Claude Opus 4.7 (1M context) <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.
Summary
cycode ai-guardrailsto support OpenAI Codex CLI alongside Cursor and Claude Code: installs~/.codex/hooks.jsonforUserPromptSubmit,SessionStart, andPreToolUse:Bash; auto-enables[features] codex_hooks = truein~/.codex/config.tomlwhile preserving existing keys.CommandExecevent +handle_before_command_exechandler to scan shell commands the agent is about to run for secrets — closest Codex equivalent to theFileRead/McpExecutionevents (Codex'sPreToolUsecurrently only intercepts Bash).codex_config.pysafely merges the feature flag viatomllib/tomli+tomli-w;CodexResponseBuilderreuses Claude Code response shapes verbatim (Codex accepts them).Scope note
Codex hooks intercept
UserPromptSubmitandPreToolUse:Bashonly — not MCP calls or file reads. SoFileReadandMcpExecutioncanonical events cannot be wired for Codex today. This MR ships what's possible; coverage can expand as Codex extends its hook surface.New direct deps
tomli-w(py3.9+) — TOML writer (stdlib has only a reader)tomli(py<3.11 only) — backport of stdlibtomllibTest plan
poetry run pytest tests/cli/commands/ai_guardrails/ -v— 150 passing (23 new)poetry run pytest tests/— 713 passingruff check+ruff formatclean on all touched filesscan --ide codexis skipped ({}returned)codex exec— hook fires and Codex honors the response🤖 Generated with Claude Code