Generate AI prompts from Git repositories with file tree structures and content
Project description
Codebase AI Prompt Generator
A tool to scan a Git repository and generate a comprehensive prompt for AI models, including file tree structure, file paths, and content.
Features
- Creates a hierarchical file tree representation of a repository
- Includes file contents formatted for AI prompts
- Customizable file inclusion/exclusion via patterns
- Option to save output to a file or print to console
- Automatically respects local and global .gitignore files
- Cursor IDE integration with one command
- Automatically excludes
.gitdirectories - Installable CLI tool
Installation
# From PyPI (recommended)
pip install codebase-ai-prompt-generator
# From source
git clone https://github.com/DengYiping/codebase-ai-prompt-generator.git
cd codebase-ai-prompt-generator
pip install -e .
Usage
After installation, you can use the codebase-prompt command directly from your terminal:
# Basic usage (scans current directory)
codebase-prompt
# Scan a specific repository
codebase-prompt /path/to/repository
# Exclude specific file patterns
codebase-prompt --exclude "*.log" "*.tmp" ".env"
# Include only specific file patterns
codebase-prompt --include "*.py" "*.js" "*.html"
# Write output to a file
codebase-prompt --output prompt.md
# Show version information
codebase-prompt --version
# Ignore .gitignore files (both local and global)
codebase-prompt --no-gitignore
# Output to Cursor IDE rules directory
codebase-prompt --cursor
# Combine options
codebase-prompt /path/to/repository --exclude "node_modules" "*.pyc" --include "*.py" "*.js" --output prompt.md
Default Exclusions
The tool automatically excludes certain files and directories to keep the output clean and relevant:
.gitdirectory and all its contents (always excluded)- Files matching patterns in
.gitignorefiles (unless--no-gitignoreis used) - Common build artifacts and cache directories (
__pycache__,*.pyc,node_modules, etc.)
These exclusions help reduce noise and keep the generated prompt focused on the actual codebase content.
.gitignore Support
By default, the tool respects both:
- The repository's local
.gitignorefile - The user's global gitignore file (found via
git config --global --get core.excludesfile)
Files matching any pattern in these files will be excluded from the output. To disable this feature, use the --no-gitignore flag.
Cursor IDE Integration
The --cursor flag automatically generates a prompt file at .cursor/rules/entire-codebase.mdc in your repository. This allows Cursor IDE to use your codebase as context when you're working with AI assistance.
To use:
- Navigate to your repository
- Run
codebase-prompt --cursor - The prompt will be available to Cursor IDE
The --cursor flag overrides the --output flag if both are specified.
Example Output
The generated prompt will have the following structure:
# Repository: repo-name
## File Tree Structure
📁 src/
📄 src/main.py
📄 src/utils.py
📁 tests/
📄 tests/test_main.py
📄 README.md
## File Contents
### src/main.py
```python
def main():
print("Hello World")
src/utils.py
def helper():
return "Helper function"
...
## Use Cases
- Generate prompts for AI code assistants to understand your entire codebase
- Create documentation snapshots of your repository
- Share codebase context with AI models for better assistance
- Provide comprehensive context to LLMs for code-related questions
- Integrate with Cursor IDE for better AI-assisted coding
## Development
To set up the development environment:
```bash
# Clone the repository
git clone https://github.com/DengYiping/codebase-ai-prompt-generator.git
cd codebase-ai-prompt-generator
# Create and activate a virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install in development mode
pip install -e .
Publishing to PyPI
This project is configured with GitHub Actions to automatically publish to PyPI when a new release is created:
Automated Release Process
-
Run the release preparation script to update the version:
python scripts/prepare_release.py [major|minor|patch]
This script will:
- Update the version in
codebase_prompt_gen/__init__.py - Create a git commit with the version change
- Create a git tag for the new version
- Update the version in
-
Push the changes and tag to GitHub:
git push origin main && git push origin v0.x.y
-
Create a new GitHub release from the tag
- Go to your repository on GitHub
- Navigate to "Releases"
- Click "Create a new release"
- Select the tag you just pushed
- Add release notes
- Publish the release
-
The GitHub Actions workflow will automatically:
- Build the package
- Publish it to PyPI
Setting up PyPI publishing
To set up publishing, you'll need to:
- Create an account on PyPI
- Generate an API token in your PyPI account settings
- Add the token as a secret in your GitHub repository settings:
- Go to your repository → Settings → Secrets and variables → Actions
- Add a new secret named
PYPI_API_TOKENwith your PyPI token as the value
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file codebase_ai_prompt_generator-0.1.2.tar.gz.
File metadata
- Download URL: codebase_ai_prompt_generator-0.1.2.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a3649a0c25c9ee4c83cbf4764a54a61ed3abffdfca2759709f5b06a93d48779
|
|
| MD5 |
638214377cef7e27b7f9a707db55b63e
|
|
| BLAKE2b-256 |
865bc0bb7f80d132fe5111dc88f60d2befe818a354f98e529fd12cbe90b3752a
|
Provenance
The following attestation bundles were made for codebase_ai_prompt_generator-0.1.2.tar.gz:
Publisher:
publish.yml on DengYiping/codebase-ai-prompt-generator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codebase_ai_prompt_generator-0.1.2.tar.gz -
Subject digest:
1a3649a0c25c9ee4c83cbf4764a54a61ed3abffdfca2759709f5b06a93d48779 - Sigstore transparency entry: 189488443
- Sigstore integration time:
-
Permalink:
DengYiping/codebase-ai-prompt-generator@0ed088492d53bd7889add9e19f6ebcddc2a1e1f8 -
Branch / Tag:
refs/tags/0.1.2 - Owner: https://github.com/DengYiping
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0ed088492d53bd7889add9e19f6ebcddc2a1e1f8 -
Trigger Event:
release
-
Statement type:
File details
Details for the file codebase_ai_prompt_generator-0.1.2-py3-none-any.whl.
File metadata
- Download URL: codebase_ai_prompt_generator-0.1.2-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ccabdc7bf11f6a0e90e688a31d0e37293d41a08e27e7d51d7d73c2d4903edd1f
|
|
| MD5 |
c122350cd3d4884a13621b3591424b06
|
|
| BLAKE2b-256 |
f4a56b0dd3dd173e6ba76e4fdf176a2e98353442472f9132dbd1d43a394ff610
|
Provenance
The following attestation bundles were made for codebase_ai_prompt_generator-0.1.2-py3-none-any.whl:
Publisher:
publish.yml on DengYiping/codebase-ai-prompt-generator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codebase_ai_prompt_generator-0.1.2-py3-none-any.whl -
Subject digest:
ccabdc7bf11f6a0e90e688a31d0e37293d41a08e27e7d51d7d73c2d4903edd1f - Sigstore transparency entry: 189488449
- Sigstore integration time:
-
Permalink:
DengYiping/codebase-ai-prompt-generator@0ed088492d53bd7889add9e19f6ebcddc2a1e1f8 -
Branch / Tag:
refs/tags/0.1.2 - Owner: https://github.com/DengYiping
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0ed088492d53bd7889add9e19f6ebcddc2a1e1f8 -
Trigger Event:
release
-
Statement type: