Skip to main content

Claude Code security guard - fixes broken permission system with intelligent pattern matching

Project description

claudeguard

claudeguard enhances Claude Code with intelligent pattern matching and team-shareable security profiles for consistent, automated permission decisions.

Why claudeguard?

Claude Code's interactive permission system ensures security but can be repetitive for routine operations. claudeguard builds on this foundation by providing automated pattern-based decisions for common workflows while maintaining full security for sensitive operations. It seamlessly integrates with Claude Code's permission system to give you the best of both worlds: security when you need it, automation when you don't.

Features

  • Reliable pattern matching: Edit(src/**), Bash(/git (status|diff)/), Bash(rm -rf*)
  • Smart defaults: Safe operations auto-allowed, dangerous operations denied
  • Team sharing: Security policies committed to git in .claudeguard/profiles/
  • Zero config: Works immediately with sensible rules
  • Full transparency: See exactly which rule matched and why

Quick Start

Installation

# Install as a tool (recommended)
uv tool install claudeguard

# Or add to your project
uv add claudeguard

# Or use pip
pip install claudeguard

Setup

cd your-claude-code-project
claudeguard install    # Configures Claude Code hooks and initializes profiles

Usage

Just use Claude Code normally - claudeguard works transparently in the background!

claude  # Enhanced with automated permission decisions

How It Works

claudeguard uses pattern matching to automatically make permission decisions:

# .claudeguard/profiles/default.yaml
rules:
  - pattern: "Read(*)"                    # Allow all file reads
    action: allow
  - pattern: "Edit(*.md)"                 # Allow markdown edits
    action: allow
  - pattern: "Bash(/git (status|diff)/)"  # Allow safe git commands (regex)
    action: allow
  - pattern: "Edit(src/**)"               # Ask before editing code
    action: ask
  - pattern: "Bash(rm -rf*)"              # Block dangerous commands
    action: deny
  - pattern: "*"                          # Ask for everything else
    action: ask

When Claude Code requests a tool permission, claudeguard:

  1. Matches the operation against your rules (first match wins)
  2. Returns allow, deny, or ask back to Claude Code's permission system
  3. Shows debug info: "Rule matched: Read(*) → allow"

Commands

  • claudeguard install - Install hooks and initialize claudeguard in current project
  • claudeguard status - Show current configuration
  • claudeguard create-profile - Create a new security profile
  • claudeguard list-profiles - List available security profiles
  • claudeguard switch-profile - Switch to a different security profile
  • claudeguard delete-profile - Delete a security profile
  • claudeguard uninstall - Remove claudeguard hook from Claude Code

Pattern Examples

Pattern Matches Typical Action
Read(*) All file reads allow
Edit(src/**) Edit files in src/ ask
Edit(*.md) Edit markdown files allow
Bash(/git (status|diff)/) Safe git commands (regex) allow
Bash(rm -rf*) Destructive rm commands deny
Bash(sudo *) All sudo commands deny
* Everything else ask

Team Workflow

  1. Project lead runs claudeguard install and customizes .claudeguard/profiles/default.yaml
  2. Commit profile: git add .claudeguard && git commit -m "Add claudeguard security profile"
  3. Team members clone repo and run claudeguard install
  4. Everyone gets consistent, reliable permissions

Advanced Usage

Custom Profiles

# .claudeguard/profiles/default.yaml
name: "strict-policy"
description: "Strict security for production code"
rules:
  - pattern: "Read(*)"
    action: allow
  - pattern: "Edit(docs/**)"
    action: allow
  - pattern: "Edit(*)"
    action: ask
  - pattern: "Bash(/git (status|diff|log)/)"
    action: allow
  - pattern: "Bash(*)"
    action: deny
  - pattern: "*"
    action: deny

Debug Output

claudeguard shows exactly why each decision was made:

claudeguard: Rule matched: Bash(/git (status|diff)/) → allow (Safe git operations)
claudeguard: Rule matched: Edit(src/**) → ask (Code changes should be reviewed)
claudeguard: Rule matched: Bash(rm -rf*) → deny (Destructive operations blocked)

Security Design

  • Fail-safe: Always fails to "ask", never to "allow"
  • Input validation: All tool calls validated and sanitized
  • Audit trail: All decisions logged with reasons
  • Least privilege: Minimal default permissions
  • Team oversight: Policies reviewed and committed to git

Development

git clone https://github.com/tarovard/claudeguard
cd claudeguard
uv sync                    # Install dependencies

# Setup pre-commit hooks (recommended)
uv run pre-commit install  # Install git hooks for automatic code quality

# Development commands
uv run pytest             # Run tests
uv run mypy src tests      # Type checking
uv run ruff check --fix .  # Format and lint

# Pre-commit will automatically run on git commit, or manually:
uv run pre-commit run --all-files  # Run all hooks manually

License

MIT - see LICENSE file.

Contributing

Bug reports and feature requests welcome at GitHub Issues.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

claudeguard-0.1.1.tar.gz (140.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

claudeguard-0.1.1-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

Details for the file claudeguard-0.1.1.tar.gz.

File metadata

  • Download URL: claudeguard-0.1.1.tar.gz
  • Upload date:
  • Size: 140.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.9

File hashes

Hashes for claudeguard-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6ef798d2a5100ff3d9a4dbb41343f2014eca195d4438f811a8dc2c2f04e3910e
MD5 3f57e7ac3a5e15c528ac0e02607516c5
BLAKE2b-256 1110e55c9294fadc168f44d75a3e1806b26ed77a46196568a964e575e1791477

See more details on using hashes here.

File details

Details for the file claudeguard-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for claudeguard-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 93545fd62cd7b7788457946730c3fc171475b7c108d7e52956951631b6679850
MD5 27ebfa430609dcbba53e449fb486bdd2
BLAKE2b-256 0d67118b6e0f53f92cfc278559e50967fae6afe62ffda47bc913400357354de9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page