Repomix (Python Version)

repository·main·Indexed 41 days ago

https://github.com/andersonby/python-repomix

A tool for analyzing and summarizing code repositories by packing an entire codebase into a single, AI-friendly file for LLMs like Claude, ChatGPT, and Gemini. Version 0.5.0 features include token counting via tiktoken, Tree-sitter based code compression, security checks using detect-secrets, and support for multiple output styles (plain, markdown, xml, json). It supports remote Git repository processing, output splitting for large codebases, and the generation of Claude Agent Skills.

Tokens
25K
Snippets
71
Records
107
Agent score
50%

What's inside Repomix

  1. Overview of Repomix features

    main

    Repomix is a tool designed to pack entire repositories into a single, AI-optimized file for use with LLMs (Claude, ChatGPT, Gemini).

    Key capabilities include:

    • AI-Optimized Formatting: Structures code for easy LLM processing.
    • Token Counting: Uses tiktoken to provide counts per file and for the whole repo (configure via --token-count-encoding).
    • Git-Aware: Automatically respects .gitignore, .repomixignore, and .ignore files.
    • Security: Uses detect-secrets to prevent sensitive data inclusion.
    • Compression: Multiple modes to reduce output size.
    • Performance: Uses multiprocessing/threading for speed.
    • Robustness: Automatically detects file encodings using chardet.
  2. Repomix core features and capabilities

    main

    Repomix is designed to pack entire repositories into a single, AI-optimized file. Key features include:

    • AI Optimization: Formats code for LLMs (Claude, ChatGPT, Gemini).
    • Token Counting: Provides token counts per file and for the whole repo using tiktoken (configurable via --token-count-encoding).
    • Git Awareness: Automatically respects .gitignore, .repomixignore, and .ignore files.
    • Security: Built-in secret detection using detect-secrets.
    • Code Compression: Multiple modes to reduce output size while preserving context.
    • Multi-directory Support: Process multiple directories at once (e.g., repomix src lib tests).
    • Performance: Uses multi-processing/threading for faster analysis.
    • Encoding Support: Automatically detects file encodings using chardet.
  3. How code compression modes work

    main

    Repomix provides advanced compression to reduce output size while retaining essential information. This is useful for large codebases or when you only need to understand structure/APIs.

    Compression Modes

    1. Interface Mode (keep_interfaces: true):

      • Retains function/class signatures and full type annotations.
      • Retains all docstrings.
      • Replaces implementation details with pass statements.
      • Best for: Generating API documentation or understanding structure.
    2. Signature Mode (keep_signatures: true, keep_interfaces: false):

      • Retains function/class definitions.
      • Retains implementation code.
      • Optionally retains docstrings based on keep_docstrings setting.
      • Best for: Standard compression while maintaining functionality.
    3. Minimal Mode (keep_signatures: false):

      • Removes all function and class definitions.
      • Retains only global variables, imports, and module-level code.
      • Best for: Maximum compression, focusing on configuration and constants.

    Usage Examples

    Generate API documentation (Interface Mode): repomix --config-override '{"compression": {"enabled": true, "keep_interfaces": true}}'

    Compress implementation details (Signature Mode): repomix --config-override '{"compression": {"enabled": true, "keep_interfaces": false, "keep_signatures": true, "keep_docstrings": false}}'

    Extract only configuration (Minimal Mode): repomix --config-override '{"compression": {"enabled": true, "keep_signatures": false}}'

  4. Use Tree-sitter for code compression

    main

    Repomix supports advanced code compression using Tree-sitter, which allows you to reduce token usage while preserving essential code structures. This is useful for fitting large codebases into AI context windows.

    Supported languages include: Python, JavaScript, TypeScript, Go, Java, C, C++, C#, Rust, Ruby, PHP, Swift, and CSS.

  5. How ignore patterns are prioritized

    main

    Repomix uses several methods to exclude files. When multiple methods are used, they are applied in the following priority order (highest to lowest):

    1. ignore.custom_patterns in repomix.config.json
    2. .repomixignore file
    3. .ignore file (if ignore.use_dot_ignore is true)
    4. .gitignore file (if ignore.use_gitignore is true)
    5. Default patterns (if ignore.use_default_ignore is true)

    All patterns use glob syntax similar to .gitignore.

  6. How ignore patterns are applied

    main

    Repomix uses multiple sources for ignore patterns, applied in the following order of priority (highest to lowest):

    1. Custom patterns in repomix.config.json (ignore.custom_patterns).
    2. .repomixignore file in the project root.
    3. .ignore file (if ignore.use_dot_ignore is true).
    4. .gitignore file (if ignore.use_gitignore is true).
    5. Default patterns (if ignore.use_default_ignore is true).

    Configuration Options

    • ignore.custom_patterns: An array of glob patterns in your config file.
    • ignore.use_gitignore: Boolean to enable/disable .gitignore usage.
    • ignore.use_dot_ignore: Boolean to enable/disable .ignore usage.
    • ignore.use_default_ignore: Boolean to enable/disable built-in exclusions (like __pycache__ or .git).

    All patterns use standard glob syntax. Note that binary files are excluded from output but their paths are still listed in the 'Repository Structure' section of the output.

  7. Generate Claude Agent Skills

    main

    Repomix can generate structured reference materials in the Claude Agent Skills format. This creates a directory structure under .claude/skills/<name>/ containing SKILL.md and a references/ folder with summaries, project structure, file contents, and tech stack information.

    Use --skill-generate [name] to create the skill. You can specify a custom directory with --skill-output <path>.

    # Generate skills with auto-detected name
    repomix --skill-generate
    
    # Generate skills with a custom name
    repomix --skill-generate my-project
    
    # Specify output directory directly
    repomix --skill-output ./my-skills-dir
  8. Use Repomix with Docker

    main

    You can run Repomix in an isolated Docker environment. This is useful for avoiding local dependency conflicts and ensuring consistent results across different machines.

    Build the image:

    docker build -t repomix .

    Run on the current directory:

    docker run --rm -v "$(pwd)":/app repomix

    Run with specific options (e.g., Markdown style and custom output):

    docker run --rm -v "$(pwd)":/app repomix --style markdown --output custom-output.md

    Run on a specific project directory:

    docker run --rm -v "/path/to/your/project":/app repomix
  9. Run Repomix using Docker

    main

    You can run Repomix in an isolated environment using Docker. You must mount your project directory to the /app directory inside the container.

    Build the image: docker build -t repomix .

    Run in current directory: docker run --rm -v "$(pwd)":/app repomix

    # Build the Docker image
    docker build -t repomix .
    
    # Run repomix in the current directory
    docker run --rm -v "$(pwd)":/app repomix
    
    # Run with specific options (e.g., markdown style and custom output)
    docker run --rm -v "$(pwd)":/app repomix --style markdown --output custom-output.md
    
    # Run on a specific project path
    docker run --rm -v "/path/to/your/project":/app repomix
  10. Use Repomix with AI tools (Claude, ChatGPT, Gemini)

    main

    After generating a packed file with Repomix, you can upload it to AI assistants to perform various tasks. Depending on the compression mode used during packing, you can tailor your prompts:

    • General Code Review: Use prompts for overall structure, maintainability, and scalability.
    • Documentation: Ask the AI to generate README.md files based on the codebase.
    • Testing: Request unit test generation, including edge cases.
    • Interface Mode: If you used interface mode compression, prompt the AI to review API design and method signatures.
    • Signature Mode: If you used signature mode compression, prompt the AI to analyze architecture and design patterns.
    • Minimal Mode: If you used minimal mode compression, prompt the AI to analyze configuration, constants, and global variables.
    This file contains my entire codebase. Please review the overall structure and suggest any improvements or refactoring opportunities, focusing on maintainability and scalability.
  11. Manage token counts and encoding

    main

    Repomix helps you estimate the size of your codebase in AI tokens.

    Choosing an Encoding

    Use --token-count-encoding to match your target model:

    • o200k_base: Default, used for GPT-4o.
    • cl100k_base: Used for GPT-3.5/4.

    Visualizing Token Distribution

    Use --token-count-tree to see a file tree with token counts. You can provide an optional threshold to only show files with at least $N$ tokens.

    # Use GPT-3.5/4 encoding
    repomix --token-count-encoding cl100k_base
    
    # Show only files with 100 or more tokens
    repomix --token-count-tree 100