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

repo2string is a Python package and CLI tool that gathers all files in a repository (or any folder), excluding ignored files as specified by a .gitignore (if present), and concatenates them into a single string. This is useful for copying the entire codebase as a context to large language models (LLMs) like ChatGPT.

Features:

  • Recursively traverse directories.
  • Skip files listed in .gitignore (if present) or skip only .git if no .gitignore exists.
  • Generate a file tree (with absolute paths).
  • 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 (-v or --verbose): Also prints the token counts per file, sorted from highest to lowest.

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

repo2string [PATH] [--verbose]

Or use the shorter alias:

r2s [PATH] [--verbose]
  • PATH is optional; defaults to . (current directory).
  • --verbose or -v prints a token-count summary per file (descending).

Example:

repo2string /path/to/myproject --verbose

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.

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:

  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
    
  3. Install the package in editable mode with development dependencies:

    pip install -e ".[test]"
    
  4. Install pre-commit hooks:

    pre-commit install
    

The pre-commit hooks will:

  • Run Ruff for linting and auto-formatting
  • Run pytest to ensure all tests pass
  • Block commits if any checks fail

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.2.12.tar.gz (7.5 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.2.12-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for repo2string-0.2.12.tar.gz
Algorithm Hash digest
SHA256 302a989e5b1b6480dbc41f5669b005e0bfd3fa66bda3b5d02b65d09e3ae23c17
MD5 d88974165ef39ae601150e4fca16dcb6
BLAKE2b-256 dabe0f9a5417477763db5d4374f81534fdf11e10b3675f6a1373cc11cd472a28

See more details on using hashes here.

File details

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

File metadata

  • Download URL: repo2string-0.2.12-py3-none-any.whl
  • Upload date:
  • Size: 6.2 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.2.12-py3-none-any.whl
Algorithm Hash digest
SHA256 7fbdb9890da47dc9c882f15161af1ff038d636775827fc7d92bded0dc5f8a25a
MD5 54ff0ee8e23aedc649440091523f493d
BLAKE2b-256 fc6f65386d84bc9aca00a38007e19e1c83c8215987611e86734e2fd254420183

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