feat(guard): support Codex CLI and Cursor alongside Claude Code#164
Merged
Conversation
ordo guard only spoke Claude Code's PreToolUse hook protocol. Both other mainstream coding agents now ship an equivalent pre-shell-execution hook (Codex CLI's PreToolUse is protocol-identical to Claude Code's; Cursor's beforeShellExecution uses its own flat event/decision shape), so the policy engine itself was already agent-agnostic — only the wire format at the edges needed adapting. - New Agent enum (claude/codex/cursor, default claude — zero behavior change for existing Claude Code users). - ordo guard hook --agent <agent>: parses each agent's event shape into one canonical HookEvent, so a policy written once behaves identically everywhere it's reachable. Emits each agent's native decision envelope (Claude/Codex share hookSpecificOutput; Cursor's beforeShellExecution schema has no documented 'no opinion' outcome, so its PASS maps to an explicit allow rather than silence). - ordo guard init --agent <a,b,c> (repeatable or comma-separated, default claude): registers each selected agent's hook in its own config file. Claude/Codex share settings.rs's merge logic (their hooks.json shape is structurally identical); Cursor gets a dedicated merge function for its flatter shape. JSON output keeps the original single-object "hook" field (Claude's registration specifically) for backward compatibility, plus a new "hooks" array covering all of them. Verified end-to-end through the compiled binary across all three agents (init writing the right config shape, hook parsing + emitting the right protocol for allow/deny/ask/pass) — not just unit-level. cargo test/ clippy/fmt clean; existing Claude Code tests pass unchanged. Docs: README, npm package README, and the en/zh guard docs page updated — the docs previously stated 'Claude Code' as the scope.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Andero-Wang
approved these changes
Jul 11, 2026
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.
ordo guardonly spoke Claude Code'sPreToolUsehook protocol. Both other mainstream coding agents now ship an equivalent pre-shell-execution hook — Codex CLI'sPreToolUseis protocol-identical to Claude Code's, Cursor'sbeforeShellExecutionuses its own flat shape — so the policy engine itself was already agent-agnostic; only the wire format at the edges needed adapting.What changed
Agentenum (claude/codex/cursor, defaultclaude— zero behavior change for existing Claude Code users, verified: every pre-existing test passes unchanged).ordo guard hook --agent <agent>: parses each agent's event shape into one canonicalHookEvent, so a policy written once behaves identically everywhere it's reachable (Cursor events synthesizetool: "Bash"since it only sees shell). Emits each agent's native decision envelope:hookSpecificOutput(PASS→ silent stdout, agent's own permission flow applies).allow/deny/askbut no "no opinion" outcome, so itsPASSmaps to an explicitallowrather than relying on undocumented empty-stdout behavior.ordo guard init --agent <a,b,c>(repeatable or comma-separated, defaultclaude): registers each selected agent's hook in its own config file —.claude/settings*.json,.codex/hooks.json,.cursor/hooks.json. Claude/Codex sharesettings.rs's existing merge logic (theirhooks.jsonshape is structurally identical, confirmed against both agents' docs); Cursor gets a dedicated merge function for its flatter shape (top-level"version", no nested"hooks"/"type"wrapper). JSON output keeps the original single-object"hook"field (Claude's registration specifically) for backward compatibility, plus a new"hooks"array covering all selected agents.guard.mddocs page — all previously said "Claude Code" as the scope.Verification
cargo test -p ordo-cli— 47 tests, including new unit tests (event parsing/conversion, per-agent decision envelopes, registration idempotency for both new config shapes) and new end-to-end integration tests through the compiled binary (tests/guard_hook.rs): multi-agentinitwrites the right shape per agent and is idempotent across re-runs,hook --agent codex/--agent cursorparse + decide + emit correctly for deny/ask/allow/pass.guard init --agent claude,codex,cursorin a scratch repo, inspected the three resulting config files, ranguard hookthrough each agent's protocol by hand and confirmed the JSON output.cargo clippy -p ordo-cli --all-targetsandcargo fmt --checkclean;cargo check --workspaceclean.Known upstream limitations (documented, not something this PR can work around)
PreToolUsecurrently only fires for Bash (Read/Write/Edit/MCP calls don't trigger it yet upstream).beforeShellExecutiononly ever sees shell commands — no file-edit hook exists, sofile_path-based rules are unreachable there.