Repomix

repository·main·Indexed 11 days ago

https://github.com/yamadashy/repomix

A tool to pack repository contents into a single, AI-friendly file (such as XML, Markdown, or JSON) for use with Large Language Models (LLMs). It features a CLI, browser extension, and web interface, offering token counting, Git-aware filtering, and Tree-sitter based code compression to reduce token counts while preserving structure. Supports local and remote repositories, including Git logs and diffs.

Tokens
65.8K
Snippets
216
Records
315
Agent score
97%

What's inside Repomix

  1. Core Features of Repomix

    main

    Repomix provides several features designed to optimize codebases for Large Language Models (LLMs):

    • AI-Optimized: Formats codebases for easy AI processing.
    • Token Counting: Provides token counts for individual files and the entire repository to help manage LLM context limits.
    • Simple to Use: Single-command repository packing.
    • Customizable: Configuration options to include or exclude specific files.
    • Git-Aware: Automatically respects .gitignore, .ignore, and .repomixignore files.
    • Security-Focused: Uses Secretlint to detect and exclude sensitive credentials.
    • Code Compression: The --compress option uses Tree-sitter to extract key code elements, reducing token counts while preserving structure.
  2. What is Repomix and how does it work?

    main
    Repomix is a tool that packs the contents of a software repository into a single file, making it easier for AI systems to analyze and process the codebase. It supports various output formats (plain text, XML, Markdown), allows ignoring files based on configurable patterns, and performs security checks to exclude potentially sensitive information.
  3. Compress code using Tree-sitter

    main

    The --compress option uses Tree-sitter to perform intelligent code extraction. It retains essential structural information (like class and function signatures) while stripping out implementation details to reduce token counts.

    This is an experimental feature. You can also control compression levels per-glob in your repomix.config.json using the output.patterns key.

    repomix --compress
  4. How custom instructions appear in the output

    main

    When you use instructionFilePath, the content of your specified markdown file is wrapped in an <instruction> XML tag within the Repomix output file. This allows AI models to clearly distinguish between the repository source code and the high-level instructions provided for the analysis task.

    <instruction>
    # Repository Instructions
    
    This repository contains the source code for the Repomix tool. Please follow these guidelines when analyzing the code:
    
    1. Focus on the core functionality in the `src/core` directory.
    2. Pay special attention to the security checks in `src/core/security`.
    3. Ignore any files in the `tests` directory.
    </instruction>
  5. Enable Sandbox Mode for the MCP Server

    main

    By default, the MCP server can access any path the host user can. To restrict the server's file tools to a specific workspace directory (defense in depth), use the --sandbox flag.

    Behavior in Sandbox Mode:

    • Path Relativity: All paths must be relative to the workspace root. Absolute paths, ~, .., and Windows drive/UNC paths are refused. Paths resolving outside the root are dropped.
    • Restricted Toolset: Only read-only, root-confined tools are registered: pack_codebase, read_repomix_output, grep_repomix_output, file_system_read_file, and file_system_read_directory. Remote packing and network-reaching tools are disabled.
    • Note: --sandbox only affects the MCP server and has no effect when running Repomix without the --mcp flag.
    # Confine to the current working directory
    repomix --mcp --sandbox
    
    # Confine to a specific directory
    repomix --mcp --sandbox path/to/project
  6. Technical specifications of the Repomix extension

    main

    The Repomix extension is built with the following technical foundations:

    • Manifest V3: Uses the latest browser extension specification.
    • Content Scripts: Used to inject the Repomix button directly into GitHub's UI.
    • Internationalization: Supports English and Japanese.
    • Cross-browser: Compatible with Chrome, Firefox, and Edge.
    • Privacy: Does not collect data or track behavior; permissions are limited to github.com only.
  7. How remote configuration trust and pinning works

    main

    When you opt-in to remote configurations in an interactive terminal, Repomix provides a confirmation prompt with several choices:

    • Yes, once: Trust the configuration for the current run only.
    • Yes, and don't ask again for this repository: Stores a content-pinned marker in $TMPDIR/repomix/trusted-remotes/.
    • No (default): Abort without loading the config.

    Content Pinning

    The "don't ask again" decision is content-pinned. Repomix records a hash of the configuration file. If the file content changes, the hash will no longer match, and Repomix will prompt you for confirmation again (similar to direnv allow).

    Warning on Scope: The hash only covers the entry configuration file. It does not cover files imported by a .ts/.js config or external scripts invoked via input.processors. Treat "don't ask again" as trust in the entire repository, not just the single file.

    Prompt Behavior Exceptions

    • --force: Automatically trusts the config without asking (prints a notice to stderr).
    • Non-interactive shells (CI/Pipes): Automatically trusts the config to preserve automation (prints a notice to stderr).
    • Absolute --config: The cloned repository's config is ignored, so no prompt is shown.
    • Redirected stdout: If stdout is redirected or --stdout is used, the prompt cannot be displayed; Repomix will report an error instead of silently trusting the config.
  8. Use JSON format for programmatic processing

    main

    The JSON format provides a structured, machine-readable representation of the repository. It is ideal for building tools, integrating with web services, or performing data analysis. The schema includes fileSummary, userProvidedHeader, directoryStructure, files (a map of paths to content), and instruction.

    {
      "fileSummary": {
        "generationHeader": "...",
        "purpose": "...",
        "fileFormat": "...",
        "usageGuidelines": "...",
        "notes": "..."
      },
      "userProvidedHeader": "...",
      "directoryStructure": "...",
      "files": {
        "src/index.js": "// File contents here"
      },
      "instruction": "..."
    }
  9. How Repomix Watch Mode works

    main

    Repomix watch mode follows these operational principles:

    • Initial pack: Performs a full pack of the codebase before entering watch mode and reports the number of files being watched.
    • Change detection: Triggers a re-pack for new, changed, or deleted files.
    • Debouncing: To prevent excessive rebuilding during rapid changes (like branch switching or bulk saves), Repomix waits 300 ms after the last detected change before initiating a re-pack.
    • Timestamps: Each rebuild is logged with a timestamp (Rebuilt at HH:MM:SS) to confirm the output is current.
  10. Data privacy for the Repomix CLI Tool

    main

    The Repomix CLI tool is designed for privacy and local execution. It does not collect, transmit, or store any user data, telemetry, or repository information.

    Network Usage:

    • The tool operates fully offline after installation.
    • An internet connection is only required for installation (via npm/yarn), using the --remote flag to process remote repositories, or when manually checking for updates.

    Security:

    • Because all processing is performed locally on your machine, it is safe for use with private and internal repositories.