Copy any repository into the clipboard. And get the token count.
Project description
repo2string
TLDR: "Help! I need to feed my entire codebase to ChatGPT!"
pip install repo2string
cd your/project/path
r2s # That's it! Your entire codebase is now in your clipboard 📋
repo2string is a tool that helps you prepare your codebase for large language models (LLMs) like ChatGPT. In CLI mode, it automatically processes all relevant files in your project, excluding common build artifacts and respecting .gitignore. For more control, the UI mode lets you interactively select specific files and folders while tracking token counts. Either way, the result is copied to your clipboard, ready to be pasted into your favorite LLM.
Features:
- Recursively traverse directories.
- Skip files listed in
.gitignore(if present) or skip only.gitif no.gitignoreexists. - Skip common directories like build outputs, dependencies, and IDE files (see default exclusions).
- Generate and include a file tree, making it easy to understand the codebase structure.
- Include the contents of all non-ignored files.
- Copy all text to your clipboard automatically.
- Token counting: Displays the token count of the entire prompt.
- Verbose mode (
-vor--verbose): Also prints the token counts per file, sorted from highest to lowest. - Interactive UI (
--ui): Opens a lightweight web interface to select exactly which files and folders to include.
Installation
You can install repo2string directly from PyPI:
pip install repo2string
Or install from source:
git clone https://github.com/szulcmaciej/repo2string.git
cd repo2string
pip install .
Usage (CLI Mode)
repo2string [PATH] [--verbose]
Or use the shorter alias:
r2s [PATH] [--verbose]
The CLI mode processes all relevant files in the directory (excluding those matched by .gitignore and default exclusions). Use this when you want to quickly copy the entire codebase.
PATHis optional; defaults to.(current directory).--verboseor-vprints a token-count summary per file (descending).
Example:
r2s /path/to/myproject --verbose
For example, if you're in your project directory:
r2s .
# Or simply:
r2s
You will see console output summarizing the total token count, plus a per-file token breakdown if in verbose mode. The entire text is copied to your clipboard.
Usage (UI Mode)
If you need to select specific files or folders to include:
r2s [PATH] --ui
This opens a lightweight web interface in your default browser. The UI runs on a local Flask server - no data ever leaves your machine, and the server automatically shuts down when you're done.
This opens an interactive interface where you can:
- See a tree view of all files in the repository
- Select/deselect individual files or entire folders
- Search for specific files
- See token counts for each file and selection
- Copy only the selected files to clipboard
The UI is particularly useful when:
- You want to exclude certain files or folders
- You need to stay under a token limit
- You want to focus on specific parts of the codebase
When done, click "Copy to Clipboard" to copy the selected files and close the UI.
Default Exclusions
The tool automatically excludes common directories and files that typically don't need to be included in the LLM context:
- Version control:
.git/ - Cache directories:
**/.*cache/,**/__pycache__/ - Build outputs:
**/build/,**/dist/,**/target/,**/bin/,**/obj/,**/out/ - Dependencies:
**/node_modules/,**/vendor/,**/package-lock.json - IDE files:
**/.idea/,**/.vscode/,**/.vs/ - Environment:
**/.env*/,**/venv/
These are in addition to any patterns specified in your .gitignore file.
Now you can paste the combined repo data into ChatGPT or another LLM interface to work on your code with maximum context.
Development Setup
To set up the development environment:
-
Clone the repository:
git clone https://github.com/szulcmaciej/repo2string.git cd repo2string
-
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
To run tests manually:
pytest
Release Process
The release process is fully automated through a chain of GitHub Actions:
- When you push to
master, the CI workflow runs tests and linting - If CI passes and the version in
pyproject.tomlwas bumped:- A new GitHub release is created automatically
- Release notes are generated from commit messages
- When the release is published:
- The package is automatically built and published to PyPI
- Using trusted publishing for enhanced security
No manual intervention is needed beyond pushing your changes with a version bump.
License
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 repo2string-0.3.5.tar.gz.
File metadata
- Download URL: repo2string-0.3.5.tar.gz
- Upload date:
- Size: 17.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
949f49a92c368b6fc29f2c5ee311e33238e1c6438e8e6960dd881bafc7e48853
|
|
| MD5 |
b02eb29f56c123bb9f1053c822518317
|
|
| BLAKE2b-256 |
5c72e9b696d8612f9482ac81e07c00c6c9bf6e9d93b1ef4e93ab03eeca492d0e
|
File details
Details for the file repo2string-0.3.5-py3-none-any.whl.
File metadata
- Download URL: repo2string-0.3.5-py3-none-any.whl
- Upload date:
- Size: 13.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07398793ec5b8a4d857c44f8e2bb1e0f6ad445d11679e2e527debddc7e69748f
|
|
| MD5 |
90e304a68bd3de8a1fcf77816f7fc6cd
|
|
| BLAKE2b-256 |
6361eb6e05696e8bfdf4bd6e8d34c20ec1086baa30e075a31826d2ed49aae01b
|