A command-line utility that intelligently converts your codebase into a single Markdown file, perfectly formatted for providing context to Large Language Models (LLMs).
stm helps you prepare your code for LLM interactions by:
- Converting multiple source files into a well-formatted Markdown document
- Respecting
.gitignorerules to exclude irrelevant files - Allowing explicit ignoring of files and directories via
--ignore - Detecting binary files and excluding them from output
- Automatically selecting appropriate language syntax highlighting
- Supporting glob patterns to easily specify target files
This is particularly useful when you need to provide code context to AI assistants like ChatGPT, Claude, or GitHub Copilot.
You need uv installed for the simplest installation:
uv tool install git+https://github.com/blasferna/stm.gitstm [paths...] [-o OUTPUT] [--project-root PROJECT_ROOT] [--no-gitignore] [--ignore IGNORE [IGNORE ...]] [--verbose]
# Convert entire current directory to stdout
stm
# Convert specific directory to a file
stm src -o context.md
# Convert multiple specific files
stm src/main.py tests/test_utils.py -o llm_context.md
# Use glob patterns to select files
stm "src/**/*.py" "tests/unit/**/*.py" -o context.md
# Ignore specific files or folders
stm src --ignore "src/config.py" "src/temp_data/" -o context.md
# Pipe output to clipboard (macOS)
stm "src/**/*.py" | pbcopy
# Pipe output to clipboard (Linux with xclip)
stm "src/**/*.py" | xclip -selection clipboard
# Pipe output to clipboard (Windows)
stm "src/**/*.py" | clip| Option | Description |
|---|---|
paths |
Paths to process (files, directories, or glob patterns like src/**/*.py). Default: current directory . |
-o, --output OUTPUT |
Output Markdown file. If not specified, prints to stdout. |
--project-root PROJECT_ROOT |
Specify the project root directory. .gitignore files are processed relative to this. Default: current working directory. |
--no-gitignore |
Disable .gitignore file processing. |
--ignore IGNORE [IGNORE ...] |
List of files or directories to explicitly ignore. Supports glob patterns (e.g., *.log, build/, src/generated/**). Paths are processed relative to the current working directory or can be absolute. Explicitly ignored items take precedence over other inclusion rules (like .gitignore). |
--verbose, -v |
Print verbose output, like skipped files. |
- Smart File Filtering: Automatically excludes binary files, respects
.gitignorerules, and allows for explicit ignores. - Language Detection: Automatically adds language identifiers for syntax highlighting.
- Path Preservation: Maintains original file paths in the output for context.
- Cross-Platform: Works consistently across operating systems.
- Flexible Input: Accept individual files, directories, or glob patterns.
- Prepare codebase snapshots for LLM conversations
- Generate documentation-ready code listings
- Create shareable code overviews
- Prepare code context for AI pair programming
MIT License - see the LICENSE file for details.
Blas Isaias Fernández (@blasferna)