shell-lsp is a language server and command-line linter and formatter for shell
scripts (bash, zsh, POSIX sh, dash and ksh) and for the files that embed shell:
justfiles, Makefiles, Dockerfiles and Nix. It began as a shell server and grew
to follow shell into those files, and then to understand each of them as a
language of its own. A .zsh file and a flake.nix get the same depth.
- Every shell by its own rules. Each dialect has its own parser and is detected per file. zsh is linted as zsh, which ShellCheck refuses to do.
- Nix without an evaluator. Flakes, modules and overlays are followed from source, in a fraction of the memory nixd uses (measured).
- The languages are connected. Shell in a recipe, a
RUNinstruction or a Nix string is checked where it stands, and fixes are written back in the host's syntax. - One binary replaces a toolbox: shellcheck, shfmt, man, Hadolint, statix, deadnix and nixfmt, with their check codes, directives and flags.
- Compatibility is measured against ShellCheck on 4,716 scripts and nixfmt on every file of nixpkgs.
Download the binary and lint a directory (use linux-arm64 or darwin-arm64
for those platforms):
curl -fsSL -o shell-lsp https://github.com/stubbedev/shell-lsp/releases/download/v0.5.27/shell-lsp-v0.5.27-linux-amd64
chmod +x shell-lsp
./shell-lsp check -f gcc .Dockerfile:1:6: warning: `ubuntu` has no tag, so each build may start from a different image; name a version, as in `ubuntu:<version>` [DL3006]
Dockerfile:2:13: warning: `apt-get install` stops to ask for confirmation, which fails the build; add `-y` [DL3014]
Dockerfile:2:13: note: `apt-get install` also installs recommended packages; add `--no-install-recommends` to install only what is listed [DL3015]
Dockerfile:2:21: warning: pin the version of `curl`, as in `curl=<version>`, so a rebuild installs the same package [DL3008]
Makefile:4:28: note: Unquoted $f is split on whitespace and expanded as a glob; double-quote it. [SC2086]
Makefile:5:2: warning: If cd fails, the following commands run in the wrong directory; add || exit (or || return in a function). [SC2164]
flake.nix:13:53: note: Unquoted $index is split on whitespace and expanded as a glob; double-quote it. [SC2086]
justfile:4:23: error: unknown recipe `test` [SL5002]
justfile:9:16: note: A file matched by *.sh may start with a dash and be read as an option; use ./*.sh or put -- before it. [SC2035]
release.sh:4:81: error: jq: `[` is never closed in the regular expression [SL3003]
release.sh:5:1: warning: If cd fails, the following commands run in the wrong directory; add || exit (or || return in a function). [SC2164]
In an editor, put the binary on PATH and point the editor at it.
In VS Code, code --install-extension stubbedev.shell-lsp is enough: the
extension offers to download the binary.
Tip
The URL above names the version this README was released with. The
latest release has
the current version, the other platforms and SHA256SUMS.
Real output from v0.5.17 and later, from shell-lsp check and from the VS Code
extension.
ShellCheck stops at a zsh shebang. Here the unquoted $f, which zsh neither
splits nor globs, is left alone, and what zsh would really get wrong is reported:
#!/usr/bin/env zsh
read -r answer
if [[ $answer == (#i)y(es|) ]]; then
print -r -- "syncing $match[1]"
for f in *.conf(.N); do
rsync $f host:
done
fisync.zsh:3:18: warning: (#i) is an extended glob operator, and this file never runs `setopt extendedglob`, so zsh matches it literally. [SL2016]
sync.zsh:4:25: warning: $match is only set by a pattern with (#b) or by =~, and nothing in this file uses either. [SL2017]
Hover takes the shell's own patterns apart and, when the values are known, computes the result:
Flags and subcommands of installed commands come from their manual pages, read
without man, down to nested subcommands such as git remote add:
awk, sed and jq programs are parsed in place, without running them:
#!/usr/bin/env bash
wanted=$1
curl -fsSL https://example.com/index.json |
jq -r --arg name "$wanted" '.[] | select(.name == $name) | .version | test("^v[")'
cd distrelease.sh:4:81: error: jq: `[` is never closed in the regular expression [SL3003]
release.sh:5:1: warning: If cd fails, the following commands run in the wrong directory; add || exit (or || return in a function). [SC2164]
The just syntax and the shell in its recipes each know about the other:
version := "1.0"
export out_dir := "build"
package $target: lint test
mkdir -p "$out_dir"
cp "$target" "$out_dir/app-{{version}}"
lint:
shellcheck *.shtest is reported as an unknown recipe, with a quick fix that adds it,
{{version}} shows its value as an inlay hint, and renaming $out_dir from the
shell edits the just variable and every read.
Hadolint's rules, BuildKit's checks and the shell in RUN report together:
A fix is computed on the shell and escaped for where it lands. In a Makefile
$f stays $$f, and in a Nix " string a quote becomes \":
- for f in *.c; do $(CC) -c $$f; done
+ for f in *.c; do $(CC) -c "$$f"; done- home.packages = [ (pkgs.writeShellScriptBin "hello" "echo $1") ];
+ home.packages = [ (pkgs.writeShellScriptBin "hello" "echo \"$1\"") ];A fix that cannot be written there is not offered.
A writeShellScript string is read as shell with no marker, and findings land
on the line of the .nix file:
{
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
outputs =
{ nixpkgs, ... }:
let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
channel = "stable";
in
{
packages.x86_64-linux.latest = pkgs.writeShellScript "latest" ''
index=$(mktemp)
curl -fsSL https://example.com/index.json > $index
wanted=${channel}
${pkgs.jq}/bin/jq -r --arg name "$wanted" '.[$name]' "$index"
'';
};
}The last line of that script is three languages deep. Definition on $name
walks from the jq flag to the shell variable to the Nix binding:
Renames stay honest about where a name lives: renaming $name edits the flag
and its reads and leaves $wanted alone, and renaming from ${channel} in the
shell edits the Nix binding.
Definition on ${pkgs.jq} opens the package in the nixpkgs that flake.lock
pins, read from its source in the Nix store, and lib. completes from the same
source:
The module system passes lib by name, so renaming it in a module would break
the module. The server names what would break instead:
A string that Nix writes to a named file is read as that file's language:
{ pkgs, ... }:
{
home.file."project/justfile".text = ''
deploy: build
rsync -a out/ host:
'';
home.file."project/shell.nix".text = ''
let unused = 1; in pkgs.mkShell { }
'';
}home.nix:1:3: note: the function never reads its argument `pkgs` [SL8007]
home.nix:4:13: error: unknown recipe `build` [SL5002]
home.nix:9:9: note: `unused` is bound but nothing that is read reads it [SL8005]
home.nix:9:24: error: `pkgs` is not defined here, so Nix rejects the file [SL8002]
check reports what the editor shows, for every language at once, and takes
ShellCheck's options and output formats:
fmt formats shell like shfmt, justfiles like just --fmt and Nix like nixfmt,
and leaves the shell in a Nix string as it is, so the string keeps its value.
Every LSP method, in both directions, is listed with its status in docs/lsp-methods.md.
| Feature | Shell | Nix | justfile | Makefile | Dockerfile |
|---|---|---|---|---|---|
| Checks | SC, SL |
SL8, and SC in strings |
SL5, and SC in recipes |
SL6, and SC in recipes |
SL7, DL, and SC in RUN |
| Quick fixes | yes | yes | yes | yes | for the shell |
| Completion, hover | yes | yes | yes | yes | yes |
| Signature help | yes | yes | yes | yes | for the shell |
| Definition, references, highlight, rename | yes | yes | yes | yes | yes |
| Call hierarchy | yes | yes | yes | yes | no |
| Outline, workspace symbols | yes | yes | yes | yes | yes |
| Semantic tokens, folding, selection ranges | yes | yes | yes | yes | yes |
| Inlay hints | yes | yes | yes | yes | no |
| Document links | source paths |
paths, URLs, flake inputs | import, mod |
include, prerequisites |
no |
| Code lenses | references, Bats "Run" | references, nix build, nix run, nix flake check |
references, "▶ Run" | references, "▶ Run" | references |
| Formatting | shfmt's printer | nixfmt 1.5.0 | just --fmt |
spacing only | no |
| Refactorings | yes | yes | no | no | no |
| Compared with | ShellCheck, bash-language-server | nixd, nil, nixfmt, statix, deadnix | just 1.58 | GNU Make 4.4 | BuildKit 0.34, Hadolint 2.14 |
| Inside a shell string | awk | sed | jq |
|---|---|---|---|
| Syntax errors and regular expressions | SL3001 |
SL3002 |
SL3003 |
| Semantic tokens | yes | yes | yes |
| Hover | builtins | commands and flags | builtins |
| Completion, signature help | yes | no | yes |
| Variables bound on the command line | -v, --assign |
no | --arg, --argjson, --slurpfile, --rawfile |
The linter has 459 SC checks, 143 SL checks and 54 DL checks, each listed
with its severity in docs/checks.md.
- Release binaries for Linux and Windows (amd64 and arm64) and macOS (arm64)
are attached to every GitHub release
with a
SHA256SUMSfile. Check the download withsha256sum --check --ignore-missing SHA256SUMS, make it executable and put it onPATHasshell-lsp(shell-lsp.exeon Windows, see docs/editors.md). - Go 1.27.3 or newer:
go install github.com/stubbedev/shell-lsp@latest - Nix, built from source with the test suite:
nix profile install github:stubbedev/shell-lsp, or try it withnix run github:stubbedev/shell-lsp -- --version - VS Code and VSCodium: the Shell LSP extension
(
stubbedev.shell-lspon the Visual Studio Marketplace and Open VSX, and a.vsixon every release) runs the server, exposes its settings, and offers to download and verify the release binary.
The server speaks LSP over stdio and needs no arguments. Attach it to the file types you want. Neovim 0.11 and later:
vim.lsp.config("shell_lsp", {
cmd = { "shell-lsp" },
filetypes = { "sh", "bash", "zsh", "ksh", "make", "just", "dockerfile", "nix" },
root_markers = { ".git" },
})
vim.lsp.enable("shell_lsp")docs/editors.md covers Helix, Zed, older Neovim, any other client, and Windows.
Note
Run it alone on the files it handles. With bash-language-server, nixd, nil or a Dockerfile language server on the same files, the editor gets every answer twice.
shell-lsp # serve LSP over stdio
shell-lsp check . # lint every file it knows below .
shell-lsp check -f sarif . > out.sarif # for GitHub code scanning
shell-lsp fmt -d . # show what formatting would change
shell-lsp fmt -w script.sh # format in placecheck takes ShellCheck's options, .shellcheckrc files, output formats and
exit codes, and fmt takes shfmt's flags, so both drop into CI and pre-commit
hooks where shellcheck and shfmt ran before. Flags, formats and recipes are
in docs/cli.md.
Settings arrive as initializationOptions, as the shellLsp section of
workspace/didChangeConfiguration, or through workspace/configuration, per
workspace folder. Unknown keys and invalid values are rejected with an error
naming the field.
{
"dialect": "bash",
"lint": {
"enable": true,
"exclude": ["SC2034"]
}
}Every setting
| Key | Default | Meaning |
|---|---|---|
dialect |
detected per file | Force bash, zsh, sh, dash, ksh or busybox for every document |
lint.enable |
true |
Report lint findings alongside syntax errors |
lint.profile |
recommended |
How much to report: recommended, minimal or strict |
lint.exclude |
[] |
Codes to suppress, as SC2034 or 2034 |
lint.optional |
[] |
Opt-in checks to enable by name, such as require-variable-braces, or all |
format.enable |
true |
Answer formatting requests |
format.indent |
editor setting | Spaces per level; 0 indents with tabs |
format.binaryNextLine |
false |
Put &&, || and | at the start of continuation lines |
format.switchCaseIndent |
false |
Indent case arms inside case ... esac |
format.spaceRedirects |
false |
Write > file instead of >file |
format.functionNextLine |
false |
Put the opening brace of a function on its own line |
format.simplify |
false |
Apply shfmt's simplifications (like shfmt -s) |
format.minify |
false |
Minify the script (like shfmt -mn) |
nix.evaluate |
false |
Evaluate flakes with nix to complete and describe NixOS, home-manager and flake-parts options and nixpkgs attributes |
How the dialect of a script is decided is in docs/shell.md,
the lint profiles in docs/linting.md, and how
.editorconfig and the format.* settings interact in
docs/formatting.md.
| Tool | What shell-lsp takes over | Evidence | What differs |
|---|---|---|---|
| ShellCheck | Check codes, directives, .shellcheckrc, options, formats, exit codes |
Over 4,716 corpus scripts, corpus/shellcheck.md: 54,290 findings agree, 10,225 only ours, 3,250 only ShellCheck's |
Its own messages and SL checks, and it lints zsh. All differences |
| shfmt | Printer, flags, .editorconfig keys |
Built on a fork of the same library | Also formats justfiles, Makefiles and Nix |
| bash-language-server | Everything it offers, for every dialect | Completion recall 135/137 against 123/137, docs/crosscheck.md |
Lints without an external shellcheck |
| nixd | Navigation, completion, hover, rename, formatting | Compared question by question with cmd/nixparity, docs/corpus.md |
Nothing is evaluated by default, see below. Deliberate differences are listed |
| nil | The same | The same | Reads the whole project, where nil does not; no type inference on hover |
| statix, deadnix | Lints and findings, statix.toml, # deadnix: skip |
On 2,500 nixpkgs files, corpus/nix-lint.md: 676 agree, 65 only ours, 0 only theirs |
Details |
| nixfmt | Output, byte for byte | Compared on every file of nixpkgs, measured | Default width and indent only |
| Hadolint | DL codes, pragmas, .hadolint.yaml |
More than 500 Dockerfiles run through it | Deliberate differences |
Measured by cmd/perfreport on shell-lsp 0.5.22-0.20261117190216-40990b1ddad6, 2026-11-17: GitHub Actions ubuntu26 20261111.196.1, 4 cores (Intel(R) Xeon(R) 6973P-C), 16 GiB of memory, linux/amd64, go1.27.4. Times are medians of 5 runs.
| Measure | shell-lsp | For comparison |
|---|---|---|
check over the 1,187 *.sh and *.bash files of nixpkgs |
267 ms, 973 ms of CPU | one shellcheck 0.11.0 process: 16.0 s, 59.9 times as long, with a different rule set |
| A keystroke with 700 scripts open, editing outside them | 9.85 ms | |
| A keystroke with 700 scripts open, typing in one | 15.9 ms | |
| A keystroke in a plain 5,000-line Nix file | 33.9 ms | |
| Peak / idle memory on disko, 127 files open | 57 / 46 MiB | nixd 2.9.3: 573 / 561 MiB |
| Peak / idle memory on disko, 127 files open | 57 / 46 MiB | nil 2026-07-23: 32 / 19 MiB |
| Peak / idle memory on nixpkgs, 200 files open | 220 / 137 MiB | nixd 2.9.3: 482 / 474 MiB, restarted 3 times |
| Peak / idle memory on nixpkgs, 200 files open | 230 / 137 MiB | nil 2026-07-23: 31 / 19 MiB |
Formatting differences from nixfmt 1.5.0 over the 44,765 .nix files of nixpkgs |
0 |
Each release measures these again and adds them to its release notes. nil reads only the files that are open, where shell-lsp and nixd index the project. How they are measured and how to rerun them is in docs/corpus.md. The test suite holds keystrokes to allocation budgets and parsing and completion to time budgets.
- fish and csh are not supported. Scripts whose shebang names them are reported as unsupported.
- Dockerfiles are not formatted, and Dockerfile findings have no quick fixes of their own beyond the shell's.
- Large projects stop being followed: past 4096 files or 8 MiB of source, and a workspace scan stops at 20000 files. A rename that has to know every reader is then refused.
- Prebuilt binaries cover Linux and Windows on amd64 and arm64 and macOS on arm64.
nix.evaluateis off by default and needs Nix. Without it nothing is evaluated, so generatedpkgsattributes get no answer.pkgs.nerd-fonts.jetbrains-mono, members of a setcallPackagebuilds such aspkgs.writers.writePython3, and the versions nixd shows as inlay hints all need the setting. nixd answers these out of the box, since it evaluates<nixpkgs>on its own. Turning it on can fetch the flake's inputs over the network, uses CPU for as long as an evaluation runs and keeps results in a disk cache. It requires Nix 2.24 or newer, Lix 2.95 or newer, or Determinate Nix based on Nix 2.24 or newer.- nixd and nil still answer some questions shell-lsp does not. Those found so far are recorded by class in docs/corpus.md, with the cases where the difference is deliberate.
pkgs.xneeds aflake.lockwhose nixpkgs is in the store, or a file inside a nixpkgs checkout.nix-shell -p xleads toxonly where one of the project's overlays sets it.- Shell that Nix assembles across
${...}, such as acasewhose patterns come fromlib.optionalString, cannot be checked, and may be reported as a syntax error. - A string passed to a wrapper in another file is linted only after a background pass has proven it.
- Some variables stdenv reads, such as
dontPatchShebangs, still reportSC2034.
The documentation is also a searchable site.
| Topic | Page |
|---|---|
| Editors, Windows, requests for client authors | docs/editors.md |
check and fmt, CI, pre-commit |
docs/cli.md |
| Dialects, completion and hover, sourced files, embedded programs, refactorings, Bats | docs/shell.md |
Profiles, quick fixes, directives, .shellcheckrc |
docs/linting.md |
Every check, and SL rules in depth |
docs/checks.md, docs/rules.md |
Formatting and .editorconfig |
docs/formatting.md |
| Justfiles, Makefiles, Dockerfiles, and how shell in them is mapped | docs/hosts.md, docs/hadolint.md |
| Nix | docs/nix.md |
| LSP methods | docs/lsp-methods.md |
| Comparisons with the reference tools | docs/corpus.md, docs/crosscheck.md |
| Working on shell-lsp | docs/development.md, docs/vscode-publishing.md |
| Release notes | Releases |
AI agents wrote the code, the tests and the documentation. The author chose what to build and how far to take it, set the design rules the code has to follow, and decided what landed. Correctness rests mainly on checks anyone can rerun, rather than on line-by-line review: tests derived from what the reference tools observably do, real shells settling disagreements, and the same gates for every change.
ShellCheck, bash-language-server, Hadolint and the Nix tools were treated as black boxes; CLEAN_ROOM.md states what may and may not be used. Parsing and shell formatting reuse a fork of mvdan.cc/sh under its BSD license, in third_party/mvdan-sh. The full account is in docs/how-it-was-built.md.








