Turn your codebase into a single, LLM-friendly text file.
snapcode is a lightweight shell script that creates a snapshot of your project (directory tree + file contents) to share with Large Language Models (ChatGPT, Claude, etc.).
It is designed to be transparent and safe: it strictly respects your existing .gitignore rules and does not hide or exclude files "magically" (other than the .git directory and binary files).
- Strict Ignore Handling: Respects git ignore rules for any target inside a git worktree. If you haven't ignored a file in git,
snapcodewill include it. - Performance: Checks ignore rules before recursing into directories (safe for large projects with ignored
node_modules). - Binary Safety: Automatically detects and skips binary files (images, compiled binaries) to keep the text output clean. Whitespace-only files (e.g.
.gitkeep) are correctly treated as text. - Symlink Safety: Symlinks to files are never followed — they are noted in the output but their targets are not read, preventing accidental leaks outside the project tree.
- Multi-Folder Support: Snapshot multiple distinct directories in a single run.
- Safe Output: Writes to a temp file in the same directory as the destination, then renames atomically — an existing snapshot is never corrupted by a failed run.
- Stable Output: File and directory entries are sorted alphabetically, so snapshots are consistent and diffable across runs.
- Portable: Single-file script. Runs on any POSIX shell (
sh,bash,zsh). Works correctly when installed via symlink.
Download the script and make it executable.
Using wget:
wget -O snapcode https://github.com/roldel/snapcode/raw/main/snapcode
chmod +x snapcodeUsing curl:
curl -L https://github.com/roldel/snapcode/raw/main/snapcode -o snapcode
chmod +x snapcodeOptional: Move it to your path to use it globally:
mv snapcode /usr/local/bin/snapcodeand update .gitignore file:
# snapcode
snapcode
snapcode.txtRun it in your project root. It will generate snapcode.txt.
./snapcodeYou can create a snapshot that combines different parts of your system. snapcode will switch contexts correctly for each folder.
./snapcode frontend/src backend/api./snapcode --output context.md./snapcode --output - | pbcopysnapcode relies on your configuration to keep secrets safe.
- It uses your
.gitignore: Ignore rules are applied viagit check-ignore, so the target must be inside a git worktree. If you have.envin your.gitignore,snapcodewill skip it. - No Magic Hiding: If you have not ignored
.env(or other secrets),snapcodewill dump them. - Safety Stop: If the target is not inside a git repository,
snapcodewill warn you that no filtering will be applied and ask for confirmation before continuing.
Note:
snapcoderequiresgitto be installed. If git is not available and--no-ignoreis not set, the script will exit with an error rather than silently dumping unfiltered files.
You can add extra ignore rules just for the snapshot without modifying your project.
# Apply rules from .llmignore ON TOP of the standard .gitignore
./snapcode --ignore .llmignoreIf your current working directory differs from the snapshot target and has its own .gitignore rules you want applied, use --include-root-gitignore:
./snapcode --include-root-gitignore /some/other/projectThis is additive — the target's own .gitignore is always respected regardless.
To ignore all filtering rules and dump every text file found (binary files are still skipped, and .git is always excluded):
./snapcode --no-ignore --yes| Option | Description |
|---|---|
--path <DIR> |
Add a directory to the snapshot (optional, can just list dirs). |
--output <FILE> |
File to write to. Use - for stdout. |
--ignore <FILE> |
Add a custom ignore file (repeatable). |
--include-root-gitignore |
Also respect .gitignore in the current working directory, in addition to each target's own rules. Useful when CWD differs from the snapshot target. |
--no-ignore |
Disable all filtering (dumps everything except .git and binary files). |
--yes |
Non-interactive mode (auto-accepts prompts). |
--version |
Print version and exit. |
-h, --help |
Show help message. |
- Shell: Standard
sh(bash/zsh compatible). - Git: Required. Used for ignore rule evaluation (
git check-ignore). Without git, the script will refuse to run unless--no-ignoreis passed. - Grep: Used for binary file detection. Falls back to
odortrif unavailable (e.g. BusyBox environments). - Tree: (Optional) If installed with
--gitignoresupport, generates a better visual directory map when no custom ignore flags are active.
The generated report is structured to be easily parsed by LLMs:
===== snapcode Report =====
Generated: Sat Dec 13 14:00:00 GMT 2025
################################################
# SECTION ROOT: /my/project
################################################
===== Directory Tree (/my/project) =====
.
├── README.md
├── logo.png
├── secret_link
└── src
├── main.js
└── utils.js
===== File Contents (/my/project) =====
===== File: /my/project/README.md =====
# My Project
===== File: /my/project/logo.png =====
[Binary file skipped]
===== Symlink: /my/project/secret_link -> /etc/passwd (skipped) =====
===== File: /my/project/src/main.js =====
console.log("Hello World");
===== File: /my/project/src/utils.js =====
export const add = (a, b) => a + b;
When writing to a file, a summary is printed to the terminal:
Done! Snapshot saved to: snapcode.txt
4 file(s) processed — 3 included, 1 skipped as binary