Skip to main content
hook

shell-wrapper-guard — Claude Code hook: what it does, how to install

Checks Bash commands for destructive actions concealed in shell wrappers. It helps catch bypasses that direct command checks can miss.

Install into Claude Code · claude-code-templates All methods and platforms ↓
npx claude-code-templates@latest --hook security/shell-wrapper-guard
Open on GitHub

What shell-wrapper-guard does

This hook checks Bash commands before they run, looking for destructive actions nested inside wrappers. It covers interpreter one-liners, nested wrappers, commands piped into a shell, here-strings, and env-based wrappers; the description lists eight bypass patterns.

The executable shell-wrapper-guard.sh runs as a PreToolUse hook matched to Bash. It complements dangerous-command-blocker rather than replacing direct command checks. Install it with npx claude-code-templates@latest --hook security/shell-wrapper-guard; .claude/settings.json is the associated settings file. It only runs for Bash tool calls.

What it helps with

  • catch file deletion hidden in sh -c
  • inspect destructive code passed to python3 -c
  • check nested shell wrappers before execution
  • detect commands piped into a shell

Example prompts for the agent

  • Check whether sh -c "rm -rf /" hides a destructive command before running it.
  • Inspect this python3 -c call for destructive actions.
  • Check this nested shell command before executing it.

How to install shell-wrapper-guard

1claude-code-templates

npx claude-code-templates@latest --hook security/shell-wrapper-guard

2Manually: put the files in place

.claude/settings.json

The hooks block: event (PreToolUse, PostToolUse, Stop…) → command. Personal ones go to ~/.claude/settings.json

Step by step, with commands for each platform: Claude Code hooks: what they are, where to configure them, how to block a risky command

Questions about shell-wrapper-guard

How do I install shell-wrapper-guard in Claude Code?

Run npx claude-code-templates@latest --hook security/shell-wrapper-guard, then use .claude/settings.json to configure the hook.

What does shell-wrapper-guard do?

It checks Bash commands before execution and detects destructive commands concealed inside wrappers or interpreter calls.

Which wrappers and bypass patterns does it cover?

The listed calls include sh -c, bash -c, python3 -c, node -e, perl -e, and ruby -e. It also covers nested wrappers, pipe-to-shell commands, here-strings, and env-based wrappers.

Source text

shell-wrapper-guard.json · MIT
{
  "description": "Detects destructive commands hidden inside shell wrappers (sh -c, bash -c, python3 -c, node -e, perl -e, ruby -e). Complements dangerous-command-blocker by catching bypass vectors like 'sh -c \"rm -rf /\"' that evade direct command checks. Covers 8 bypass patterns: interpreter one-liners, nested wrappers, pipe-to-shell, here-strings, and env-based wrappers.",
  "supportingFiles": [
    {
      "source": "shell-wrapper-guard.sh",
      "destination": ".claude/hooks/shell-wrapper-guard.sh",
      "executable": true
    }
  ],
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "bash .claude/hooks/shell-wrapper-guard.sh"
          }
        ]
      }
    ]
  }
}

© davila7 · MIT · davila7/claude-code-templates

Similar hooks

All hooks for Security →

From the same set740

The whole set →

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor