Skip to main content

Classify bash commands as READONLY, WRITE, DANGEROUS, or UNKNOWN

Project description

bash-classify

Classify bash commands by their side-effect risk level.

What it does

bash-classify parses bash expressions using tree-sitter, classifies each command against a database of 120+ known commands, and outputs a structured JSON verdict. Commands are classified into four levels: READONLY, WRITE, DANGEROUS, and UNKNOWN.

Designed primarily as a Claude Code hook to automatically allow safe, read-only commands while flagging risky ones for human review.

Installation

uv tool install bash-classify
# or
pip install bash-classify

Quick start

$ echo 'kubectl get pods -n production' | bash-classify | jq '.classification'
"READONLY"

$ echo 'git push --force origin main' | bash-classify | jq '.classification'
"DANGEROUS"

$ echo 'cp file.txt /etc/config' | bash-classify | jq '.classification'
"DANGEROUS"

$ echo 'find . -name "*.pyc" -delete' | bash-classify | jq '.classification'
"DANGEROUS"

Claude Code plugin

The repo includes a Claude Code plugin that auto-allows readonly bash commands via a PreToolUse hook. Install it as a marketplace:

# First, install the bash-classify CLI
uv tool install bash-classify

# Then install the plugin marketplace
claude plugin add /path/to/bash-classify

Or from GitHub directly:

claude plugin add https://github.com/fprochazka/bash-classify

Once installed, any Bash tool call classified as READONLY is auto-approved — no permission prompt. Everything else (WRITE, DANGEROUS, UNKNOWN) still requires confirmation.

Command database

The classification database includes 120+ command definitions covering common Unix utilities, package managers, container tools, cloud CLIs, and more.

Classification levels

Level Description Examples
READONLY No side effects, safe to auto-approve ls, cat, grep, kubectl get
WRITE Modifies local files or state mkdir, cp, git commit
DANGEROUS Destructive, system-wide, or irreversible rm -rf, git push --force, chmod
UNKNOWN Command not in database Any unrecognized command

How it works

  • Tree-sitter parsing -- bash expressions are parsed into an AST for accurate command extraction, handling pipes, subshells, and command substitution
  • YAML command database -- each command has classification rules with subcommand and option matching
  • Subcommand matching -- kubectl get and kubectl delete can have different classifications
  • Delegation for wrappers -- commands like xargs, sudo, and env delegate classification to the inner command

Python API

from bash_classify import classify_expression

result = classify_expression("kubectl get pods")
print(result.classification)  # Classification.READONLY

See SPEC.md for the full specification.

Development

git clone https://github.com/fprochazka/bash-classify.git
cd bash-classify
uv sync --dev

Run tests and linting before committing:

uv run ruff format .
uv run ruff check .
uv run pytest

To add or modify command definitions, see docs/classification-guidance.md. All YAML files in src/bash_classify/commands/ are validated against a JSON Schema — your IDE will provide autocomplete if it supports the # $schema: comment.

Releasing

Version is derived automatically from git tags via hatch-vcs — no manual version bumping needed.

git tag v<version>
git push origin v<version>

The publish.yml GitHub Action builds and publishes to PyPI automatically via trusted publishing.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bash_classify-0.1.1.tar.gz (89.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bash_classify-0.1.1-py3-none-any.whl (66.6 kB view details)

Uploaded Python 3

File details

Details for the file bash_classify-0.1.1.tar.gz.

File metadata

  • Download URL: bash_classify-0.1.1.tar.gz
  • Upload date:
  • Size: 89.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for bash_classify-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a9175ba84eb4eb244193decd8140a0a2b64602a6dfc12e01381548c3c33b47c7
MD5 77732474e74b6a57c70ce91b616f33eb
BLAKE2b-256 e3019c9c00722abd34cb8591d33c2e2d25dff964b5e0a01e7f277d6a75d4d425

See more details on using hashes here.

Provenance

The following attestation bundles were made for bash_classify-0.1.1.tar.gz:

Publisher: publish.yml on fprochazka/bash-classify

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bash_classify-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: bash_classify-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 66.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for bash_classify-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5edc45054baa4eb7d53cb70c62a03b45d4b1bb9be42413ac17a466f40be4a657
MD5 443884f9abc9e75ad181bd9808c55e57
BLAKE2b-256 1857f3b792233a593e19b6f4e20cf545217925c9974152f3b87497f3e593e4dd

See more details on using hashes here.

Provenance

The following attestation bundles were made for bash_classify-0.1.1-py3-none-any.whl:

Publisher: publish.yml on fprochazka/bash-classify

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page