Railgun

Introduction

Railgun is a Claude Code hook that protects against secrets leakage, dangerous commands, and unauthorized tool use.

What is Railgun?

Railgun is The Firewall for Claude Code. It sits between Claude and your system, inspecting every tool invocation before it executes.

┌──────────────┐     ┌─────────────┐     ┌──────────────────┐
│  Claude Code │ ──► │  Railgun  │ ──► │  Tool Execution  │
│  (LLM)       │     │  (Inspect)  │     │  (Bash, Write..) │
└──────────────┘     └─────────────┘     └──────────────────┘


                     Block or Allow

Why Railgun?

The Problem

Claude Code has powerful capabilities that can be dangerous if misused:

  • Bash commands can leak secrets via curl, environment variables, or error messages
  • File operations can expose .env, credentials, or private keys
  • Network requests can exfiltrate data to unauthorized domains

The Solution

Railgun performs inspection on every tool call:

  1. Check tool permissions — Is this tool allowed, denied, or requires confirmation?
  2. Scan for secrets — AWS keys, GitHub tokens, private keys, high-entropy strings
  3. Block dangerous commandsrm -rf /, fork bombs, disk operations
  4. Protect sensitive paths.ssh/, .env, *.pem, credentials files
  5. Prevent exfiltration — Block ngrok, pastebin, webhook.site

All with < 1ms latency and a fail-closed architecture.

Key Features

FeatureDescription
Secret DetectionBlocks AWS keys, GitHub tokens, OpenAI keys, private keys
Dangerous CommandsPrevents rm -rf /, fork bombs, disk writes
Protected PathsBlocks access to .ssh/, .aws/credentials, .env
Network ProtectionBlocks exfiltration to ngrok, pastebin, webhook.site
Tool PermissionsAllow/deny/ask rules for any tool or MCP server
Sub-ms LatencyPre-compiled patterns, won't slow your workflow

Architecture

Railgun is a Rust Cargo workspace:

CratePurpose
bin/rgCLI: hook execution, install/uninstall, lint, test
rg-typesShared types: Config, Verdict, HookInput
rg-policyPolicy engine: secret scanning, command blocking

Who is Railgun for?

  • Developers using Claude Code for daily work
  • Teams wanting guardrails on AI-assisted development
  • Security-conscious organizations with compliance requirements

Next Steps

On this page