Skip to main content

Catenator

Catenator is a Python tool for concatenating code files in a directory into a single output string.

Features

  • Concatenate code files from a specified directory
  • Include or exclude specific file extensions
  • Include a directory tree structure
  • Include README files in the output
  • Output to file, clipboard, or stdout
  • gitignore-style .catignore files

Installation

Install using pip

pip install catenator

Usage

As a Command-Line Tool

Basic usage:

catenator /path/to/your/project

Options:

  • --output FILE: Write output to a file instead of stdout
  • --clipboard: Copy output to clipboard
  • --no-tree: Disable directory tree generation
  • --no-readme: Exclude README files from the output
  • --include EXTENSIONS: Comma-separated list of file extensions to include (replaces defaults)
  • --ignore EXTENSIONS: Comma-separated list of file extensions to ignore
  • --count-tokens: Output approximation of how many tokens in output (tiktoken cl100k_base)
  • --watch: Watch for changes and update output file automatically (requires --output)
  • --ignore-tests: Leave out tests from the concatenated output
  • --token-limit N: Keep output under N tokens by summarizing least important files
  • --llm: Use AI for richer summaries when using --token-limit (requires robot module)

Example:

python catenator.py /path/to/your/project --output concatenated.md --include py,js,ts

As a Python Module

You can also use Catenator in your Python scripts:

from catenator import Catenator

catenator = Catenator(
    directory='/path/to/your/project',
    include_extensions=['py', 'js', 'ts'],
)
result = catenator.catenate()
print(result)

.catignore File

The .catignore file allows you to specify files and directories that should be excluded from the concatenation process. The syntax is like .gitignore files.

Syntax

Lines starting with # are treated as comments. Blank lines are ignored. Patterns can include filenames, directories, or wildcard characters.

Examples

# Ignore all JavaScript files
*.js

# Ignore specific file
ignored_file.txt

# Ignore entire directory
ignored_dir/

.catconfig.yaml for Custom Builds

For more complex configurations, you can define custom "builds" in a .catconfig.yaml file in your project's root directory. This allows you to specify multiple sets of whitelisted and blacklisted files.

--build Option

To use a build, use the --build command-line option:

catenator /path/to/your/project --build <build_name>

When you use the --build option, the catenator will ignore .catignore and other filtering flags, and will instead rely solely on the whitelist and blacklist defined in the specified build.

Example .catconfig.yaml

Here is an example of a .catconfig.yaml file with two builds, frontend and backend:

builds:
  frontend:
    whitelist:
      - "src/frontend/"
      - "README.md"
    blacklist:
      - "src/frontend/node_modules/"
  backend:
    whitelist:
      - "src/backend/"
      - "requirements.txt"
    blacklist:
      - "*.log"

In this example:

  • catenator . --build frontend will concatenate all files in src/frontend/ (except node_modules) and the README.md file.
  • catenator . --build backend will concatenate all files in src/backend/ and the requirements.txt file, excluding any .log files.

Token Limit and Summarization

When a project exceeds a specified token limit, catenator uses a progressive approach to fit within the budget:

catenator /path/to/project --token-limit 10000

This will:

  1. Rank all files by importance to understanding the project
  2. Include full content for the most important files
  3. Add summaries for less important files until 90% of budget is used
  4. Add just docstrings for remaining files until 100% of budget
  5. Truncate if still over the limit

By default, summaries are structural extracts (function/class signatures and docstrings). For richer AI-generated summaries, add the --llm flag:

catenator /path/to/project --token-limit 10000 --llm

Files are labeled in the output: (summary) for summarized files, (docstring) for docstring-only files. Summaries are cached in ~/.catenator/summaries/. Token counting requires tiktoken; AI summaries require the robot module.

License

This project is licensed under the Creative Commons Zero v1.0 Universal (CC0-1.0) License.

Release files for catenator 0.2.7

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

Source distribution (sdist)

Source distribution for catenator 0.2.7
File Size Uploaded
catenator-0.2.7.tar.gz 18.4 kB Details

Built distribution (wheel)

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

Total release size: 34.8 kB

Release files / catenator-0.2.7.tar.gz

Download URL catenator-0.2.7.tar.gz
Size 18.4 kB
Tags Source
SHA-256 checksum
How to use checksums
20c7e7a3e972d6f4ad6d6afb23724b8857907fb96414bbd9568c9e4c6230bc26
BLAKE2b-256 checksum
How to use checksums
fc74f2575f9fe408de03450e4a865a7652bb34de28ce2c595fd55fa35da0eef1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / catenator-0.2.7-py3-none-any.whl

Download URL catenator-0.2.7-py3-none-any.whl
Size 16.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0fa3dc384abd834af2bdd1a9cac457e131b21194707077ec163973546b27e180
BLAKE2b-256 checksum
How to use checksums
960d1ba32c503df5dc61048baeecad7296df9fb50efdb78b94e9d8e441e09f8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.2.7 This release

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

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