smart-repomix
v1.0.4
Published
AI-powered wrapper for repomix that intelligently filters unnecessary files
Maintainers
Readme
Smart Repomix
An AI-powered wrapper for repomix that intelligently filters unnecessary files from your codebase using Google's Gemini AI.
What it does
Smart Repomix enhances the standard repomix tool by:
- Running repomix in-memory to scan your entire codebase
- Using AI to analyze which files are unnecessary based on your instruction
- Re-running repomix with intelligent ignore patterns
- Producing a cleaner, more focused output
Installation
Option 1: Use directly with npx (recommended)
npx smart-repomix -I "ignore test files and build artifacts"Option 2: Install globally
npm install -g smart-repomix
smart-repomix -I "ignore test files and build artifacts"Option 3: Install as a dev dependency
npm install --save-dev smart-repomixPrerequisites
- Node.js >= 14.0.0
- A Google Gemini API key (get one here)
npx(comes with npm 5.2+)
Quick Start
For local development:
# Clone/download the package files
git clone <your-repo-url>
cd smart-repomix
npm install
# Set API key
export GEMINI_API_KEY="your-api-key"
# Test locally
node cli.js -I "ignore test files" --dry-runSee QUICKSTART.md for detailed setup instructions.
Configuration
Smart Repomix can be configured through your existing repomix.config.json file:
{
// Your regular repomix config...
"output": {
"filePath": "my-output.xml"
},
// Smart Repomix specific config
"smartRepomix": {
"apiKey": "your-gemini-api-key",
"promptTemplate": "Custom prompt with {{instruction}} and {{codebase}} placeholders"
}
}Configuration Options
smartRepomix.apiKey: Your Gemini API key (alternative to env var or CLI option)smartRepomix.promptTemplate: Custom prompt template with placeholders:{{instruction}}: Will be replaced with your -I instruction{{codebase}}: Will be replaced with the XML codebase content
Custom Prompt Template Example
{
"smartRepomix": {
"promptTemplate": "Analyze this {{codebase}} and identify files to ignore based on: {{instruction}}. Return only comma-separated glob patterns."
}
}Usage
Basic usage
# Uses your repomix.config.json for output settings
npx smart-repomix -I "ignore test files, documentation, and build outputs"
# Or specify output explicitly
npx smart-repomix -I "ignore test files" -o my-output.xmlAdvanced options
# Use a different Gemini model
npx smart-repomix -I "ignore test files" -m gemini-2.5-pro
# Verbose output
npx smart-repomix -I "ignore test files" -v
# Dry run (see what would be ignored without creating output)
npx smart-repomix -I "ignore test files" --dry-run
# Pass API key directly
npx smart-repomix -I "ignore test files" -k "your-api-key"Command Line Options
-I, --instruction <instruction>- Required. Instruction for AI to determine which files to ignore-o, --output <path>- Output file path (defaults to repomix config orrepomix-output.xml)-k, --api-key <key>- Gemini API key (or useGEMINI_API_KEYenv var or config)-m, --model <model>- Gemini model to use (default:gemini-2.5-flash)-v, --verbose- Show verbose output--dry-run- Show what files would be ignored without creating final output
API Key Priority
The API key is resolved in this order:
-kcommand line optionGEMINI_API_KEYenvironment variablesmartRepomix.apiKeyinrepomix.config.json
Example Instructions
Here are some effective instruction examples:
# For sharing code for review
npx smart-repomix -I "ignore test files, build artifacts, and documentation"
# For production code analysis
npx smart-repomix -I "ignore development files, tests, examples, and build outputs"
# For debugging
npx smart-repomix -I "keep only source code and configuration files"
# For documentation
npx smart-repomix -I "ignore node_modules, build directories, and temporary files"How it Works
- Initial Scan: Runs
repomix --stdoutto capture your entire codebase in memory - AI Analysis: Sends the codebase to Gemini with your instruction
- Pattern Generation: AI returns glob patterns for files to ignore
- Filtered Output: Runs
repomixagain with the ignore patterns, respecting your config
Programmatic Usage
You can also use smart-repomix in your Node.js code:
import smartRepomix from 'smart-repomix';
const ignorePatterns = await smartRepomix({
instruction: 'ignore test files and build artifacts',
outputPath: 'output.xml', // optional, uses repomix config if not specified
apiKey: 'your-api-key',
model: 'gemini-2.5-flash',
verbose: true
});
console.log('Ignored patterns:', ignorePatterns);Tips
- Be specific in your instructions for better results
- Use
--dry-runfirst to preview what will be ignored - The
gemini-2.5-flashmodel is fast and works well for most cases - For very large codebases, consider using
gemini-2.5-profor better analysis - Smart Repomix respects your existing
repomix.config.jsonsettings
License
MIT
