A tool for copying code context to clipboard for use in LLM chats
Project description
LLM Context
LLM Context is a tool designed to help developers efficiently copy and paste relevant context from code repositories or text-based document collections into Large Language Model (LLM) chats. It leverages .gitignore
patterns for smart file selection and uses the clipboard for seamless integration with LLM interfaces.
Note on AI Assistance: This project was developed in collaboration with Claude-3.5-Sonnet. LLM Context itself was used during development to share code context with Claude in project mode. All of the code that makes it into the repo is human curated (by me 😇, @restlessronin).
Key Features
- Smart File Selection: Respects
.gitignore
rules and allows custom ignore patterns for fine-grained control over context inclusion. - Clipboard Integration: Automatically copies the generated context to your clipboard for easy pasting into LLM chats.
Current Usage Patterns
-
LLM Integration: LLM Context has been primarily used to provide Project Knowledge in Claude and GPT Knowledge in OpenAI. It can also be used with vanilla chat interfaces, and there's potential to optimize the tool for this use case in future updates.
-
Project Types: The tool has been successfully used with both code repositories and collections of text / markdown / html documents.
-
Project Size: LLM Context has been mainly used for projects where all files can be comfortably loaded into the LLM's context. Its usage for larger projects, where not all files would fit within the LLM's context window, has been limited and the workflow for such cases is not yet developed.
We welcome feedback on how to improve the workflow for larger projects and other use cases.
Installation
Use pipx to install LLM Context:
pipx install llm-context
Usage
Quick Start and Typical Workflow
- Navigate to your project's root directory.
- (Optional) Edit
.llm-context/config.json
to add custom ignore patterns. - Run
lc-sel-full
to select files for full content inclusion. - (Optional) Review the selected file list in
.llm-context/curr_ctx.json
. - Run
lc-context
to generate and copy the context to your clipboard. - Paste the generated context into your Claude Project Knowledge or GPT Knowledge.
- Start your conversation with the LLM about your project.
Handling LLM File Requests
When the LLM encounters references to files that weren't included in the initial context, it may request to see their contents. To handle such requests:
- Copy the LLM's file request (typically in a markdown block) to your clipboard.
- Run
lc-clipfiles
to generate the content of the requested files. - Paste the generated file contents back into your chat with the LLM.
This process allows the LLM to access the full content of the requested files for a more comprehensive analysis, without modifying the original context.
Configuration
Customizing Ignore Patterns
You can add custom ignore patterns to additionally exclude specific files or directories from being processed by LLM Context.
- Create a
.llm-context/config.json
file in your project root if it doesn't exist. - Add or modify the
gitignores
key in the JSON file.
The custom ignore patterns should focus on files that are not already ignored by your project's top-level .gitignore but may not be useful for code context, such as media files, large generated files, detailed changelogs, or environment-specific configuration files.
Example:
{
"gitignores": {
"full_files": [
".git",
".gitignore",
".llm-context/",
"*.lock",
"CHANGELOG.md",
"*.log",
"*.svg",
"*.png",
"*.jpg",
"*.jpeg",
"*.gif",
"*.ico",
"*.woff",
"*.woff2",
"*.eot",
"*.ttf",
"*.map"
]
}
}
Reviewing and Editing Selected Files
You can review and manually edit the list of selected files to fine-tune the context provided to the LLM. The .llm-context/curr_ctx.json
file in your project root contains the current selection. This can be useful for checking what's included in the context or for debugging context overflow issues.
Experimental: Handling Larger Repositories
For larger repositories, we're exploring a workflow that combines full file content and file outlines to provide a more comprehensive yet manageable context:
- Full content would be included for key files that require detailed analysis.
- Outlines could be provided for less critical files or those that are too large for full inclusion.
This approach might allow you to provide context for more files without exceeding the LLM's context window limit.
If you wish to experiment with this approach, you can use the lc-sel-outline
command after lc-sel-full
to select files for outline inclusion.
When using this feature, if the AI requests to see the full content of an outlined file, you should use the lc-clipfiles
command in conjunction with the outline. This allows you to provide the complete file content when needed, while still benefiting from the more compact outline in the initial context.
Note: The outlining feature currently supports the following programming languages: C, C++, C#, Elisp, Elixir, Elm, Go, Java, JavaScript, OCaml, PHP, Python, QL, Ruby, Rust, and TypeScript. Files in unsupported languages will not be outlined and will be excluded from the outline selection.
We welcome feedback on this experimental feature and how it might be improved to better handle larger projects.
Feedback and Contributions
If you encounter any issues, have suggestions for improvements, or want to share your experience using the tool, please open an issue on our GitHub repository or submit a pull request with proposed changes.
Acknowledgments
LLM Context has evolved from several projects and influences:
- This project is a successor to LLM Code Highlighter, a TypeScript library developed for use in IDEs like VS Code.
- LLM Code Highlighter was inspired by Aider Chat, particularly its RepoMap functionality.
- The original concept grew out of a project for RubberDuck and was later used for Continue.
- LLM Code Highlighter included functionality for ranking and highlighting tags, based on a translation of Aider Chat's Python code to TypeScript (with the help of Chat-GPT-4). This functionality is not yet implemented in LLM Context.
- The outlining functionality, independently developed in LLM Code Highlighter, has been moved to this project.
- Parts of the code in LLM Context were translated from TypeScript to Python with Claude-3.5-Sonnet's help, bringing the project full circle (Python -> TypeScript -> Python).
- This project currently uses the tree-sitter tag query files from Aider Chat.
We are grateful for the open-source community and the innovations that have influenced this project's development.
I am grateful for the help of Claude-3.5-Sonnet in the development of this project.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the Apache License, Version 2.0. See the LICENSE file for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for llm_context-0.0.11-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4dfc30354690cebfdb379ee13b9631e883b8bb6911ee3073e3a384df3e4e4bd |
|
MD5 | 94b4157ecb74801a8c2f050596c0b223 |
|
BLAKE2b-256 | 4ba3340dfcdefeaa1129619937461a37f1282475080b85736607a770834d209d |