# Installation Guide This guide covers installing the **Prompt Injection Defender** hook from the Claude Hooks collection. ## Prerequisites - [UV](https://github.com/astral-sh/uv) - Python package manager (for Python hooks) - [Claude Code](https://docs.anthropic.com/en/docs/claude-code) - Anthropic's coding assistant ## Quick Install (Recommended) ### Option 1: One-Line Install Script ```bash # Clone and install to your project git clone https://github.com/lasso-security/claude-hooks.git /tmp/claude-hooks cd /path/to/your-project bash /tmp/claude-hooks/install.sh ``` ### Option 2: Interactive Installation If you have this repo added as a Claude skill, simply tell Claude: ``` "install the prompt injection defender" ``` --- ## Manual Installation ### Step 1: Install UV (Python Runtime) ```bash curl -LsSf https://astral.sh/uv/install.sh | sh ``` ### Step 2: Clone Claude Hooks Repository ```bash git clone https://github.com/lasso-security/claude-hooks.git cd claude-hooks ``` ### Step 3: Copy Hook Files to Your Project Navigate to your target project and copy the defender files: ```bash # Set your project path export MY_PROJECT="/path/to/your-project" # Create hooks directory in your project mkdir -p "$MY_PROJECT/.claude/hooks/prompt-injection-defender" # Copy hook files cp .claude/skills/prompt-injection-defender/hooks/defender-python/* \ "$MY_PROJECT/.claude/hooks/prompt-injection-defender/" # Copy pattern definitions cp .claude/skills/prompt-injection-defender/patterns.yaml \ "$MY_PROJECT/.claude/hooks/prompt-injection-defender/" ``` ### Step 4: Configure Claude Code Settings Add the hook configuration to your project's `.claude/settings.local.json`: ```json { "hooks": { "PostToolUse": [ { "matcher": "Read", "hooks": [ { "type": "command", "command": "uv run \"$CLAUDE_PROJECT_DIR\"/.claude/hooks/prompt-injection-defender/post-tool-defender.py", "timeout": 5 } ] }, { "matcher": "WebFetch", "hooks": [ { "type": "command", "command": "uv run \"$CLAUDE_PROJECT_DIR\"/.claude/hooks/prompt-injection-defender/post-tool-defender.py", "timeout": 5 } ] }, { "matcher": "Bash", "hooks": [ { "type": "command", "command": "uv run \"$CLAUDE_PROJECT_DIR\"/.claude/hooks/prompt-injection-defender/post-tool-defender.py", "timeout": 5 } ] }, { "matcher": "Grep", "hooks": [ { "type": "command", "command": "uv run \"$CLAUDE_PROJECT_DIR\"/.claude/hooks/prompt-injection-defender/post-tool-defender.py", "timeout": 5 } ] }, { "matcher": "Task", "hooks": [ { "type": "command", "command": "uv run \"$CLAUDE_PROJECT_DIR\"/.claude/hooks/prompt-injection-defender/post-tool-defender.py", "timeout": 5 } ] } ] } } ``` ### Step 5: Restart Claude Code Restart Claude Code to load the new hook configuration. --- ## Installation Levels You can install hooks at different levels depending on your needs: | Level | File | Scope | | -------- | ----------------------------- | ------------------------------ | | Global | `~/.claude/settings.json` | All projects | | Project | `.claude/settings.json` | Shared with team (commit this) | | Personal | `.claude/settings.local.json` | Your overrides (gitignored) | --- ## TypeScript Alternative If you prefer TypeScript/Bun over Python/UV: 1. **Install Bun**: ```bash curl -fsSL https://bun.sh/install | bash ``` 2. **Use TypeScript files** from `hooks/defender-typescript/` instead 3. **Use `typescript-settings.json`** as your settings template --- ## Verify Installation After installation, test that the defender is working: 1. Create a test file with a known injection pattern: ```bash echo "" > /tmp/test-injection.txt ``` 2. Ask Claude Code to read the file: ``` "Read /tmp/test-injection.txt" ``` 3. You should see a warning in Claude's context about the suspicious content. --- ## Troubleshooting ### Hook not triggering - Ensure UV is installed and in your PATH - Check that file paths in settings are correct - Verify `.claude/hooks/` directory exists in your project ### Permission errors ```bash chmod +x .claude/hooks/prompt-injection-defender/*.py ``` ### Pattern file not found Ensure `patterns.yaml` is in the same directory as the Python hook script.