A tool to help with copying and pasting code context into LLM chats
Project description
LLM Code Context
LLM Code Context is a Python-based tool designed to streamline the process of sharing code context with Large Language Models (LLMs). It allows developers to easily select, format, and copy relevant code snippets and project structure information, enhancing the quality of interactions with AI assistants in coding tasks.
This project was developed with significant input from Claude 3 Opus and Claude 3.5 Sonnet. All of the code that makes it into the repo is human curated (by me ๐, @restlessronin).
Features
- File Selection: Offers a command-line interface for selecting files from your project.
- Intelligent Ignoring: Respects
.gitignore
rules and additional custom ignore patterns to exclude irrelevant files. - Customizable Output: Uses Jinja2 templates for flexible formatting of the selected code context.
- Folder Structure Visualization: Generates a textual representation of your project's folder structure.
- Clipboard Integration: Automatically copies the generated context to your clipboard for easy pasting.
- Configuration Management: Supports user-specific and project-specific configurations for a tailored experience.
Installation
Using pipx (Recommended)
pipx is a tool to help you install and run end-user CLI applications written in Python.
- If you haven't installed pipx yet, follow the installation instructions in the pipx documentation.
- Once pipx is installed, you can install LLM Code Context:
pipx install llm-code-context
This will install LLM Code Context in an isolated environment and make its commands available in your shell.
Usage
LLM Code Context offers various command-line tools, each designed for a specific task. All commands should be run from the root directory of your project, where the .gitignore
file is located. This is crucial because:
- The default file selection process starts from this root directory and selects all files that are not ignored by .gitignore rules.
- It ensures that file selection and ignore rules are applied correctly and consistently.
Here are the main commands:
-
Select files:
lcc-select
-
Generate context from selected files:
lcc-genfiles
-
Generate folder structure diagram:
lcc-dirtree
Typical workflow:
- Navigate to your project's root directory in the terminal.
- Edit the project configuration file
.llm-code-context/config.json
to add any files to the "gitignores" key that should be in git but may not be useful for code context (e.g., "LICENSE" and "poetry.lock", maybe even "README.md"). - Run
lcc-select
to choose the files you want to include in your context. You can look at.llm-code-context/scratch.json
to see what files are currently selected. If you prefer, you can edit the scratch file directly, before the next step. - Run
lcc-genfiles
to process the selected files and copy the formatted context to your clipboard. - Paste the context into your conversation with the LLM.
Configuration
LLM Code Context uses three configuration files:
- User Configuration (located in a platform-specific directory determined by
platformdirs
):
{
"templates_path": "/path/to/your/templates"
}
- Project Configuration (
.llm-code-context/config.json
in your project root). Example:
{
"template": "all-file-contents.j2",
"gitignores": [".git", "LICENSE"]
}
- Scratch Configuration (
.llm-code-context/scratch.json
in your project root). Example:- Keeps track of the currently selected files.
You can edit these files manually or use the provided interfaces to update them.
Project Structure
โโโ llm-code-context.py
โโโ .gitignore
โโโ .llm-code-context
โ โโโ .gitignore
โ โโโ config.json
โโโ LICENSE
โโโ MANIFEST.in
โโโ README.md
โโโ poetry.lock
โโโ pyproject.toml
โโโ src
โ โโโ llm_code_context
โ โโโ __init__.py
โ โโโ config_manager.py
โ โโโ context_generator.py
โ โโโ file_selector.py
โ โโโ folder_structure_diagram.py
โ โโโ git_ignorer.py
โ โโโ initializer.py
โ โโโ pathspec_ignorer.py
โ โโโ template_processor.py
โ โโโ templates
โ โโโ all-file-contents.j2
โโโ tests
โโโ test_pathspec_ignorer.py
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
File details
Details for the file llm_code_context-0.0.5.tar.gz
.
File metadata
- Download URL: llm_code_context-0.0.5.tar.gz
- Upload date:
- Size: 12.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.4 Darwin/23.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7507a9514699e30478d2a3ae355c7a843d02d2ac0916427f943fb6466169f1cc |
|
MD5 | e6ad6d26c3d9e56f877fc17415dd06b2 |
|
BLAKE2b-256 | 3df23e1107d5c9fbc4d2c9b7bed229f4f1bc95bfd9b67fab3d862aa3f491a2b0 |
File details
Details for the file llm_code_context-0.0.5-py3-none-any.whl
.
File metadata
- Download URL: llm_code_context-0.0.5-py3-none-any.whl
- Upload date:
- Size: 13.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.4 Darwin/23.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aaad3ab2a22c16293e16ccb0b177d5b1de664c187e722a2170bb75eb113533eb |
|
MD5 | 38645917d9226f4c5b3faa710c057f5e |
|
BLAKE2b-256 | e02823ba2d6146120eaa4ca7cc8f1e71af608e8811bbc2818a62f6dc55913ad5 |