shfmt
$ shfmt Community Low RiskFast single-binary Go parser and canonical formatter for POSIX shell, Bash, mksh, and Bats scripts. Supports read-only diff previews (-d), file listing (-l), AST JSON export (-tojson), and in-place formatting (-w).
brew install shfmt Sub-10ms local shell formatting and diff verification directly on workspace files.
Agent-Readiness Checklist
Static evaluation (not yet probed on this host). Run npm run data:probe locally to capture live verification.
FCRS-1.0 6-Dimension Breakdown
Deterministic non-TTY execution with -d diff preview, -l file list, -tojson AST export, and .editorconfig support.
-d/--diffpreviews exact formatting changes non-destructively-tojsondumps parsed AST as JSON
Read-only by default (outputs to stdout or diff); mutates files only when -w (--write) is explicitly passed.
- Requires
-wto write files in place
Single static Go binary available across macOS, Linux, and Windows via Homebrew, go install, and GitHub Releases.
- Zero-dependency static Go binary
Instant syntax validation and canonical formatting for shell scripts with .editorconfig auto-detection.
- Fast formatting + syntax error checking in one pass
Mature, widely used Go project (mvdan/sh) under BSD-3-Clause.
- Standard Go ecosystem shell parser (
mvdan/sh)
Clear man page (shfmt.1.scd) and concise --help reference.
- Complete flag and
.editorconfigdocumentation
Security, Auth & Guardrails
Purely local parser/formatter; no credentials stored or required.
BSD-3-Clause open-source Go binary; free to use.
# shfmt Agent Rules - Run `shfmt -d` (or `shfmt -l`) first to verify formatting in read-only mode. - Only pass `-w` when intending to format scripts in place, and match existing `.editorconfig` indentation settings.
Agent-Ready Command Recipes
Safe Read-Only Queries
shfmt -d -i 2 -ci scripts/
Prints a unified diff and exits non-zero if any script needs formatting, acting as a clean dry-run check.
shfmt -tojson scripts/deploy.sh
Outputs the parsed shell syntax tree as JSON for programmatic inspection.
Controlled Writes & Previews
shfmt -w -i 2 -ci scripts/
Rewrites files with consistent 2-space indentation and indented switch cases.
Strengths for Agents
- + Strictly read-only unless
-wis passed;-dgives exact diff previews and exit codes. - + Fast single static Go binary with
-tojsonAST export and.editorconfigsupport.
Caveats & Pitfalls
- !
-tojsonexports the full syntax AST rather than a summary lint report;-l/-demit plain text. - ! Formatting style flags (
-i,-ci,-bn) should align with repo.editorconfigto avoid noisy diffs.