By aethryl
Steers the agent to the language server instead of reading source through the shell
npx claudepluginhub aethryl/lsp-guardDenies reading source files through cat/sed and whole-file reads of large files when a language server is available, and nudges symbol searches to the LSP.
A Claude Code plugin that makes the agent read source code through the language server
instead of cat and sed.
Agents tend to read a whole file to find one function. On a 1,000-line file that costs
thousands of tokens; an outline from documentSymbol plus a ranged Read costs a few hundred.
lsp-guard is a PreToolUse hook that pushes the agent toward the second option:
cat, sed, head, tail, less, more, bat and nl on a source file,
including through the rtk wrapper. Writes pass: a command containing a heredoc, sed -i
and output redirects (>) are allowed, as are these tools on piped input
(git show HEAD:app.py | head).documentSymbol first. A Read with offset or limit always passes.findReferences or workspaceSymbol when it greps source,
through grep/rg/egrep or the Grep tool. This is a hint, not a denial.The same rules apply to subagents, which have the LSP tool too.
Needs python3 on PATH (3.9+).
/plugin marketplace add Aethryl/lsp-guard
/plugin install lsp-guard@lsp-guard
lsp-guard only points the agent at the LSP tool; it doesn't provide one. Install an LSP plugin for each language you want guarded:
| Language | Extensions | Server on PATH | LSP plugin |
|---|---|---|---|
| Python | .py .pyi | ty, pyright-langserver or pylsp | ty-agent-lsp or pyright-lsp |
| Rust | .rs | rust-analyzer | rust-analyzer-lsp |
| TypeScript / JavaScript | .ts .tsx .mts .cts .js .jsx .mjs .cjs | typescript-language-server | typescript-lsp |
A language is guarded only when one of its servers is on PATH. Files in other languages are left alone.
Nothing to configure. Once installed, the hook runs before every Bash, Read and Grep call. When it denies a call, the agent gets the reason and a suggestion, for example:
service.py has 1240 lines. Outline it first with LSP documentSymbol, then Read the
symbol's range with offset/limit. Pass an explicit offset/limit if you really need the
whole file.
If you do need the whole file, ask for it: the agent can pass an explicit offset/limit.
hooks.json registers hooks/lsp_guard.py
as a PreToolUse hook on Bash|Read|Grep. The script uses only the Python standard library:
shutil.which) and builds the list of
guarded extensions from them.;, &&, ||, | and newlines, and checks each
segment's program and arguments.deny decision or with additionalContext, or prints nothing to let
the call through.7-day visitors to each marketplace page
Anthropic example skills
Anthropic's Claude Code plugins, installed from the claude-plugins-official repository
Ultra-compressed communication mode. Shortens prose while preserving technical terms, code, commands, and exact errors.