lx is a CLI tool that formats file system content for Large Language Models.
It replaces manual copy-pasting with a precise shell command, handling recursive discovery, formatting, and token estimation automatically.
Via go install:
go install github.com/rasros/lx/cmd/[email protected]Or via curl:
curl -fsSL https://raw.githubusercontent.com/rasros/lx/main/install.sh | bashThe copy-to-clipboard feature (-c / --copy) depends on the following:
- macOS: Native support via
pbcopy. - Windows: Native support via
clip. - Linux: Requires
xclipfor X11 orwl-clipboardfor Wayland to be installed.
If you're on Linux and not sure, do this:
echo $XDG_SESSION_TYPEIf it outputs wayland, install wl-clipboard. If it outputs x11, install xclip.
Format a single file:
lx go.modThis produces the following fenced output:
go.mod (10 rows)
---
```gomod
module github.com/rasros/lx
go 1.25.5
require gopkg.in/yaml.v3 v3.0.1
require (
github.com/atotto/clipboard v0.1.4
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00
)
```Recursively walk a directory and output contents (respects .gitignore):
lx src/Copy output directly to clipboard:
lx -c . # . is also the default if no arguments are providedWrite output to a file:
lx -o prompt.md src/lx allows you to compose context from multiple sources with specific ordering.
For example, to grab all server code (excluding tests), add the dependency file, organize them with headers, and copy the result to your clipboard:
lx -s "Server Code" -i "*.py" -e "test_*.py" src/server -E -s "Libs" requirements.txt -cWhat just happened?
-s "...": Injects a Markdown section header.-i/-e: Sets up filters to only include Python files and exclude tests.src/server: Recursively walks the source directory using those filters.-E: Resets the active filters so subsequent files aren't filtered.-s: Injects a new section header.requirements.txt: Appends the specific dependency file.-c: Copies the entire formatted output to your clipboard.
lx plays nicely with other tools. You can pipe a list of filenames from fd, find, or ripgrep directly into lx.
Using ripgrep to find files containing "TODO":
rg -l "TODO" | lx -cUsing fd to find all Rust files:
fd -e rs | lxYou can switch to XML formatting, which is recommended by Anthropic's documentation for Claude to ensure better parsing of long contexts.
lx --xml src/lx can output a complete, minimalistic HTML document styled with Pico CSS. This is useful for creating shareable
archives or viewing code in a browser. It automatically detects images and renders them too.
lx --html src/ > output.htmllx works like ripgrep or fd. It recursively walks directories while automatically respecting .gitignore,
.ignore, and .lxignore files.
lx src/ # Walks src/, skipping ignored files
lx -H . # Includes hidden filesLimit output to specific lines to save tokens.
# Get 50 lines from the middle of a file
lx --lines 50 error.log
# Compact mode: List filenames and sizes only (no content)
lx -n0 src/Add line numbers to help the LLM pinpoint specific locations in code or logs.
lx -l server.logInject custom instructions directly into the stream without leaving the terminal with -s or -p.
lx -p "Refactor the following code to use Pydantic:" main.pyTip: You can create aliases for common prompts. Add this to your shell profile to quickly inject your test prompt:
alias lxt='lx -p "$(cat ~/prompts/tests.md)"'lx prints a summary of file counts, total size, and estimated tokens to stderr. This appears automatically when
output is redirected from stdout. You can disable it by --no-stats.
Binary files are printed as a single line and do not cause errors.
PDF conversion and compressed archives are planned as future improvements.
lx is fully template-driven. You can customize the Markdown output format by creating a config file at
~/.config/lx/config.yaml.