Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

2 Commits

Repository files navigation

Code2LLM CLI Tool

A utility for generating LLM-friendly context files from codebases with intelligent filtering and structure visualization.

Features

  • Recursive directory traversal
  • Gitignore-style pattern matching
  • File size limits
  • Visual directory tree with ignored/size-exceeded annotations
  • Markdown output with syntax highlighting
  • Context description integration

Installation

pip install pathspec

Usage

python code2llm.py [OPTIONS]

Options

FlagDescriptionDefault
--target-dirDirectory to process. (current dir)
--ignore-filePath to ignore rules file.context.ignore
--outputOutput file pathcontext.md
--max-sizeMaximum file size in bytes102400 (100KB)
--context-filePath to optional context description fileNone

Example Commands

  1. Basic usage:

    python code2llm.py
  2. Process specific directory with custom ignore rules:

    python code2llm.py --target-dir ./src --ignore-file .custom-ignore
  3. Generate output with 2MB size limit and project description:

    python code2llm.py --max-size 2097152 --context-file project-info.md

.context.ignore Example

# Common ignore patterns*.env*.log*.bin*.hex*.pdf*.jpg*.png*.zip.DS_Store# Directoriesnode_modules/
__pycache__/
.vscode/
dist/
build/

Output Structure

  1. Context Overview (optional):
    Contains content from --context-file

  2. Codebase Structure:
    Visual directory tree showing all files with ignored/size-exceeded annotations

  3. File Contents:
    All included files with syntax-highlighted content

Best Practices

  • Use --context-file to provide architectural overview
  • Keep generated files under 1MB for chat-based LLMs
  • Regularly update .context.ignore as project evolves
  • Combine with manual context descriptions for best results

About

A simple python tool for generating human readable context to pass to an LLM.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages