Skip to content

Generate Markdown representations of your codebase to provide context for Large Language Models (LLMs). Improve LLM interactions (like ChatGPT) by providing accurate project context. Enhance code analysis, prompt engineering, and AI-driven development. For developers using LLMs in their workflow.

License

Notifications You must be signed in to change notification settings

nt9142/code-context-llm

Repository files navigation

Code Context LLM visualization

Code Context LLM

npm version License: MIT Downloads Cross-Platform

Generate a Markdown representation of your project's file structure to provide valuable context for Large Language Models (LLMs) like ChatGPT, enhancing code analysis, prompt engineering, and AI-driven development.

Screenshot

Interactive CLI Screenshot

Quick start: npx code-context-llm

Table of Contents

Introduction

Code Context LLM bridges the gap between your codebase and Large Language Models (LLMs). Without proper context, LLMs might hallucinate file structures or offer irrelevant suggestions, impacting developer productivity and code quality.

By generating a comprehensive Markdown outline of your project's directory tree, this tool empowers developers to enhance prompt engineering, improve AI-assisted code navigation, and facilitate code understanding for AI models. Ensure AI interactions are accurate, relevant, and aligned with your project's architecture.

Features

  • 🔒 Secure Content Redaction: Automatically redacts sensitive information like API keys, passwords, and credentials, allowing safe sharing of project structures. Learn more about our security measures.
  • 🧠 LLM Context Generation: Provides accurate project context for improved LLM prompts, enhancing AI responses.
  • 📂 Respects .gitignore: Excludes files and directories specified in your .gitignore, keeping your context clean.
  • 🖥️ Interactive React Ink UI: A keyboard-driven terminal UI for selecting folders and reviewing exclusions.
  • 🎯 Override Exclusions: Review items excluded by .gitignore or defaults and include them selectively.
  • 📝 Markdown Output: Produces a readable and structured Markdown file for easy sharing and documentation.

Installation

Quick Start with npx

Get started instantly without installing:

npx code-context-llm

Global Installation

Install the package globally to use it anytime:

npm install -g code-context-llm

Usage

Interactive Mode (React Ink)

Run:

npx code-context-llm

You'll be guided through:

  • Selecting which top-level folders to include.
  • Reviewing excluded items (from .gitignore and default skips) and choosing any to include.
  • Confirming to generate the Markdown file (default: ProjectStructure.md).

Keyboard controls:

  • ↑/↓: Move cursor
  • ←/→: Collapse/Expand directories
  • Space: Toggle selection
  • a: Toggle select all
  • Enter: Continue/confirm
  • q or Esc: Quit

Notes:

  • Dot-prefixed files and directories are excluded by default, but you can include them during the review step.

Command-Line Options

  • [root] (positional): Root directory to process (default: .). Examples:
    • npx code-context-llm .
    • npx code-context-llm ./some-folder
  • -o, --output-file <filename>: Name of the output Markdown file (default: ProjectStructure.md).
  • -p, --project-path <path>: Deprecated; use the positional [root] argument instead.
  • -h, --help: Display help information.
  • -V, --version: Display the version number.

Use Cases

  • LLM Prompt Engineering: Enhance code summaries and refactoring tasks by providing LLMs with accurate project context, potentially saving up to 50% of development time.
  • Codebase Documentation: Automatically generate a Markdown outline of your project's architecture, reducing documentation effort by up to 70%.
  • AI-Assisted Development: Improve the accuracy of AI-powered code suggestions and bug detection by offering context about file relationships.
  • Team Collaboration: Share project structures with team members to improve onboarding and facilitate code reviews.
  • Codebase Summarization: Create summaries of large codebases for reviews or audits, helping you quickly understand unfamiliar projects.

Example Output

Here's a snippet of the generated Markdown:

# Project Structure for /path/to/your/project

- **src/**
  - **components/**
    - Header.js (1.2 KB)
      - Content preview:
        ```javascript
        import React from "react";
        // Header component
        const Header = () => {
          return <header>Welcome to My Project</header>;
        };
        export default Header;
        ```
    - Footer.js (800 bytes)
  - **utils/**
    - helpers.js (2.5 KB)
- **package.json** (1.1 KB)
  - Content preview:
    ```json
    {
      "name": "my-project",
      "version": "1.0.0",
      "dependencies": {
        "react": "^17.0.2"
      }
    }
    ```

This structured overview helps LLMs understand your project's architecture, improving code analysis and AI interactions.

Security

Your project's security is our priority. Code Context LLM automatically redacts sensitive information such as API keys, passwords, credentials, and other secrets from code previews. We use pattern matching to identify and replace sensitive data with [REDACTED]. However, we strongly recommend that you review the generated Markdown file yourself to ensure that no sensitive information is included before sharing it.

Contributing

Contributions are welcome! If you have suggestions or find issues, please:

  • Open an issue.
  • Submit a pull request.
  • Share your ideas in the discussions section.

Please see our contribution guidelines for more details.

License

This project is licensed under the MIT License.

Support

If you find this project helpful:

  • Star this repository on GitHub!
  • 🗣 Spread the word by sharing with your colleagues and friends.
  • 💬 Share your feedback and experiences.

Keywords: LLM context, Code Understanding for AI, Prompt Engineering Tools, Codebase Documentation for LLMs, AI-Assisted Code Navigation, Improve LLM Prompts, Code Context, Markdown, Project Structure, Codebase Summarization, AI, Machine Learning, Code Analysis, Documentation Generator, CLI Tool, Developer Tools.

About

Generate Markdown representations of your codebase to provide context for Large Language Models (LLMs). Improve LLM interactions (like ChatGPT) by providing accurate project context. Enhance code analysis, prompt engineering, and AI-driven development. For developers using LLMs in their workflow.

Resources

License

Stars

Watchers

Forks

Packages

No packages published