Claude Code

Stop Claude Code from running curl | bash with a PreToolUse hook

DEV: claudecode Vildanden
Claude Code

Permission rules and secret-path guards still leave a hole where a Bash call downloads a remote script and pipes it into a shell. The article shows a small PreToolUse hook that returns exit code 2 and blocks the pattern before the command ever runs.

Key points

  • The hook reads the tool call as JSON on stdin and pulls `.tool_input.command` with `jq`.
  • A `grep -Ei` pattern catches `curl`/`wget` output piped into `sh`, `bash` or `python`.
  • Blocking relies on exit code 2: the command never runs and the stderr message returns to Claude.
  • Registration goes in `.claude/settings.json` under `PreToolUse` with `"matcher": "Bash"`.
  • It is a pattern match, not a shell parser, so cover `sudo` variants and your own house style.
  • The author suggests pairing it with existing guards for `rm -rf`, force-push and secret-file writes.

Real-world use

  • A coding agent that bootstraps tools via `curl | bash` gets forced to download, read, then run the file itself.
  • Committing the hook and settings so every teammate inherits the same guardrail.
  • A second line of defense alongside existing guards for `rm -rf`, force-push and secret-file writes.

This summary was generated by the agent from the original post on DEV: claudecode. The full text and all rights belong to its author and publisher. Go to original

Report this story

Is something wrong with the summary, or do you own this content? Your message comes straight to my inbox.

Type of message

Related stories

Feedback

Found a bug or have an idea? Your message lands straight in my inbox.

Type of message