Guidance for agents developing rtk-codex-hook.
This repo is a small Rust CLI for Codex PreToolUse hooks on Windows.
src/main.rs: CLI entry point, stdin reading,--explain, and--version.src/hook.rs: Codex hook JSON parsing, fail-open behavior, and deny JSON output.src/rewrite.rs: conservative command tokenization and RTK rewrite suggestions.tests/pretool.rs: integration fixture that feeds Codex-style JSON to the binary.README.md: user-facing overview and install prompt.docs/DEVELOPMENT.md: build, release, behavior, and debugging docs.
- The hook must fail open. Malformed JSON, missing fields, unsupported commands,
parser uncertainty, and internal errors must exit
0with no output. - Emit JSON only when denying a command with a specific RTK suggestion.
- Keep deny JSON compact and shaped as:
{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"Use RTK-optimized command instead: <suggestion>"}}- Do not write to stderr during normal hook execution.
- Do not rewrite destructive or mutating PowerShell commands. When in doubt, return no suggestion.
- Keep rewrite behavior generic. Do not add repo-specific or language-specific policy unless the user explicitly asks and the behavior is designed as a general rule with tests.
- Preserve pasteable Windows/PowerShell suggestions, especially quoting around
$env:...setup inpwsh -Commandsuggestions.
- Do not work directly on
mainunless the user explicitly asks. Use a branch or a linked worktree for changes. - For install requests, point Codex at
CODEX_INSTALL.md; humans should only need the short prompt inREADME.md. - Keep edits small and tied to observable hook behavior.
- Prefer deterministic in-process rewrite tests. If using the external
rtk rewritepath, keep it as a separate integration concern so tests do not depend on a locally installed RTK binary. - Add or update
tests/pretool.rsfor every behavior change. Test both:- the command that should produce a deny suggestion
- nearby commands that should fail open with no output
- Keep
docs/DEVELOPMENT.mdbehavior descriptions in sync with tested behavior. - Commit completed work; do not leave intended repo changes unstaged or uncommitted.
Run these before committing code changes:
cargo fmt --check
cargo clippy --all-targets --all-features -- -D warnings
cargo test
cargo build --releaseFor docs-only changes, run at least:
cargo testUse manual probes for tricky rewrite behavior:
cargo run -- --explain "git status --short"
cargo run -- --explain "Get-Content -LiteralPath input.txt | Out-File output.txt"Get-Contentredirects should preserve requested read windows with--max-linesor--tail-lines.Select-Stringredirects should preserve-Context Nas-C N.Get-ChildItemfile discovery should preferrtk rg --files.- Raw
rgsuggestions should quote patterns that contain alternation or other PowerShell-sensitive characters. - Existing good RTK commands should be left alone.
- A correct no-op is better than a clever but risky rewrite.