A Python utility for generating .cursorrules
files by combining global and language-specific cursor rules.
- Combines global cursor rules with language-specific rules
- Supports multiple programming languages
- Automatic backup of existing rules
- List available language configurations
- Configurable via YAML configuration
- Verbose logging support
- Clone the repository:
git clone https://github.com/draeician/crules.git
cd crules
- Install using pipx: (much better than doing pip install .)
pipx install .
NOTE: uninstall with pipx uninstall crules or
Note: If you encounter an "externally-managed-environment" error, you have two options:
- Recommended: Create and use a virtual environment:
python3 -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate pip install . ```us- Alternative: Use the
--break-system-packages
flag (not recommended):This is not recommended as it may interfere with system Python packages.pip install . --break-system-packages
The default configuration file is located at ~/.config/Cursor/cursor-rules/config.yaml
:
global_rules_path: "~/.config/Cursor/cursor-rules/cursorrules"
language_rules_dir: "~/.config/Cursor/cursor-rules/lang_rules"
delimiter: "\n# --- Delimiter ---\n"
backup_existing: true
~/.config/Cursor/cursor-rules/
├── config.yaml
├── cursorrules
└── lang_rules/
├── cursor.python
├── cursor.javascript
└── cursor.<language>
Generate a .cursorrules
file for one or more languages:
# Single language
python -m crules python
# Multiple languages
python -m crules python javascript rust
View all available language configurations:
python -m crules --list
Example output:
Available language rules:
- python (cursor.python)
- javascript (cursor.javascript)
- rust (cursor.rust)
# Force overwrite existing .cursorrules file
python -m crules -f python
# Enable verbose output
python -m crules -v python
# Show help
python -m crules --help
languages
: One or more language identifiers-f, --force
: Force overwrite of existing files-v, --verbose
: Enable verbose output-l, --list
: List available language rules-s, --setup
: Create necessary directories and files-h, --help
: Show help message
Before using crules, run the setup command to create necessary directories and files:
python -m crules --setup
This will create:
- Configuration directory:
~/.config/Cursor/cursor-rules/
- Language rules directory:
~/.config/Cursor/cursor-rules/lang_rules/
- Global rules file:
~/.config/Cursor/cursor-rules/cursorrules
- Default config file:
~/.config/Cursor/cursor-rules/config.yaml
The generated .cursorrules
file combines:
- Global rules from the
cursorrules
file - Language-specific rules from
cursor.<language>
files - Uses a configurable delimiter between sections
Example structure:
# Global Rules
<global rules content>
# --- Delimiter ---
# Rules for python
<python rules content>
# --- Delimiter ---
# Rules for javascript
<javascript rules content>
- Python 3.9+
- PyYAML
- Click
crules/
├── src/
│ └── crules/
│ ├── __init__.py
│ ├── __main__.py
│ ├── cli.py
│ ├── config.py
│ └── file_ops.py
├── pyproject.toml
└── README.md
- Clone the repository
- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install development dependencies:
pip install -e ".[dev]"
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.