Parse files (e.g. code repos) and websites to clipboard or a file for ingestions by AI / LLMs
Parse files (e.g. code repos) and websites to clipboard or a file for ingestions by AI / LLMs
Ingest parses directories of plain text files, such as source code, into a single markdown file suitable for ingestion by AI/LLMs.
Ingest can also pass the prompt directly to any OpenAI compatible API for processing.
And ingest web URLs.
Ingest Intro ("Podcast" Episode):
Make sure you have Go installed on your system, then run:
go install github.com/sammcj/ingest@HEADI don't recommend this method as it's not as easy to update, but you can use the following command:
curl -sL https://raw.githubusercontent.com/sammcj/ingest/refs/heads/main/scripts/install.sh | bashmv ingest* /usr/local/bin/ingestBasic usage:
ingest [flags] ingest will default to the current working directory if no path is provided, e.g:
$ ingest
⠋ Traversing directory and building tree... [0s]
[ℹ️] Tokens (Approximate): 15,945
[✅] Copied to clipboard successfully.The tokeniser vocabularies (o200k_base and cl100k_base) are compiled into the binary, so ingest works offline and never downloads or caches anything.
Anthropic has never published a Claude tokeniser, so offline counts are produced with o200k_base and scaled to the model given by --model (default claude-opus-5):
Both factors are approximations that vary with content. For an exact count use -a/--anthropic, which calls Anthropic's count_tokens endpoint with the same --model (free, but needs ANTHROPIC_API_KEY). --no-correction reports the raw o200k_base count.
Generate a prompt from a directory, including only Python files:
ingest -i "**/*.py" /path/to/projectGenerate a prompt with git diff and copy to clipboard:
ingest -d /path/to/projectGenerate a prompt for multiple files/directories:
ingest /path/to/project /path/to/other/projectGenerate a prompt and save to a file:
ingest -o output.md /path/to/projectYou can also provide individual files or multiple paths:
ingest /path/to/file /path/to/directorySave output to to ~/ingest/.md:
ingest --save /path/to/projectCount tokens for a specific model, or exactly via the Anthropic API:
ingest --model claude-fable-5 /path/to/project
ingest --anthropic /path/to/projectIngest can pass the generated prompt to any OpenAI compatible API for processing.
ingest --llm /path/to/projectBy default this will use any prompt suffix from your configuration file:
./ingest utils.go --llm
⠋ Traversing directory and building tree... [0s]
This is Go code for a file named `utils.go`. It contains various utility functions for
handling terminal output, clipboard operations, and configuration directories.
...You can provide a prompt suffix to append to the generated prompt:
ingest --llm -p "explain this code" /path/to/projectIngest provides token counting using either an offline tokeniser (default) or the Anthropic API for more accurate counts.
By default, ingest uses an offline tokeniser with a correction factor for improved accuracy:
ingest /path/to/project
# [ℹ️] Tokens (Approximate): 15,945The offline tokeniser applies a 1.18x multiplier based on empirical analysis comparing it with Anthropic's API. This correction reduces average estimation error from ~17% to ~2%, providing slightly more accurate token counts without requiring an API key.
To disable the correction factor and use raw token counts, use the --no-correction flag:
ingest --no-correction /path/to/project
# Uses raw offline tokeniser without correction multiplierThe first time ingest runs, it downloads a small tokeniser file for offline use.
For accurate token counts using Anthropic's counting API, use the -a or --anthropic flag:
export ANTHROPIC_API_KEY="your-api-key"
ingest -a /path/to/project
# ✓ Using Anthropic API (claude-sonnet-4-5) for token counting
# [ℹ️] Tokens (Approximate): 15,942The API accepts keys from these environment variables (checked in order):
ANTHROPIC_API_KEYANTHROPIC_TOKENANTHROPIC_TOKEN_COUNT_KEYPerformance optimisation: When counting tokens for multiple files (e.g. in the "Top 15 largest files" report), ingest processes API requests in parallel batches of 4, significantly reducing the time needed for token counting.
If the API call fails, ingest automatically falls back to the offline tokeniser.
Experimental
Ingest can compress source code files by extracting key structural information while omitting implementation details. This is useful for reducing token usage while preserving the important parts of the code structure.
ingest --compress /path/to/projectThe compression extracts:
Currently supported languages:
Example of compressed JavaScript:
// This is a JavaScript comment
import { something } from 'module';
export class MyJSClass { ... } // Body removed
constructor(name) { ... } // Body removed
greet(message) { ... } // Body removed
export function myJSFunction(x, y) { ... } // Body removed
const myArrowFunc = (a, b) => { ... } // Body removedCrawl with explicit web mode
ingest --web https://example.comAuto-detect URL and crawl
ingest https://example.comCrawl with domain restriction
ingest --web --web-domains example.com https://example.comCrawl deeper with more concurrency
ingest --web --web-depth 3 --web-concurrent 10 https://example.comExclude a path from the crawl
ingest --web https://example.com -e '/posts/**'Ingest includes shell completions for Bash, Zsh, and Fish.
To load completions for the current session:
Bash:
source .md
- `--tokens`: Display the token count of the generated prompt
- `--verbose`: Print verbose output
- `--web-concurrent`: Maximum concurrent requests for web crawling
- `--web-depth`: Maximum depth for web crawling
- `--web-domains`: Comma-separated list of domains to restrict web crawling
- `--web`: Crawl a web page
- `-c, --encoding`: Optional tokeniser to use for token count
- `-d, --diff`: Include git diff
- `-e, --exclude`: Patterns to exclude (can be used multiple times)
- `-i, --include`: Patterns to include (can be used multiple times)
- `-l, --line-number`: Add line numbers to the source code
- `-n, --no-clipboard`: Disable copying to clipboard
- `-o, --output`: Optional output file path
- `-p, --prompt`: Optional prompt suffix to append to the generated prompt
- `-t, --template`: Path to a custom Handlebars template
- `-V, --version`: Print the version number (WIP - still trying to get this to work nicely)
### Excludes
You can get a list of the default excludes by parsing `--print-default-excludes` to ingest.
These are defined in [defaultExcludes.go](https://github.com/sammcj/ingest/blob/main/filesystem/defaultExcludes.go).
To override the default excludes, create a `default.glob` file in `~/.config/ingest/patterns/exclude` with the patterns you want to exclude.
### Templates
Templates are written in standard [go templating syntax](https://pkg.go.dev/text/template).
You can get a list of the default templates by parsing `--print-default-template` to ingest.
These are defined in [template.go](https://github.com/sammcj/ingest/blob/main/template/template.go).
To override the default templates, create a `default.tmpl` file in `~/.config/ingest/patterns/templates` with the template you want to use by default.
## Contributing
Contributions are welcome, Please feel free to submit a Pull Request.
You can help sponsor the project by trading the $INGEST SOL Token: https://bags.fm/Dm98Qa1Xw2n35bq73R2t1bFgXPApUKu2YwzU8TjWBAGS
## License
- Copyright 2024 Sam McLeod
- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.No open issues yet, or sync has not completed.