Skip to main content

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 ๐Ÿ˜‡).

Features

  • File Selection: Offers both command-line and graphical user interfaces 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 applications written in Python.

  1. If you haven't installed pipx yet, follow the installation instructions in the pipx documentation.
  2. 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 provides several command-line entry points for different functionalities:

  1. Select files (CLI):

    lcc-select
    
  2. Select files (GUI):

    lcc-ui-select
    
  3. Generate context from selected files:

    lcc-genfiles
    
  4. Generate folder structure diagram:

    lcc-dirtree
    

Typical workflow:

  1. Run lcc-select or lcc-ui-select to choose the files you want to include in your context.
  2. Run lcc-genfiles to process the selected files and copy the formatted context to your clipboard.
  3. Paste the context into your conversation with the LLM.

Configuration

LLM Code Context uses three configuration files:

  1. User Configuration (~/.llm-context/config.json). Example:
{
  "templates_path": "/path/to/your/templates"
}
  1. Project Configuration (.llm-context/config.json in your project root). Example:
{
  "template": "all-file-contents.j2",
  "gitignores": [".git", "node_modules"],
  "root_path": "/path/to/your/project"
}
  1. Scratch Configuration (.llm-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/
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ llm_code_context/
โ”‚       โ”œโ”€โ”€ __init__.py
โ”‚       โ”œโ”€โ”€ config_manager.py
โ”‚       โ”œโ”€โ”€ context_generator.py
โ”‚       โ”œโ”€โ”€ file_selector.py
โ”‚       โ”œโ”€โ”€ file_selector_ui.py
โ”‚       โ”œโ”€โ”€ folder_structure_diagram.py
โ”‚       โ”œโ”€โ”€ gitignore_parser.py
โ”‚       โ”œโ”€โ”€ pathspec_ignorer.py
โ”‚       โ””โ”€โ”€ template_processor.py
โ”œโ”€โ”€ templates/
โ”‚   โ””โ”€โ”€ all-file-contents.j2
โ”œโ”€โ”€ tests/
โ”‚   โ””โ”€โ”€ test_pathspec_ignorer.py
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ poetry.lock
โ””โ”€โ”€ pyproject.toml

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

llm_code_context-0.0.2.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

llm_code_context-0.0.2-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file llm_code_context-0.0.2.tar.gz.

File metadata

  • Download URL: llm_code_context-0.0.2.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.4 Darwin/23.6.0

File hashes

Hashes for llm_code_context-0.0.2.tar.gz
Algorithm Hash digest
SHA256 480b7a60678955e05abba9c01d0f52869803e18e065002e98e6efd170930eddb
MD5 dea3692057f74232b89cd41f4d5a3054
BLAKE2b-256 a2a1656765e9c3241c1cdde66622241203b8aad32e5329970f5d4c1f53dd1028

See more details on using hashes here.

File details

Details for the file llm_code_context-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for llm_code_context-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 00e84376837d8b94fc05ae0a32a0572b07d9d2bc59453aad2ac1692f218d0ab8
MD5 e7d13121ebed4f8488d8789ecb1a9530
BLAKE2b-256 811720c84061daa6b00809632882f5e93dcb7ed221b6f03337d85d6a11819a3d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page