longline
A safety hook for Claude Code that parses Bash commands and enforces configurable security policies.
What it does
longline acts as a Claude Code PreToolUse hook. It intercepts Bash commands before execution, parses them using tree-sitter, evaluates them against YAML-defined safety rules, and returns allow/ask/deny decisions.
Key features:
- Structured parsing of pipelines, redirects, command substitutions, and complex shell constructs
- Configurable safety levels (critical, high, strict)
- 800+ golden test cases for accuracy
- JSONL audit logging
- Fail-closed design: unknown/unparseable constructs default to
ask
Installation
# Build and install
# Copy default rules
Configuration
Add to your Claude Code settings (~/.claude/settings.json):
Usage
longline reads hook JSON from stdin and outputs decisions to stdout:
# Test a command
|
# Inspect rules
# Check a specific command
Rules
Rules are defined in YAML with three matcher types:
- command: Match command name and arguments
- pipeline: Match command sequences (e.g.,
curl | sh) - redirect: Match output redirection targets
Example rule:
- id: rm-recursive-root
level: critical
match:
command: rm
flags:
any_of:
args:
any_of:
decision: deny
reason: "Recursive delete targeting root filesystem"
Safety levels
- critical: Catastrophic operations (rm -rf /, dd to disk, etc.)
- high: Dangerous operations (secret access, network exfiltration)
- strict: Potentially risky operations requiring review
Decision model
allow: Command is safe, proceed without promptingask: Command requires user approvaldeny: Command is blocked (can be downgraded toaskwith--ask-on-deny)
License
MIT