https://github.com/colthreepv/llm-context
A CLI tool that helps you generate context files for Large Language Models (LLMs).
https://github.com/colthreepv/llm-context
ai cli context-builder language-models llm nlp prompt-engineering
Last synced: 4 months ago
JSON representation
A CLI tool that helps you generate context files for Large Language Models (LLMs).
- Host: GitHub
- URL: https://github.com/colthreepv/llm-context
- Owner: colthreepv
- License: unlicense
- Created: 2024-11-05T14:44:43.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-08T02:23:47.000Z (over 1 year ago)
- Last Synced: 2025-09-19T17:42:05.934Z (9 months ago)
- Topics: ai, cli, context-builder, language-models, llm, nlp, prompt-engineering
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/llm-context
- Size: 154 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# llm-context
A CLI tool that builds context files from your project for Large Language Models (LLMs). It traverses directories, collecting file structures and contents into a single `.txt` file optimized for LLM context.
## Installation
```bash
npm install -g llm-context
```
For development:
```bash
git clone https://github.com/colthreepv/llm-context
cd llm-context
pnpm install
# Build and link globally so you can invoke 'llm-context' anywhere
pnpm build
pnpm link --global
```
## Usage
Basic syntax:
```bash
llm-context [options]
```
Example:
```bash
llm-context ./ context
```
This creates `llm-context.context.txt` containing:
- A `` block showing your file structure with token counts
- `` blocks containing each file's contents
### File Ignoring System
Use `-i` or `--ignore` to exclude files/directories:
```bash
llm-context ./src output -i "*.test.ts" -i cache -i docs -i web/src
```
The ignore system uses a "greedy" pattern matching approach:
- Patterns are converted to regular expressions
- `*` matches any sequence of characters
- `?` matches any single character
- Matches are case-sensitive
- A match anywhere in the path excludes the file/directory
Examples:
- `*.log` → matches `error.log`, `debug.log`
- `test/*` → matches anything in the `test` directory
- `.env.*` → matches `.env.local`, `.env.production`
- `web/src` → matches `web/src/**/*`, but not something like `app/src/**/*`
Default ignored paths include:
- VCS: `.git`, `.gitignore`
- Dependencies: `node_modules`, `*lock.json`, `*.yaml`
- Build outputs: `dist`, `build`, `.next`
- Configs: `.env*`, `.vscode`, `.idea`
- System files: `.DS_Store`, `Thumbs.db`
- Temporary: `coverage`, `tmp`, `.cache`
### Output Structure
The generated file contains:
1. A `` block with directory structure and token counts:
```
project (1234)
├── src (789)
│ ├── index.ts (234)
│ └── utils.ts (555)
└── package.json (45)
```
2. File contents in `` blocks:
```
// File contents here
```
### Token Estimation
The tool estimates tokens using a character-to-token ratio of ~3.62 characters per token. This is an approximation to help you stay within LLM context limits.
Large JSON files are automatically truncated to maintain reasonable context sizes:
- Objects: Limited to first 4 key-value pairs
- Arrays: Limited to first 2 items