Skip to main content

Copy any repository into the clipboard. And get the token count.

Project description

repo2string

PyPI - Version Python Versions License: MIT Downloads CI codecov

TLDR: "Help! ChatGPT needs to see my code!"

Yeet your entire codebase into clipboard:

pip install repo2string
cd your/project/path
r2s  # Yoink! Your entire codebase is now in your clipboard 📋

Token limit got you down? Cherry-pick your files:

r2s -s  # Opens a nice UI for file selection 🎯

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 file selection UI 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 .git if no .gitignore exists.
  • 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 (uses the gpt-4o/o1 tokenizer)
  • Verbose mode (-v or --verbose): Also prints the token counts per file, sorted from highest to lowest.
  • File selection UI (-s or --select): 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

You can use either the full command repo2string or its shorter alias r2s.

CLI Mode

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.

r2s [PATH] [--verbose]
  • PATH is optional; defaults to current directory
  • --verbose or -v shows token counts per file

Example:

r2s                           # Copy current directory
r2s /path/to/project         # Copy specific directory
r2s -v                     # Show token counts per file

File Selection UI

Need more control? The file selection UI lets you choose specific files and folders while tracking token counts.

r2s [PATH] --select  # or -s

This opens a local web interface where you can:

  1. Browse the file tree
  2. Select/deselect files and folders
  3. Search for specific files
  4. Monitor token counts
  5. Copy only what you need

Selection Mode Screenshot

The UI runs locally - no data leaves your machine, and the server shuts down automatically when you're done.

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.

Development Setup

To set up the development environment:

  1. Clone the repository:

    git clone https://github.com/szulcmaciej/repo2string.git
    cd repo2string
    
  2. 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:

  1. When you push to master, the CI workflow runs tests and linting
  2. If CI passes and the version in pyproject.toml was bumped:
    • A new GitHub release is created automatically
    • Release notes are generated from commit messages
  3. 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

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

repo2string-0.4.2.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

repo2string-0.4.2-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file repo2string-0.4.2.tar.gz.

File metadata

  • Download URL: repo2string-0.4.2.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for repo2string-0.4.2.tar.gz
Algorithm Hash digest
SHA256 3e47135ff35908253349e564d8c9d23fa62527e6af2e8ad271ece4df09ebb8d7
MD5 3e9bac0419475e55cbe9d268d892ac85
BLAKE2b-256 1b9d7fd8a7d4f11253bd2e253fb7599a7a1ee2b1e799a94ae1c302f4d144eba2

See more details on using hashes here.

File details

Details for the file repo2string-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: repo2string-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for repo2string-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 126fdd96acf1d3687f056f329707790e2a22d03e2f224022cf82eac3bd601b6b
MD5 3b64e7a485cc327b3f2f6f8e18891805
BLAKE2b-256 24ecc8c26a3927a116babf7b6032d55fab8c19c32eab62a19d2fea142e49264b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page