Railgun

CLI Reference

Complete reference for the Railgun command-line interface.

Railgun is invoked via the railgun command.

Synopsis

railgun [OPTIONS] <COMMAND>
 
Commands:
  install    Configure Claude Code to use Railgun
  uninstall  Remove Railgun from Claude Code
  lint       Validate configuration file
  test       Test policy against specific input
  hook       Run as hook (used internally by Claude Code)
 
Options:
  -c, --config <FILE>  Path to config file [default: railgun.toml]
  -h, --help           Print help
  -V, --version        Print version

Commands

railgun install

Configure Claude Code to use Railgun as a preToolUse hook.

railgun install

This modifies ~/.claude/settings.json to add:

{
  "hooks": {
    "preToolUse": [
      {
        "matcher": "*",
        "command": "railgun hook"
      }
    ]
  }
}

railgun uninstall

Remove Railgun from Claude Code's hook configuration.

railgun uninstall

railgun lint

Validate your configuration file for syntax errors and invalid patterns.

railgun lint
railgun lint -c custom.toml

railgun test

Test your policy against a specific tool input without running Claude Code.

railgun test <TOOL_NAME> '<JSON_INPUT>'

Examples:

# Test Bash command
railgun test Bash '{"command":"ls -la"}'
 
# Test file write
railgun test Write '{"file_path":"/tmp/test.txt","content":"hello"}'
 
# Test with secrets
railgun test Bash '{"command":"echo $AWS_SECRET_ACCESS_KEY"}'
 
# Test protected path
railgun test Read '{"file_path":"~/.ssh/id_rsa"}'
 
# Test network
railgun test WebFetch '{"url":"https://pastebin.com/raw/abc123"}'

Output:

ALLOWED

or

DENIED
Reason: Dangerous command pattern: rm -rf with root path

railgun hook

Run as a Claude Code hook. Reads JSON from stdin, writes verdict to stdout.

echo '{"tool_name":"Bash","tool_input":{"command":"ls"}}' | railgun hook

Input Format:

{
  "tool_name": "Bash",
  "tool_input": {
    "command": "ls -la"
  }
}

Exit Codes:

CodeVerdictBehavior
0AllowTool executes normally
0AskUser prompted (with hookSpecificOutput)
2DenyTool blocked (with hookSpecificOutput)

Global Options

--config, -c

Specify the path to your configuration file.

railgun -c ./custom/railgun.toml lint
railgun --config /etc/railgun.toml test Bash '{"command":"ls"}'

Config Search Order:

  1. Explicit -c flag
  2. railgun.toml in current directory
  3. ~/.config/railgun/railgun.toml
  4. Built-in defaults

Environment Variables

VariablePurpose
RUST_LOGLog level (debug, info, warn, error)
RAILGUN_CONFIGAlternative to -c flag

Exit Codes

CodeMeaning
0Success (or Allow/Ask verdict for hook)
1Configuration error or general failure
2Deny verdict (hook mode only)

Next Steps

On this page