Skip to main content

pyctxpack

pyctxpack is a command-line tool that consolidates source files from a local repository into a single text file, making it easy to provide context to LLMs such as ChatGPT, Claude, or Gemini.

It scans a project directory, collects relevant source files, and outputs them in a structured format optimized for AI analysis and prompting.

This tool helps developers quickly prepare project context when asking questions about their code.


🇯🇵 Japanese README is available below.
日本語の説明はこのREADMEの後半にあります。


Features

  • Smart File Collection
    Recursively scans directories and gathers source files.

  • Flexible Filtering
    Limit files by extension, file size, or total file count.

  • .gitignore Support
    Respects .gitignore rules and excludes unnecessary files (e.g., node_modules).

  • Project Structure Visualization
    Automatically inserts a directory tree at the top of the output.

  • Robust Encoding Detection
    Automatically detects UTF-8, UTF-16, and CP932 (Shift_JIS).
    Binary files are automatically skipped.

  • Token Estimation
    Estimate the approximate number of tokens before sending to an LLM.

Installation

Using pip:

pip install pyctxpack

Using uv:

uv tool install pyctxpack

Usage

Basic command:

pyctxpack src/ -o context.md

Common Options

Limit file extensions

pyctxpack . -o out.md -e py,js,ts

Include project structure and respect .gitignore

pyctxpack . -o out.md --tree --gitignore

Estimate tokens and record them in the output file

pyctxpack . -o out.md --estimate-tokens --token-output

Use LLM-optimized formatting

pyctxpack . -o out.md --llm-format

Command Line Arguments

Argument Description
target Target directory or file
-o, --output [Required] Output file path
-e, --ext File extensions to include (comma separated, e.g. py,ts)
--max-size Maximum file size in KB
--max-files Maximum number of files to collect
--tree Include project structure tree at the beginning
--gitignore Respect .gitignore rules
--estimate-tokens Print estimated token count
--token-output Append estimated token count to the output file
--llm-format Use formatting optimized for LLM parsing

License

MIT License

Contributing

Contributions are welcome!

git clone https://github.com/pekokana/ctxpack.git
cd ctxpack
uv sync
uv run pytest

日本語README

pyctxpack

pyctxpack は、ローカルリポジトリのソースコードを1つのテキストファイルにまとめ、LLM(ChatGPT, Claude, Gemini等)に渡すコンテキストを瞬時に作成するためのコマンドラインツールです。

多くのファイルを扱うプロジェクトでも、適切なフィルタリングとフォーマットによって、AIへの依頼をスムーズにします。

主な特徴

  • スマートなファイル収集: ディレクトリを再帰的にスキャンし、ソースファイルを統合。
  • 柔軟なフィルタリング: 拡張子、最大ファイルサイズ、最大ファイル数による制限。
  • .gitignore 対応: プロジェクトの無視設定を尊重し、不要なファイル(node_modules等)を除外。
  • プロジェクト構造の可視化: ファイルリストの冒頭にディレクトリツリーを自動挿入。
  • 堅牢な文字コード判定: UTF-8, UTF-16, CP932(Shift_JIS) を自動判別。バイナリファイルは自動でスキップ。
  • トークン数見積もり: LLMに渡す前に、おおよそのトークン数を確認可能。

インストール

pip install pyctxpack

または uv を使用している場合:

uv tool install pyctxpack

使い方

基本コマンド:

pyctxpack src/ -o context.md

よく使うオプション

拡張子を限定する:

pyctxpack . -o out.md -e py,js,ts

プロジェクト構造を含め、.gitignoreを反映させる:

pyctxpack . -o out.md --tree --gitignore

トークン数を見積もり、ファイルにも記録する:

pyctxpack . -o out.md --estimate-tokens --token-output

LLMに最適化されたフォーマット(セパレーターを強化)を使用:

pyctxpack . -o out.md --llm-format

コマンドライン引数詳細

引数 説明
target 対象となるディレクトリまたはファイル
-o, --output [必須] 出力先のファイル名
-e, --ext 対象とする拡張子(カンマ区切り。例: py,ts)
--max-size 収集するファイルの最大サイズ (KB)
--max-files 収集する最大ファイル数
--tree 出力の冒頭にプロジェクト構造(ツリー)を含める
--gitignore .gitignore の設定に従ってファイルを無視する
--estimate-tokens 実行時に推定トークン数を表示
--token-output ファイルの末尾に推定トークン数を書き込む
--llm-format LLMがファイルを識別しやすいフォーマットを使用する

ライセンス

MIT License

貢献

Issue や Pull Request は大歓迎です。 開発環境のセットアップ:

git clone https://github.com/pekokana/ctxpack.git
cd ctxpack
uv sync
uv run pytest  # 全テストの実行

Metadata

Release files for pyctxpack 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyctxpack 0.1.2
File Size Uploaded Provenance Actions
pyctxpack-0.1.2.tar.gz 115.1 kB Without provenance Details for pyctxpack-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyctxpack 0.1.2
File Interpreter ABI Platform Actions
pyctxpack-0.1.2-py3-none-any.whl Python 3 none any Details for pyctxpack-0.1.2-py3-none-any.whl

Total release size: 124.6 kB

Release files / pyctxpack-0.1.2.tar.gz

Download URL pyctxpack-0.1.2.tar.gz
Size 115.1 kB
Tags Source
SHA-256 checksum
How to use checksums
7399536c8754265633d35b8f2db5d08b2e705910dcbe83f555564660c8d7b764
BLAKE2b-256 checksum
How to use checksums
9a0f410284d4c41f391ebfba29a635189a1c35fe6223eec0ee19dc71bca1a4ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.12

Release files / pyctxpack-0.1.2-py3-none-any.whl

Download URL pyctxpack-0.1.2-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ae7d15a49799740cbd08d2877590a56d1eb1d5e795c81d4c1eb2b64c00652832
BLAKE2b-256 checksum
How to use checksums
b0409f440b942ea4b38691325ab5ea94685c92d3152593d74a499e68960983a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.12

Security for pyctxpack 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page