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.
- 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.ignorefiles. 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.jsonin 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.
go install github.com/StevenACoffman/repomix@latestOr build from source:
git clone https://github.com/StevenACoffman/repomix
cd repomix
go build -o repomix .Pack the current directory:
repomix packThis 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.
# 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| Subcommand | Description |
|---|---|
pack |
Pack a repository into a single file (main command) |
version |
Print the build version |
| 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 |
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.maxFileSizeis in bytes (e.g.52428800= 50 MB). The CLI flag--max-file-sizeis 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.
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.
# File Summary
## Purpose
...
# Directory Structure
` ` `
βββ cmd/
β βββ pack/
βββ main.go
` ` `
# Files
## File: main.go
` ` `go
package main
...
` ` `
{
"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.
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
================================================================
Patterns are applied in this priority order (highest to lowest):
- CLI
--ignorepatterns andcustomPatternsfrom config file .repomixignorein the target directory.ignorefiles (disable with--no-dot-ignore).gitignorefiles (disable with--no-gitignore)- 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.
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
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-checkOr in config:
{ "security": { "enableSecurityCheck": false } }Append a custom instruction block to the output by pointing to a Markdown file:
repomix pack --instruction-file-path repomix-instruction.mdOr 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).
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).
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
MIT