A CLI tool to anonymize code using a local LLM before sending to Claude Code or other AI services.
-
macOS/Linux:
curl -fsSL https://ollama.ai/install.sh | sh -
Windows: Download from ollama.ai
-
Start Ollama service:
-
Install a model (in a new terminal):
# Install Llama 3.2 (recommended) ollama pull llama3.2 # Or install other models ollama pull codellama ollama pull llama3.1
-
Install UV (if not already installed):
# macOS/Linux curl -LsSf https://astral.sh/uv/install.sh | sh -
Install LLM Anonymizer:
-
Verify installation:
That's it! The llm-anon command is now available globally.
Development Installation (click to expand)For development or if you want to modify the code:
-
Clone this repository:
git clone https://github.com/ChristianBako/LLM-Anonymizer-.git cd LLM-Anonymizer- -
Install dependencies:
-
Use with uv run:
uv run python -m llm_anon.cli --help
- -o, --output PATH: Output file or directory
- -m, --model TEXT: LLM model to use (default: llama3.2)
- -t, --temperature FLOAT: Temperature for generation (default: 0.1)
- --preserve-comments: Keep original comments
- --preserve-strings: Keep string literals unchanged
- -r, --recursive: Process directories recursively
- -v, --verbose: Show detailed progress
- --validation-config PATH: Path to validation config file with banned strings
- --max-retries INTEGER: Maximum retries for validation failures (default: 3)
- Python (.py)
- JavaScript (.js, .jsx)
- TypeScript (.ts, .tsx)
- Java (.java)
- C/C++ (.c, .cpp, .cc, .cxx, .h, .hpp)
- Rust (.rs)
- Go (.go)
The tool includes a powerful validation system to ensure sensitive information is completely removed from anonymized code.
Create a text file with banned strings (one per line). Comments start with #:
Or create a comprehensive config file:
Pro tip: Start with your company name, domain, and any API keys or internal URLs. Check out examples/ for test files and sample configurations.
- Initial Anonymization: LLM processes code normally
- String Detection: Scans output for banned strings using word boundaries
- Re-prompting: If banned strings found, sends explicit removal instructions
- Retry Logic: Repeats up to --max-retries times until validation passes
- Failure Handling: Reports specific banned strings if validation ultimately fails
- Case-sensitive matching by default
- Word boundary detection prevents false positives
- Progressive prompting gets more explicit with each retry
- Detailed error reporting shows exactly which strings were found
- File Detection: Automatically detects programming language from file extension
- LLM Processing: Sends code to local Ollama model with anonymization prompt
- Validation (if enabled): Checks output against banned strings and re-prompts if needed
- Smart Replacement: Replaces variable names, function names, and identifiers while preserving:
- Code structure and logic
- Control flow
- Data types
- Import statements
- Syntax and formatting
- Use smaller models for faster processing: llama3.2:1b
- Lower temperature (0.1) for more consistent results
- Process files individually for large codebases to avoid timeouts