Claude Code Integration

sag init sets up three things for Claude Code automatically.

1. STOP HOOK

Every time Claude Code finishes writing code, Saguaro reviews uncommitted changes. If violations are found, Claude is blocked and asked to fix them before completing.

1sag hook install # Enable (done by sag init)
2sag hook uninstall # Disable

Under the hood, Saguaro installs two hooks: a PreToolUse hook that injects rule context before certain tool calls, and a StopHook that triggers a full review when Claude is about to complete.

2. MCP SERVER

Saguaro registers itself as an MCP (Model Context Protocol) server via .mcp.json. Claude Code discovers it on startup and gains access to Saguaro tools.

MCP is an open protocol that lets AI assistants connect to external tools and data sources. By registering as an MCP server, Saguaro makes its capabilities available directly inside Claude Code without any extra configuration.

Tools available through the MCP server include:

  • Run a code review
  • Create new rules
  • Generate rules from your codebase
  • List existing rules
  • Explain what a rule does

3. SLASH COMMANDS

CommandWhat it does
/sag-reviewRun a code review manually
/sag-createruleCreate a new rule with AI assistance
/sag-generaterulesAuto-generate rules from your codebase

These slash commands are available inside Claude Code after running sag init.

4. HOW THE STOP HOOK WORKS

4.1When Claude Code is about to complete, the StopHook fires.

4.2Saguaro diffs uncommitted changes against the base branch.

4.3Matched rules are checked against changed files.

4.4If violations are found, the review results are returned to Claude with instructions to fix them. Claude is blocked from completing until the issues are resolved.

4.5If no violations are found, the hook passes silently and Claude completes normally.

The PreToolUse hook also runs before certain tool calls to inject rule awareness, giving Claude context about your team's conventions while it writes code.