Skip to main content

Combine source files into a single text file for AI context (ChatGPT, Claude, Gemini)

Project description

ctxpack

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

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

主な特徴

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

インストール

pip install ctxpack

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

uv tool install ctxpack

使い方

基本コマンド:

ctxpack src/ -o context.md

よく使うオプション

拡張子を限定する:

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

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

ctxpack . -o out.md --tree --gitignore

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

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

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

ctxpack . -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  # 全テストの実行

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

pyctxpack-0.1.0.tar.gz (101.7 kB view details)

Uploaded Source

Built Distribution

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

pyctxpack-0.1.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file pyctxpack-0.1.0.tar.gz.

File metadata

  • Download URL: pyctxpack-0.1.0.tar.gz
  • Upload date:
  • Size: 101.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for pyctxpack-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9a45ab629e025b5e30e6fc8be8481c0d0bbe672e33d745849749347bfe23cae0
MD5 27d0e47da594e5b53e0f2c7e3d42073d
BLAKE2b-256 c9698a37f9396fbcfead8e9dec9df524601cc1cf61311e92a3dbd5adf0a5454b

See more details on using hashes here.

File details

Details for the file pyctxpack-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyctxpack-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for pyctxpack-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9551107c95ea3dc9bfc262d88dd61ac44d350ff705b099409c42c55df081e683
MD5 08b02001ffc7b8f2cc2c795639abb2ce
BLAKE2b-256 f5af1eb6eb3979b9e72c2149d567e36fa03cf750b5320da4d9067fa8727d7c05

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