Claude Code Integration
Reins integrates with Claude Code via PreToolUse and PostToolUse hooks registered in .claude/settings.json. Every tool call is intercepted synchronously — the agent cannot proceed until the hook exits.
Install
npm install -g @pegasi-ai/reins
reins initreins init detects Claude Code, writes the hooks into .claude/settings.json, and runs an initial security scan.
What gets installed
reins init adds hook entries for five matchers: Bash, Edit, MultiEdit, Write, and "" (empty matcher catches all MCP tool calls).
{
"hooks": {
"PreToolUse": [
{ "matcher": "Bash", "hooks": [{ "type": "command", "command": "node /path/to/dist/hooks/pre-tool-use.js", "_reins": true }] },
{ "matcher": "Edit", "hooks": [{ "type": "command", "command": "node /path/to/dist/hooks/pre-tool-use.js", "_reins": true }] },
{ "matcher": "MultiEdit", "hooks": [{ "type": "command", "command": "node /path/to/dist/hooks/pre-tool-use.js", "_reins": true }] },
{ "matcher": "Write", "hooks": [{ "type": "command", "command": "node /path/to/dist/hooks/pre-tool-use.js", "_reins": true }] },
{ "matcher": "", "hooks": [{ "type": "command", "command": "node /path/to/dist/hooks/pre-tool-use.js", "_reins": true }] }
],
"PostToolUse": [
{ "matcher": "Bash", "hooks": [{ "type": "command", "command": "node /path/to/dist/hooks/post-tool-use.js", "_reins": true }] },
{ "matcher": "Edit", "hooks": [{ "type": "command", "command": "node /path/to/dist/hooks/post-tool-use.js", "_reins": true }] },
{ "matcher": "MultiEdit", "hooks": [{ "type": "command", "command": "node /path/to/dist/hooks/post-tool-use.js", "_reins": true }] },
{ "matcher": "Write", "hooks": [{ "type": "command", "command": "node /path/to/dist/hooks/post-tool-use.js", "_reins": true }] },
{ "matcher": "", "hooks": [{ "type": "command", "command": "node /path/to/dist/hooks/post-tool-use.js", "_reins": true }] }
]
}
}The _reins marker lets Reins identify and update its own hooks without touching any other entries.
Hook exit codes
| Exit code | Meaning | Claude Code behavior |
|---|---|---|
0 | ALLOWED | Proceed normally |
2 | BLOCKED | Tool call is cancelled; stderr is shown to the user |
0 + JSON decision: WARN | WARNING | Proceed with caution; warning surfaced in output |
Skill
The Reins skill teaches Claude Code how to respond when an action is blocked — attributing the block to Reins, explaining the rule, and suggesting safe alternatives.
Claude Code has no npx add-skill command or central skill registry. Skills are markdown files placed in ~/.claude/skills/<name>/SKILL.md. There are three ways to get it:
Via reins init (recommended) — the wizard installs the skill automatically alongside the hooks. Nothing else needed.
Project-level — commit .claude/skills/reins/SKILL.md into your repo. Anyone who clones gets it with no install step:
.claude/skills/reins/SKILL.mdPersonal install via curl — available across all your projects, not just this repo:
mkdir -p ~/.claude/skills/reins
curl -o ~/.claude/skills/reins/SKILL.md \
https://raw.githubusercontent.com/pegasi-ai/reins/main/skill/SKILL.mdAll three can coexist. reins init installs to ~/.claude/skills/reins/ (personal). The project-level file takes no extra steps and works for contributors who haven’t run reins init.
Personal — available across all your projects:
mkdir -p ~/.claude/skills/reins
curl -o ~/.claude/skills/reins/SKILL.md \
https://raw.githubusercontent.com/pegasi-ai/reins/main/skill/SKILL.mdExamples
Blocked: recursive root deletion
echo '{"tool_name":"Bash","tool_input":{"command":"rm -rf /"}}' \
| node dist/hooks/pre-tool-use.js🪢 Reins: action blocked
Severity: CRITICAL
Reason: Critically destructive command
Tool: Bash
Action: rm -rf /
Rule: rm\s+-rf\s+[\/~]
This action was blocked by Reins. Do not retry it.
Run `reins audit -n 5` to view the logged decision.Blocked: write to protected path
echo '{"tool_name":"Write","tool_input":{"file_path":"~/.ssh/authorized_keys","content":"..."}}' \
| node dist/hooks/pre-tool-use.js🪢 Reins: action blocked
Severity: CRITICAL
Reason: Write to protected path
Tool: Write
Action: ~/.ssh/authorized_keys
Rule: protected_path:~/.sshAudit trail after blocks
reins audit -n 3════════════════════════════════════════════════════════════════════════════════
📋 ClawReins Audit Trail
════════════════════════════════════════════════════════════════════════════════
Showing last 3 decision(s):
8:28:28 PM | Shell.bash | BLOCKED | 0.0s
8:29:01 PM | FileSystem.write | BLOCKED | 0.0s
8:31:15 PM | FileSystem.read | ALLOWED | 0.0s
Audit log: ~/.openclaw/clawreins/decisions.jsonlVerify your setup
reins status # hook status + Reins Cloud connection
reins scan # 13-check security audit
reins audit # last 50 decisionsTemporarily suspend enforcement
reins disable # suspend all hooks
reins enable # resumeDisabled state is stored in ~/.openclaw/clawreins/config.json so it persists across sessions. Always re-enable after testing.