Skip to content

StevenACoffman/repomix

Repository files navigation

repomix (Go port)

Pack your entire repository into a single, AI-friendly file.

repomix is a Go port of the original repomix (TypeScript) tool. It produces output that is format-compatible with the TypeScript version, so existing repomix workflows and configuration files work without changes.

Features

  • AI-Optimized: Outputs your codebase in a structured format that is easy for LLMs to understand β€” XML by default, matching the TypeScript repomix schema.
  • Multiple output styles: XML (default), Markdown, JSON, and plain text.
  • Git-Aware: Automatically respects .gitignore, .repomixignore, and .ignore files. Sorts files by git change frequency so the most-active files appear last in the context window where LLMs attend most.
  • Security-Focused: Built-in checks detect and exclude files containing secrets β€” API keys, private keys, tokens, database connection strings, and more.
  • Configurable: All options can be set via repomix.config.json in the target directory, with CLI flags taking precedence.
  • Zero runtime dependencies: A single statically-linked binary. No Node.js, Python, or other runtimes required.
  • Multiple directories: Pack several directories in a single invocation.

Quick Start

Install

go install github.com/StevenACoffman/repomix@latest

Or build from source:

git clone https://github.com/StevenACoffman/repomix
cd repomix
go build -o repomix .

Run

Pack the current directory:

repomix pack

This writes repomix-output.xml to the current directory. Send that file to an AI assistant with a prompt like:

This file contains all the files in my repository combined into one.
Please review the code and suggest improvements.

Usage

Basic examples

# Pack the current directory (default: XML output β†’ repomix-output.xml)
repomix pack

# Pack a specific directory
repomix pack path/to/project

# Pack multiple directories
repomix pack src lib tests

# Write to stdout instead of a file
repomix pack --stdout

# Choose output style
repomix pack --style markdown   # β†’ repomix-output.md
repomix pack --style json       # β†’ repomix-output.json
repomix pack --style plain      # β†’ repomix-output.txt

# Specify output file name
repomix pack -o context.xml

# Include only specific files (comma-separated glob patterns)
repomix pack --include "src/**/*.go,**/*.md"

# Add extra ignore patterns
repomix pack -i "**/*_test.go,testdata/**"

# Skip files larger than 1 MB
repomix pack --max-file-size 1

# Add line numbers to every file in the output
repomix pack --output-show-line-numbers

# Strip empty lines from file contents
repomix pack --remove-empty-lines

# Truncate long base64 strings (reduces size for repos with embedded images)
repomix pack --truncate-base64

Subcommands

Subcommand Description
pack Pack a repository into a single file (main command)
version Print the build version

All flags

Flag Short Default Description
--output -o auto Output file path
--style xml Output style: xml, markdown, json, plain
--include all files Comma-separated glob patterns of files to include
--ignore -i Comma-separated extra ignore patterns
--stdout false Write output to stdout instead of a file
--remove-empty-lines false Remove empty lines from file contents
--output-show-line-numbers false Prefix each line with its line number
--header-text Custom text to include in the output header
--instruction-file-path Path to a file whose contents are appended as instructions
--max-file-size 0 (no limit) Skip files larger than this size in MB
--truncate-base64 false Truncate long base64-encoded strings
--parsable-style false Escape special XML/HTML characters for strictly valid output
--no-file-summary false Omit the file summary section
--no-directory-structure false Omit the directory tree section
--no-files false Omit file contents (directory structure only)
--no-security-check false Disable security checking
--no-default-patterns false Disable built-in ignore patterns
--no-gitignore false Do not read .gitignore files
--no-dot-ignore false Do not read .ignore files
--no-git-sort-by-changes false Disable sorting files by git change frequency
--git-sort-max-commits 100 Maximum commits to scan for git change sorting

Configuration File

Place a repomix.config.json file in the target directory to set defaults. CLI flags always override file settings. A malformed config file is reported as an error β€” repomix will not silently fall back to defaults.

{
  "output": {
    "filePath": "repomix-output.xml",
    "style": "xml",
    "fileSummary": true,
    "directoryStructure": true,
    "files": true,
    "removeEmptyLines": false,
    "showLineNumbers": false,
    "truncateBase64": false,
    "parsableStyle": false,
    "git": {
      "sortByChanges": true,
      "sortByChangesMaxCommits": 100
    }
  },
  "include": [],
  "ignore": {
    "useGitignore": true,
    "useDotIgnore": true,
    "useDefaultPatterns": true,
    "customPatterns": []
  },
  "security": {
    "enableSecurityCheck": true
  },
  "input": {
    "maxFileSize": 52428800
  }
}

Note: input.maxFileSize is in bytes (e.g. 52428800 = 50 MB). The CLI flag --max-file-size is in MB.

This schema is compatible with the TypeScript repomix repomix.config.json format. Unknown fields from the TypeScript schema (e.g. compress, tokenCount) are silently ignored.

Output Formats

XML (default)

TypeScript-compatible format. Starts with a plain-text generation header, followed by <file_summary>, <directory_structure>, and <files> sections.

This file is a merged representation of the entire codebase, combined into a
single document by repomix.

<file_summary>
This section contains a summary of this file.

<purpose>
This file contains a packed representation of the entire repository's contents.
...
</purpose>
...
</file_summary>

<directory_structure>
β”œβ”€β”€ cmd/
β”‚   └── pack/
β”‚       β”œβ”€β”€ pack.go
β”‚       └── output.go
└── main.go
</directory_structure>

<files>
This section contains the contents of the repository's files.

<file path="main.go">
package main
...
</file>

</files>

Use --parsable-style to XML-escape file contents for strictly valid XML parsing.

Markdown

# File Summary

## Purpose
...

# Directory Structure

