@mesrai/cli
v0.4.23
Published
Mesrai CLI - AI-powered code review from your terminal
Readme
yarn global add @mesrai/cliQuick Start
# 1. Install
yarn global add @mesrai/cli
# 2. Authenticate (or skip for trial mode — no account needed)
mesrai auth login
# 3. Review your code
mesrai reviewThat's it. Mesrai analyzes your changes, finds issues, and lets you fix them interactively — or auto-fix everything at once with mesrai review --fix.
What It Does
Code Review
Analyze local changes, staged files, commits, or branch diffs. Mesrai finds bugs, security issues, performance problems, and style violations — then suggests fixes with real code.
mesrai review # Review working tree changes (interactive)
mesrai review --staged # Only staged files
mesrai review --branch main # Compare against a branch
mesrai review --fix # Auto-apply all fixable issues
mesrai review --prompt-only # Structured output for AI agentsReviews are context-aware — Mesrai reads your .cursorrules, claude.md, and .mesrai.md so suggestions follow your team's standards. More on review modes
Mesrai Rules
Create, update, and inspect the Mesrai Rules that guide Mesrai behavior for your team.
mesrai rules create --title "Use async/await" --rule "Prefer async/await over raw promises" --repo-id global --severity high --scope file --path "**/*.ts"
mesrai rules update --uuid <uuid> --repo-id global --severity critical
mesrai rules view --repo-id globalmesrai rules update requires --uuid.
Defaults:
repo-iddefaults toglobalseveritydefaults tomediumscopedefaults tofilepathis optional (omitted means all files)
PR Suggestions
Fetch AI-powered suggestions for open pull requests directly from your terminal.
mesrai pr suggestions --pr-url https://github.com/org/repo/pull/42
mesrai pr suggestions --pr-number 42 --repo-id <id>Filter by severity, export as JSON or Markdown, or pipe into an AI agent with --prompt-only for automated fixes.
Business Validation (Local Diff vs Task)
Run Mesrai business-rules validation directly from your local diff with optional task reference.
# Working tree diff (default)
mesrai pr business-validation
# Staged-only with explicit task reference
mesrai pr business-validation --staged --task-id KC-1441
# Branch or files scope
mesrai pr business-validation --branch main --task-id KC-1441
mesrai pr business-validation src/service.ts src/use-case.ts --task-id KC-1441Decision Memory
AI agents make dozens of decisions per session — architecture choices, trade-offs, why approach X was picked over Y. Without a record, that reasoning vanishes when the session ends.
Mesrai captures agent decisions into your repo as structured markdown. When you or another agent return to the code, the full context is there.
mesrai decisions enable # Install hooks + initialize config
mesrai decisions status # See what's been captured
mesrai decisions show [name] # View PR or module memory
mesrai decisions promote # Promote decisions to long-term memoryStored in .mesrai/pr/by-sha/<head-sha>.md — versioned with your code, readable by humans and agents. More on decision memory
Best With AI Agents
Mesrai is designed to work inside AI coding agents. While you can use it standalone, the real power comes when your agent runs reviews automatically and fixes issues in a loop — no manual intervention needed.
Works with: Claude Code, Cursor, Windsurf, GitHub Copilot, Gemini CLI, and 20+ more environments.
Install the Skill (recommended)
Two commands. Installs the CLI globally + deploys the review skill into every supported agent on your machine — Claude Code, Cursor, Windsurf, and others.
npm install -g @mesrai/cli
mesrai skills installAuto-detects installed IDEs. Re-run mesrai skills install anytime to add new agents.
How It Works With Agents
Once installed, your AI agent can autonomously:
- Write code as usual
- Run
mesrai review --prompt-onlyto analyze changes - Read the structured output and understand each issue
- Fix the issues automatically
- Repeat until the review is clean
This creates a tight feedback loop: the agent writes, reviews, and fixes — all without leaving your IDE.
Beyond reviews, Mesrai also captures what your agent decided and why via Decision Memory. Every reasoning step is saved into your repo — so when you (or another agent) pick up the work later, the full context is already there. No more re-explaining what was done or losing decisions between sessions.
Setup: Claude Code
Add to your project's CLAUDE.md:
## Code Review
After implementing changes, run `mesrai review --prompt-only` to check for issues.
If issues are found, fix them and re-run until clean.Or use the skill directly — after installing via the command above, just ask Claude Code to review your code and it will use Mesrai automatically.
Setup: Cursor / Windsurf
Add to your .cursorrules or equivalent:
When writing code:
1. Implement the feature
2. Run: mesrai review --prompt-only
3. If issues are found, fix them automatically
4. Repeat until review is clean
5. Show final resultSetup: Headless / Shared Environments
Set a team key so agents and shared machines are authenticated without individual logins:
export MESRAI_TEAM_KEY=mesrai_xxxxx
mesrai review --prompt-onlyWorks with Codex, CI runners, remote dev environments, and any context where personal login isn't practical. Get your key at app.mesrai.com/organization/cli-keys.
Copy & Paste Workflow (interactive)
If you prefer manual control:
- Run
mesrai review - Navigate to a file with issues
- Select "Copy fix prompt for AI agent"
- Paste into Claude Code or Cursor — the AI fixes it
The copied prompt includes file path, line numbers, severity, and detailed suggestions — optimized for AI agents.
Installation
Recommended — CLI + skills for all your agents
npm install -g @mesrai/cli
mesrai skills installmesrai skills install auto-detects installed agents (Claude Code, Cursor, Windsurf, and others) and deploys the review skill into each.
CLI only
npm install -g @mesrai/cliyarn global add @mesrai/clinpx @mesrai/cli reviewKeep everything updated
mesrai update # update CLI to latest npm release
mesrai skills resync # refresh agent skills after update
mesrai skills uninstall # remove managed skills from detected targetsAgent Mode
Mesrai now supports an explicit agent mode for deterministic automation output.
Global flag
Use --agent on any command to return a stable JSON envelope:
{
"ok": true,
"command": "review",
"data": {},
"error": null,
"meta": {
"schemaVersion": "1.0",
"cliVersion": "x.y.z",
"mode": "agent",
"durationMs": 123
}
}Command schema introspection
mesrai schema
mesrai schema --command "pr suggestions"Field selection for smaller payloads
Available on review and pr suggestions:
mesrai review --agent --fields summary,issues.file,issues.line
mesrai pr suggestions --agent --pr-url https://github.com/org/repo/pull/42 --fields summary,issues.file--fields requires --agent or --format json.
Dry-run for mutable commands
mesrai hook install --dry-run
mesrai hook uninstall --dry-run
mesrai decisions enable --dry-run
mesrai decisions disable --dry-run
mesrai decisions promote --dry-runDry-run prints the planned actions and does not mutate local hooks/config/files.
Review Modes
Interactive (default)
mesrai reviewNavigate files with issue counts, preview fixes before applying, and copy AI-friendly prompts to paste into Claude Code or Cursor.
Auto-fix
mesrai review --fixApplies all fixable issues at once. Shows a confirmation prompt before making changes.
AI Agent
mesrai review --prompt-onlyMinimal, structured output designed for Claude Code, Cursor, and Windsurf. Perfect for autonomous generate-review-fix loops.
Output Formats
mesrai review # Interactive (default)
mesrai review --format json # JSON output
mesrai review --format markdown # Markdown report
mesrai review --prompt-only # AI agent output
mesrai review --format markdown -o report.md # Save to fileOutput Streams
stdout: command result/payload (for example JSON/Markdown reports)stderr: debug traces (--verbose), spinner/progress messages, and errors
This keeps machine-readable output clean for piping:
mesrai review --format json > review.json
mesrai review --format json --verbose 1>review.json 2>review.debug.logDiff Targets
mesrai review # Working tree changes
mesrai review --staged # Staged files only
mesrai review --commit HEAD~1 # Specific commit
mesrai review --branch main # Compare against branch
mesrai review src/index.ts src/utils.ts # Specific filesAll Flags
| Flag | Description |
| ---------------------- | --------------------------------------------- |
| --staged | Analyze only staged files |
| --commit <sha> | Analyze a specific commit |
| --branch <name> | Compare against a branch |
| --rules-only | Only check configured rules |
| --fast | Faster analysis for large diffs |
| --fix | Auto-apply all fixable issues |
| --prompt-only | AI agent optimized output |
| --context <file> | Include custom context file |
| --format <fmt> | Output format: terminal, json, markdown |
| --output <file> | Save output to file |
| --fail-on <severity> | Exit code 1 if issues meet or exceed severity |
| -i, --interactive | Explicitly enable interactive mode |
Decision Memory
Full reference for the decision capture system (intro above).
# Enable with specific agents
mesrai decisions enable --agents claude,cursor,codex
# Custom Codex config path
mesrai decisions enable --agents codex --codex-config ~/.codex/config.toml
# Overwrite existing config
mesrai decisions enable --force
# Check what's been captured on current branch
mesrai decisions status
# View decisions for a PR or specific module
mesrai decisions show [name]
# Promote PR-level decisions to long-term module memory
mesrai decisions promote --branch feat/auth --modules auth,users
# Disable hooks (preserves all captured data in .mesrai/)
mesrai decisions disableHow it works: Hooks fire on agent turn-complete events and persist decisions to .mesrai/pr/by-sha/<head-sha>.md. Files are committed to your repo, versioned with your code, readable by humans and agents.
Supported agents: Claude Code, Cursor, Codex.
CI/CD & Git Hooks
Pre-push Hook
mesrai hook install --fail-on error # Block pushes with errors
mesrai hook status # Check hook status
mesrai hook uninstall # Remove hookPipeline Usage
# Strict rules check with JSON output
mesrai review --rules-only --format json --fail-on error
# Generate markdown report artifact
mesrai review --format markdown --output review-report.mdAuthentication
Mesrai supports multiple auth methods depending on your setup:
Trial Mode (no account)
Just run mesrai review. No signup needed. You get 5 reviews/day with up to 10 files and 500 lines per file — enough to try it out. Sign up free to remove limits.
Personal Login
For individual developers. Creates a session with automatic token refresh.
mesrai auth login # Sign in with email/password
mesrai auth status # Check auth status and usage
mesrai auth logout # Sign outCredentials are stored locally in ~/.mesrai/credentials.json.
Team Key
For teams where not everyone needs their own account. A single shared key gives the whole team access — developers just set the key and start reviewing, no individual signup required.
mesrai auth team-key --key mesrai_xxxxxOr set it as an environment variable:
export MESRAI_TEAM_KEY=mesrai_xxxxxGet your team key at app.mesrai.com/organization/cli-keys. Team keys have configurable device limits managed from the dashboard.
This is also the recommended auth method for AI coding agents (Claude Code, Cursor, Codex) — set the env var once and every agent session is authenticated automatically.
Repository Configuration
Repository configuration requires team-key auth:
- team keys work across
add,list,show,setup,set, and pattern mutations through the CLI config endpoints
These commands always read and update the repository's current settings directly. There is no reset-to-default flow in the CLI.
mesrai config -r and mesrai config --remote are shortcuts for mesrai config remote add.
mesrai config -r . # Shortcut for: mesrai config remote add .
mesrai config --remote . # Shortcut for: mesrai config remote add .
mesrai config --remote . --json # Add and print machine-readable result
mesrai config --remote . --no-prompt # Add without starting setup
mesrai config remote add . # Add the current repository explicitly
mesrai config remote show . # Inspect current repository settings
mesrai config remote setup . # Run guided setup again
mesrai config remote setup . --json # Print structured setup result
mesrai config remote set . review.enabled true
mesrai config remote set . review.enabled true --json
mesrai config remote set . patterns.ignoreFiles "**/*.lock,dist/**"
mesrai config remote add-pattern . ignore-files "dist/**"
mesrai config remote add-ignore-file . "dist/**"
mesrai config remote remove-base-branch . "release/*"
mesrai config remote remove-pattern . base-branches "release/*"
mesrai config remote open . --section suggestion-control
mesrai config remote list --json
mesrai config remote list # List repositories already configuredWhen a repository is added from an interactive terminal, Mesrai offers a guided setup for:
- automated review
- auto approve
- minimum severity level
- ignored file patterns
- base branch patterns
- ignored title patterns
Pattern fields accept glob expressions such as **/*.lock, dist/**, release/*, and draft*.
Use mesrai config remote open when you need advanced repository settings that are still web-only. The CLI opens the Mesrai app and prints the repository/section path to navigate.
Use --json with show, set, open, add-pattern, remove-pattern, and the pattern aliases when you need stable machine-readable output for scripts or AI agents.
When targeting a repository that is different from your current working directory, pass owner/repo explicitly instead of .:
mesrai config -r Wellington01/mesrai-extension
mesrai config remote show Wellington01/mesrai-extensionLocal API note
When testing against the local backend with yarn start:local, repository configuration works with a team key when the local API exposes:
GET /cli/config/repositories/availableGET /cli/config/repositories/selectedPOST /cli/config/repositoriesGET /cli/config/repositories/:repositoryId/settingsPATCH /cli/config/repositories/:repositoryId/settings
Repository configuration access denied: ...Example local commands:
export MESRAI_TEAM_KEY=mesrai_xxxxx
yarn start:local config -r Wellington01/mesrai-extension --no-prompt
yarn start:local config remote list --json
yarn start:local config remote show Wellington01/mesrai-extensionCI/CD Token
For pipelines and automated environments. Generated from your personal login:
mesrai auth token # Generate a CI/CD tokenThen use it in your pipeline:
export MESRAI_TOKEN=<your-token>
mesrai review --format json --fail-on errorNote: For PR-level reviews in CI/CD, we recommend using the Mesrai platform GitHub/GitLab integration instead of the CLI. It's purpose-built for PR workflows with inline comments, status checks, and team dashboards.
| Variable | Description |
| ---------------- | ------------------------------------------------------------------------------ |
| MESRAI_API_URL | API endpoint (default: https://api.mesrai.com). HTTPS only (except localhost). |
| MESRAI_APP_URL | Optional Mesrai app URL override for mesrai config remote open. |
| MESRAI_TOKEN | CI/CD token for automated pipelines (generated via mesrai auth token) |
| MESRAI_TEAM_KEY | Team key for shared team access and AI coding agents |
Privacy & Security
Mesrai sends your code diffs to the Mesrai API for analysis. We take this seriously:
- HTTPS only — All API communication is encrypted. Custom API URLs are validated.
- No training on your code — Your code is not used to train models.
- Minimal data — Only diffs and context files are sent, not your entire codebase.
- Credentials stored locally — Auth tokens are kept in
~/.mesrai/credentials.jsonon your machine.
Support
Email: [email protected] Docs: docs.mesrai.com
License
Copyright (c) 2026 Mesrai. All rights reserved.
