Skip to main content

Claude Code Integration

Rafter’s Claude Code integration has three parts: hooks that intercept tool calls before and after they run, a set of skills Claude loads based on what you’re doing, and a sub-agent another agent can delegate security questions to. All three are installed by rafter agent init --with-claude-code.

Hooks

PreToolUse / PostToolUse entries in .claude/settings.json. Enforced outside the conversation on every matched tool call, independent of whether the agent remembers to check — see Enforcement.

Skills

Four skills in .claude/skills/ that Claude loads when their description matches what you’re doing: detection, secure design, code review, and vetting third-party skills.

Sub-agent

A rafter sub-agent at .claude/agents/rafter.md, restricted to Bash, Read, Grep, that another agent can delegate to with Agent(subagent_type="rafter").

Setup

1. Install Rafter CLI

Install globally:

2. Initialize Local Security

Run initialization with Claude Code integration:
Or install all detected integrations at once:
--all sets up every detected integration and downloads Betterleaks. It does not install the git pre-commit hook — run rafter agent install-hook for that (see Pre-Commit Hook below).
rafter agent init with no flags installs nothing — detection only affects messaging and (with --interactive) which integrations it offers to install. Either --with-claude-code or --all is required to actually write the Claude Code integration, and --all only picks it up if ~/.claude exists. Once installed, it writes: With --local, these land project-locally (<cwd>/.claude/...) instead of under $HOME, and the install additionally writes a project-scope <cwd>/.mcp.json registering the MCP server — the user-scope install never writes .mcp.json.
Use rafter agent init --with-claude-code --dry-run to print every file path the install would create or modify, without touching anything.

3. Restart Claude Code

Restart your Claude Code session to load the hooks and skills:

Hooks

.claude/settings.json gets two hook entries: The PreToolUse hook only ever denies. When it has no objection it returns no decision ({}), so Claude Code’s own permission settings and prompts apply as they would without Rafter; it never pre-approves a call. The hook denies a command that would normally require approval — it has no way to prompt mid-conversation. The deny reason tells you to run the command with rafter agent exec '<command>' at an interactive terminal, where you can approve it yourself. It also denies (rather than allows) on an internal error, with a reason of the form rafter hook error: <type>: <message>; denying to be safe. A malformed .rafter.yml is a handled condition, not an error — it produces a warning and the hook proceeds with default settings, not a denial. Re-running rafter agent init --with-claude-code is idempotent: it removes any previously-installed Rafter hook entries before adding current ones, so it won’t duplicate on a second run, and it preserves hooks from other tools already in settings.json. Rerun it to update the matchers of an older install; agent verify checks that a Rafter hook is installed, not its matcher.

Skills & Sub-Agent

Claude Code loads a skill automatically when its frontmatter description matches the current task — there’s no slash command to type. The four skills:
Routes to the other three when it’s unclear which applies, or when the task needs rafter run (remote SAST+SCA), rafter secrets (local secrets-only), rafter agent audit, policy checks, or command-risk evaluation. It also tells the agent to scan within the user’s quota: run rafter run once per task or before a PR, scan only changes while iterating, and never loop or --watch from an agent session.
Required before writing code for a feature touching auth, payments, credentials, tokens, sessions, file upload, user data, or data deletion. Asks the design-time questions (which primitive, which boundary, which default) rather than scanning finished code.
Required before marking done a diff that touches user input, SQL, shell, auth, credentials, file paths, serialization, or dependencies. Structured OWASP/ASVS/MITRE walkthroughs, meant to pair with rafter run on the same diff.
Required before copying any third-party SKILL.md, MCP manifest, Cursor rule, or agent config onto the machine. Runs the deterministic rafter skill review pass first, then walks a provenance / malware-indicator / prompt-injection / data-practices checklist. Replaces the deprecated rafter agent audit-skill.
The rafter sub-agent (.claude/agents/rafter.md) is the same router, packaged so another agent can delegate to it directly — Agent(subagent_type="rafter") — instead of relying on description-matching. It’s restricted to Bash, Read, and Grep: it doesn’t write code or commit.

CLI Commands

The skills and hooks call these directly — you can also run them yourself:
command
Remote SAST + SCA + secrets scan (needs RAFTER_API_KEY). rafter scan is an alias.
command
Local, offline secrets scan — not a full code-security scan.
command
Run a shell command through the same risk classification the hook uses — the way to approve a command the hook denied.
command
Security review of a skill, MCP manifest, or agent config before installing it. Accepts a local path, git URL, or github:/gitlab:/npm: shorthand, or --installed to audit everything already on the machine.
command
View security event logs.

Example Interactions

You: “I just updated all the npm packages”Claude: “Let me run a security scan to check for any new vulnerabilities in the updated dependencies.”[Invokes: rafter run]Claude: “Scan complete! Found 2 medium-severity issues in newly updated packages. Here’s what needs attention…”
You: “Can you review my changes before I create a PR?”Claude: “I’ll run the code-review skill and a security scan on your feature branch first.”[Loads rafter-code-review, invokes: rafter run —branch feature-auth]Claude: “Security scan passed with no issues. Your changes look good from a security perspective. Ready to create the PR?”
You: “Install this skill someone linked me on Discord”Claude: “Let me vet it first.” [Loads rafter-skill-review, invokes rafter skill review <path-or-url>]Claude: “The deterministic pass is clean, but I want to check provenance and look for prompt injection before installing — give me a minute.”

Configuration

Command Policy

Command enforcement is set by agent.commandPolicy:
Examples use the Node CLI’s camelCase keys; the Python CLI uses snake_case. See the key casing note.
A small set of catastrophic patterns (rm -rf /, fork bombs, disk wipes, reverse shells, and similar) is always blocked regardless of mode or policy — this can’t be configured away. Above that floor, commandPolicy.blockedPatterns and commandPolicy.requireApproval (see Custom Blocked Patterns below) are the per-project knobs; mode: approve-dangerous additionally requires approval for anything the risk assessor rates high.

View Current Config

Workflows

Secure Development Cycle

1

Start Feature

You: “Add user authentication”Claude: Loads rafter-secure-design before writing code, then writes it.
2

Pre-Commit Check

You: rafter secrets .Verify no secrets before committing.
3

Commit

Commit normally — if the pre-commit hook is installed (rafter agent install-hook), it scans staged files automatically.
4

Pre-PR Review

You: “Review my changes”Claude: Loads rafter-code-review, invokes rafter run --branch feature-auth.“Security scan passed. Ready to create PR?”

Installing Untrusted Skills

1

Download Skill

Save the skill file or clone the repo locally.
2

Audit Security

You: “Audit this skill before I install it”Claude: Loads rafter-skill-review, runs rafter skill review <path>, then walks the provenance / malware-indicator / prompt-injection / data-practices checklist.
3

Make Informed Decision

Install only once every branch of the checklist has a file:line answer. Partial confidence means don’t install.

Monitoring

View Agent Activity

Audit Reports

rafter agent audit has no --json flag. For a machine-readable audit trail, read ~/.rafter/audit.jsonl directly — it’s newline-delimited JSON.

Troubleshooting

  1. Confirm the integration, end to end:
    Plain rafter agent verify already checks that the files exist and executes the configured hook command with a synthetic rm -rf / --no-preserve-root payload, confirming it denies. Adding --probe sends a second, different synthetic command (rm -rf /tmp/rafter-probe-<pid>-<timestamp>) through the hook and confirms ~/.rafter/audit.jsonl recorded a command_intercepted entry for it — catching the separate failure mode where the hook denies correctly but never writes to the audit log.
  2. Reinstall:
  3. Restart Claude Code.
Skills load based on description matching, not a fixed trigger list.
  1. Verify the skill file exists and has valid frontmatter:
  2. Try a more explicit request naming the security concern directly, e.g. “run a Rafter security scan on this.”
  3. For remote scans, verify RAFTER_API_KEY is set:
If rafter run fails:
  1. Set the key in your shell environment (a project .env cannot set RAFTER_API_KEY as of 0.10.6 — the CLI ignores it there):
  2. Or store it in Rafter’s own config:
  3. Get a key from: rafter.so/dashboard
  1. Check the hook is actually wired up:
  2. Check settings.json directly for a PreToolUse entry whose command contains hook pretool.
  3. Re-run rafter agent init --with-claude-code — this rewrites the hook entry and removes any stale one that pointed at an old install path.

Best Practices

Recommended Workflow

  1. Let the skills load automatically: don’t disable them — proactive design/review catches issues earlier than a scan at the end.
  2. Scan before commits: rafter secrets ., or install the pre-commit hook so it happens for you.
  3. Vet untrusted skills with rafter-skill-review: before copying any third-party SKILL.md, MCP manifest, or agent config onto the machine.
  4. Review audit logs after anything suspicious: rafter agent audit --last 20.
  5. Keep the CLI updated: npm update -g @rafter-security/cli (or pip install -U rafter-cli).

Advanced Usage

Pre-Commit Hook

rafter agent init (with or without --all) does not install a git hook. Install it separately:
The pre-commit hook runs rafter secrets --staged --quiet and blocks the commit if it finds anything (or if the staged diff can’t be read at all — a scan that fails to run is treated as a block, not a pass).

Custom Blocked Patterns

Add organization-specific command patterns via ~/.rafter/config.json:
blockedPatterns entries are denied outright; requireApproval entries are denied with an approval hint (the hook can’t prompt, same as above) unless run via rafter agent exec at a terminal.

Vetting a Skill Before Install

rafter skill review is the deterministic first pass behind rafter-skill-review:
It pulls the skill (cloning a git URL into a temp dir), runs rafter secrets over the tree, extracts URLs and high-risk shell patterns, and reports a structured pass/fail. Exit code 0 means the deterministic pass found nothing — it does not mean the skill is safe: prompt injection, bad data practices, and authorship fraud are invisible to regex. The rafter-skill-review skill’s job is the judgment layer on top: provenance, malware indicators, prompt injection, and data-practices checklists it walks after the deterministic pass. rafter agent audit-skill still works but is deprecated in favor of this.

Comparison: OpenClaw vs Claude Code

OpenClaw: One skill (rafter-security), no hooks — the skill tells the agent which rafter commands to run and when.Claude Code: Four skills plus a sub-agent, backed by enforced PreToolUse/PostToolUse hooks.
OpenClaw: Advisory — the skill’s instructions guide the agent, but nothing intercepts a tool call it decides to skip.Claude Code: The hook runs outside the conversation and denies a matched tool call before it happens, independent of whether the agent “remembers” to check.

Support

Documentation

Complete guides and API reference

GitHub Issues

Report bugs and request features

Dashboard

Manage API keys and view scan history

Claude Code Docs

Learn more about Claude Code

Next Steps

Command Reference

Complete CLI command documentation

Secret Scanning

Deep dive into secret detection

CI/CD Integration

Use Rafter in continuous integration

API Reference

Backend API documentation