` ` `
β”œβ”€β”€ cmd/
β”‚   └── pack/
└── main.go
` ` `

# Files

## File: main.go
` ` `go
package main
...
` ` `

JSON

{
  "fileSummary": {
    "generationHeader": "This file is a merged representation...",
    "purpose": "...",
    "fileFormat": "...",
    "usageGuidelines": "...",
    "notes": "..."
  },
  "directoryStructure": "β”œβ”€β”€ cmd/\nβ”‚   └── pack/\n└── main.go\n",
  "files": {
    "main.go": "package main\n..."
  }
}

File keys within "files" are sorted alphabetically.

Plain text

This file is a merged representation of the entire codebase...

================================================================
File Summary
================================================================
...

================================================================
Directory Structure
================================================================
β”œβ”€β”€ cmd/
└── main.go

================================================================
Files
================================================================

================
File: main.go
================
package main
...

================================================================
End of Codebase
================================================================

Ignore Patterns

Patterns are applied in this priority order (highest to lowest):

  1. CLI --ignore patterns and customPatterns from config file
  2. .repomixignore in the target directory
  3. .ignore files (disable with --no-dot-ignore)
  4. .gitignore files (disable with --no-gitignore)
  5. Built-in default patterns (disable with --no-default-patterns)

The built-in patterns exclude version control directories, dependency directories (node_modules, vendor, target), build outputs, lock files for major ecosystems (Node.js, Python, Rust, Ruby, Go, PHP, Elixir, Haskell), editor files, OS files, and repomix output files themselves.

You can also create a .repomixignore file in the target directory using the same syntax as .gitignore.

Pattern syntax

All patterns support gitignore-style ** glob syntax. Patterns without a slash match against each path component individually (filename-only match). Patterns with a slash match against the full relative path.

# Match any file named exactly "secrets.json" anywhere in the tree
secrets.json

# Match only at the repo root
config/local.yaml

# Match any path under any "generated" directory
**/generated/**

# Match all Go test files anywhere
**/*_test.go

Security Checks

When the security check is enabled (default), files are scanned before inclusion. Files are excluded if:

The filename matches a sensitive pattern, such as:

  • .env, *_rsa, *.pem, *.key, *.p12, *.pfx, *.keystore, *.jks

The content matches a secret pattern, such as:

  • API keys: api_key: "abc123..."
  • Access/auth tokens: access_token = "...", token = "..."
  • AWS credentials: AKIA... key IDs, aws_secret = "..."
  • GitHub tokens: ghp_...
  • Private keys: -----BEGIN RSA PRIVATE KEY-----
  • Database URLs: postgres://user:pass@host, mongodb://user:pass@host
  • Passwords, secrets: password = "...", secret = "..."

Excluded files are listed on stderr with the pattern that triggered the match. To disable:

repomix pack --no-security-check

Or in config:

{ "security": { "enableSecurityCheck": false } }

Custom Instructions

Append a custom instruction block to the output by pointing to a Markdown file:

repomix pack --instruction-file-path repomix-instruction.md

Or in repomix.config.json:

{ "output": { "instructionFilePath": "repomix-instruction.md" } }

Example repomix-instruction.md:

## Context

This is a Go CLI tool using the ff/v4 flag library.
When suggesting changes, follow standard Go conventions and keep packages small.

The instruction content is appended as an <instruction> block (XML), # Instruction section (Markdown/plain), or "instruction" key (JSON).

Git-Based File Sorting

By default, repomix uses git log to count how many commits modified each file (deletions are excluded from the count), then sorts files so that the most-frequently-changed files appear last. This exploits the "lost in the middle" effect in LLMs β€” content at the end of the context window receives more attention than content in the middle.

Disable with --no-git-sort-by-changes, or cap the commit scan depth with --git-sort-max-commits (default: 100).

Directory Structure

repomix/
β”œβ”€β”€ main.go                  # Entry point
β”œβ”€β”€ cmd/
β”‚   β”œβ”€β”€ cmd.go               # Command dispatcher (routes args to subcommands)
β”‚   β”œβ”€β”€ root/
β”‚   β”‚   └── root.go          # Shared root config (I/O writers and root command)
β”‚   β”œβ”€β”€ pack/
β”‚   β”‚   β”œβ”€β”€ pack.go          # pack subcommand: flag parsing, exec wiring
β”‚   β”‚   β”œβ”€β”€ types.go         # Shared struct types (outputCfg, contentInfo, …)
β”‚   β”‚   β”œβ”€β”€ config.go        # repomix.config.json loading
β”‚   β”‚   β”œβ”€β”€ search.go        # File discovery, include/ignore filtering
β”‚   β”‚   β”œβ”€β”€ collect.go       # File reading from disk
β”‚   β”‚   β”œβ”€β”€ process.go       # Content transformation (line numbers, base64, …)
β”‚   β”‚   β”œβ”€β”€ output.go        # Output rendering (XML, Markdown, JSON, plain)
β”‚   β”‚   β”œβ”€β”€ glob.go          # Double-star glob matching
β”‚   β”‚   β”œβ”€β”€ ignore.go        # Built-in default ignore patterns
β”‚   β”‚   β”œβ”€β”€ git.go           # Git change-count sorting
β”‚   β”‚   └── security.go      # Security pattern checks
β”‚   └── version/
β”‚       └── version.go       # version subcommand
└── go.mod

License

MIT

About

πŸ“¦ Repomix is a tool that packs your entire repository into a single, AI-friendly file. Perfect for when you need to feed your codebase to Large Language Models (LLMs) or other AI tools like Claude, ChatGPT, DeepSeek, Perplexity, Gemini, Gemma, Llama, Grok, and more.

Resources

License

Stars

2 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages