ContextRail Code Review Agent
Run standards-aware PR reviews with @contextrail/code-review-agent and output machine-readable artifacts for CI.
Official references
Use these as your source of truth during implementation.
Install and run
Start with npx, then move to project-level installation if needed.
npx -y @contextrail/code-review-agent review --helpnpm i -D @contextrail/code-review-agent
npx code-review-agent review --helpRequired configuration
Use environment variables for sensitive settings. Avoid passing secrets as CLI flags.
CONTEXTRAIL_MCP_SERVER_URLCONTEXTRAIL_MCP_JWT_TOKENOPENROUTER_API_KEY
Review a PR diff
Run against base/head SHAs and emit machine-readable output for automation.
git fetch origin
BASE_SHA="$(git merge-base origin/main HEAD)"
HEAD_SHA="$(git rev-parse HEAD)"
npx -y @contextrail/code-review-agent review \
--repo . \
--from "$BASE_SHA" \
--to "$HEAD_SHA" \
--output ./.reviewInput modes
Choose diff-based review for PRs or file-based review for local iteration.
npx -y @contextrail/code-review-agent review \
--repo . \
--files "src/a.ts,src/b.ts" \
--output ./.reviewnpx -y @contextrail/code-review-agent review \
--repo . \
--file src/a.ts \
--file src/b.ts \
--output ./.reviewCLI flags developers use most
These map directly to the package CLI parser and help output.
--repoRepository path to review.
--from / --toCommit range for PR or branch diff review.
--filesComma-separated file list for targeted review.
--file (repeatable)Repeat for explicit file paths when scripting.
--outputOutput directory for result artifacts (defaults to ./review).
--domainsScope review domains (for example: security,architecture).
--pr-descriptionExtra PR context to improve reviewer grounding.
--mcp-server-urlOverride MCP endpoint without changing environment config.
--orchestrator-model / --reviewer-model / --critic-modelModel overrides per role for cost/quality tuning.
--max-steps / --max-iterations / --aggregation-max-stepsControl LLM pass limits and convergence behavior.
--max-tokens-per-file / --context-linesControl surrounding-context budget per changed file.
--log-leveldebug|info|warn|error|silent for local troubleshooting and CI signal.
CI implementation pattern
Use exit code + artifacts to gate merges in automation.
# 1) Run review
npx -y @contextrail/code-review-agent review \
--repo . \
--from "$BASE_SHA" \
--to "$HEAD_SHA" \
--domains "security,architecture" \
--output ./.review
# 2) Parse artifacts / upload result.json
# 3) Fail workflow on exit code 1.review/result.json.review/orchestrator/*.review/reviewers/*.review/token-budget.json- Exit
0= approve, exit1= request changes.
- Keep credentials in environment variables, not CLI flags, to avoid shell history leaks.
- Treat
CONTEXTRAIL_MCP_JWT_TOKENandOPENROUTER_API_KEYas secrets.