22
33## Overview
44
5- The ` context ` tool extracts relevant code and context from your codebase to send to an LLM (Large Language Model).
5+ The ` context ` tool extracts relevant code and context from your codebase to send to an LLM (Large Language Model). It helps create focused, comprehensive snapshots of your codebase for more accurate AI assistance.
66
77## Usage
88
99``` bash
1010# Using patterns
11- ./context --files=" src/components/*.js" --exclude=" *.test.js" --max-size=300KB --format=md > context.txt
11+ ./context --files=" src/components/*.js" --exclude=" *.test.js" --max-size=300KB > context.txt
1212
1313# Using direct file paths
1414./context src/app.js src/utils.js README.md > context.txt
1515
16- # Including a prompt template
17- ./context --prompt=prompts/context_prompt.txt app.js > context.txt
16+ # Including git information and custom depth
17+ ./context --files= " src/*.js " --include-git --git-depth=5 --depth=2 > context.txt
1818```
1919
2020## Arguments
2121
2222| Argument | Description | Default |
2323| ----------| -------------| ---------|
2424| ` --files=<pattern> ` | File pattern to include (e.g., "src/* .js") | None |
25- | Direct file arguments | Files or directories to include (e.g., app.js README.md) | None |
25+ | Direct file arguments | Files to include (e.g., app.js README.md) | None |
2626| ` --exclude=<pattern> ` | File pattern to exclude (e.g., "node_modules/** ") | None |
2727| ` --max-size=<size> ` | Maximum context size in KB/MB (e.g., "500KB") | "500KB" |
28- | ` --include-deps ` | Include dependent files based on imports/requires | False |
2928| ` --depth=<num> ` | Dependency traversal depth | 1 |
3029| ` --include-git ` | Include git information (recent commits, authors) | False |
3130| ` --git-depth=<num> ` | Number of recent commits to include | 3 |
32- | ` --format=<format> ` | Output format (md, json, text) | "md" |
3331| ` --summary ` | Include short summary of each file | False |
3432| ` --show-file-sizes ` | Include file sizes in output | False |
3533| ` --truncate-large=<size> ` | Truncate files larger than specified size (e.g., "50KB") | None |
36- | ` --prompt=<file> ` | Include prompt template from specified file | None |
34+ | ` --verbose ` | Show verbose output during processing | False |
3735| ` --ls-files ` | Include git ls-files output | True |
3836| ` --no-ls-files ` | Don't include git ls-files output | False |
3937| ` --ls-files-limit=<num> ` | Limit the number of files shown in ls-files | 100 |
38+ | ` --help ` , ` -h ` | Show help message | - |
4039
4140## Examples
4241
@@ -48,41 +47,66 @@ Extract all JS files in the src directory:
4847./context --files=" src/**/*.js" > code_context.md
4948```
5049
51- ### With Dependencies
50+ ### Exclude Specific Files
5251
53- Include imported/required files (1 level deep) :
52+ Include all JavaScript files but exclude test files :
5453
5554``` bash
56- ./context --files=" src/components/Button .js" --include-deps > button_context .md
55+ ./context --files=" src/**/* .js" --exclude= " **/*.test.js " > context .md
5756```
5857
59- ### Include Git Information
58+ ### Custom Size Limits
59+
60+ Set maximum context size and truncate large files:
61+
62+ ``` bash
63+ ./context --files=" src/*.js" --max-size=1MB --truncate-large=50KB > context.md
64+ ```
65+
66+ ### Git Information
6067
6168Generate context with git history:
6269
6370``` bash
6471./context --files=" src/utils/*.js" --include-git --git-depth=5 > utils_context.md
6572```
6673
67- ### JSON Output
74+ ### File Summary and Sizes
75+
76+ Include file summaries and size information:
77+
78+ ``` bash
79+ ./context --files=" src/*.py" --summary --show-file-sizes > context.md
80+ ```
81+
82+ ### Control Repository File Listing
83+
84+ Limit the number of files shown in the repository listing:
85+
86+ ``` bash
87+ ./context --files=" src/main.js" --ls-files-limit=50 > context.md
88+ ```
6889
69- Get context in JSON format for programmatic usage :
90+ Or disable the repository file listing completely :
7091
7192``` bash
72- ./context --files=" *.py " --format=json > context.json
93+ ./context --files=" src/main.js " --no-ls-files > context.md
7394```
7495
75- ## Customization
96+ ## Output Format
7697
77- The script is designed to be simple and easy to modify. You can :
98+ The tool generates markdown output with the following sections :
7899
79- 1 . Add support for more languages in the dependency resolution
80- 2 . Modify the output format for your specific needs
81- 3 . Add additional metadata to the context generation
100+ 1 . ** Code Context** - The main header
101+ 2 . ** Files** - The content of each matched file
102+ 3 . ** Git Information** (if requested) - Recent commits and branch information
103+ 4 . ** Repository Files** - List of files in the git repository
104+ 5 . ** Instructions for LLM** (if available) - Instructions from a prompt template
82105
83106## Tips
84107
85- - When working with LLMs, try to keep the context focused and relevant
86- - Use ` --exclude ` to filter out test files, build artifacts, etc.
87- - The ` --summary ` flag can help provide high-level context about each file
88- - If you hit token limits, use ` --truncate-large ` to limit file sizes
108+ - Keep the context focused and relevant for the task at hand
109+ - Use ` --exclude ` to filter out test files, build artifacts, and other non-essential files
110+ - The ` --summary ` flag helps provide high-level context about each file
111+ - If you hit token limits with your LLM, use ` --truncate-large ` to limit file sizes
112+ - For large repositories, adjust ` --ls-files-limit ` to show only the most relevant files
0 commit comments