├── .gitignore-tap ├── .gitignore ├── ccat.rb ├── CLAUDE.md ├── LICENSE ├── install.sh ├── uninstall.sh ├── ccat.sh ├── cleanup-ccat4ai.sh └── README.md /.gitignore-tap: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.swp 3 | *.swo -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Output files 2 | *.md 3 | !README.md 4 | !CLAUDE.md 5 | 6 | # Temporary directories 7 | */ 8 | !.github/ 9 | 10 | # System files 11 | .DS_Store 12 | Thumbs.db 13 | 14 | # Editor files 15 | .vscode/ 16 | .idea/ 17 | *.swp 18 | *.swo -------------------------------------------------------------------------------- /ccat.rb: -------------------------------------------------------------------------------- 1 | class Ccat < Formula 2 | desc "CLI tool to clone and concatenate code repositories for AI analysis" 3 | homepage "https://github.com/unclecode/ccat" 4 | url "https://github.com/unclecode/ccat/archive/refs/tags/v0.1.0.tar.gz" 5 | sha256 "REPLACE_WITH_ACTUAL_SHA_AFTER_CREATING_RELEASE" 6 | license "MIT" 7 | 8 | depends_on "git" 9 | depends_on "tree" 10 | depends_on "grep" 11 | depends_on "file" 12 | 13 | def install 14 | bin.install "ccat.sh" => "ccat" 15 | end 16 | 17 | test do 18 | system "#{bin}/ccat", "--version" 19 | end 20 | end -------------------------------------------------------------------------------- /CLAUDE.md: -------------------------------------------------------------------------------- 1 | # CCAT Project Reference 2 | 3 | ## Commands 4 | - Run script: `bash ccat.sh ` 5 | - Lint bash script: `shellcheck ccat.sh` 6 | - Check script syntax: `bash -n ccat.sh` 7 | 8 | ## Code Style Guidelines 9 | - **Bash**: Follow Google's Shell Style Guide 10 | - **Naming**: Use lowercase with underscores for variables/functions 11 | - **Error Handling**: Use proper exit codes and trap for cleanup 12 | - **Comments**: Add comments for non-obvious logic sections 13 | - **Formatting**: Indent with 2 spaces 14 | - **Tool Requirements**: Requires git, tree, file, and grep tools 15 | - **Script Structure**: 16 | 1. Clone repo 17 | 2. Process text files 18 | 3. Extract code structure 19 | 4. Clean up 20 | 21 | ## Purpose 22 | CCAT (Code Cat) is a utility that clones a git repository and: 23 | 1. Creates a markdown file with all text content concatenated 24 | 2. Creates a mini version with only class/function definitions 25 | 3. Adds a directory structure tree to both output files -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 Unclecode 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Installing CodeCat4AI..." 4 | echo "" 5 | echo "RECOMMENDED: Install via Homebrew (https://brew.sh):" 6 | echo " brew tap unclecode/ccat4ai" 7 | echo " brew install ccat4ai" 8 | echo "" 9 | echo "Installing manually..." 10 | 11 | # Make sure the script is executable 12 | chmod +x ccat.sh 13 | 14 | # Create ~/bin if it doesn't exist 15 | mkdir -p "$HOME/bin" 16 | INSTALL_DIR="$HOME/bin" 17 | 18 | # Add to PATH if not already there 19 | if [[ ":$PATH:" != *":$HOME/bin:"* ]]; then 20 | echo 'export PATH="$HOME/bin:$PATH"' >> "$HOME/.bashrc" 21 | echo 'export PATH="$HOME/bin:$PATH"' >> "$HOME/.zshrc" 2>/dev/null || true 22 | echo "Added $HOME/bin to PATH in .bashrc and .zshrc" 23 | echo "Please restart your shell or run 'source ~/.bashrc' (or ~/.zshrc) to update your PATH" 24 | fi 25 | 26 | # Create the symlink 27 | ln -sf "$(pwd)/ccat.sh" "$INSTALL_DIR/ccat4ai" 28 | 29 | echo "CodeCat4AI installed successfully to $INSTALL_DIR/ccat4ai!" 30 | echo "You can now run 'ccat4ai [repository_url_or_path] [output_name]' from anywhere." 31 | echo "" 32 | echo "Want to create a shorter 'ccat' alias? Run:" 33 | echo " ln -sf $INSTALL_DIR/ccat4ai $INSTALL_DIR/ccat" -------------------------------------------------------------------------------- /uninstall.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Uninstalling CodeCat4AI..." 4 | echo "" 5 | echo "RECOMMENDED: If installed via Homebrew, uninstall with:" 6 | echo " brew uninstall ccat4ai" 7 | echo " brew untap unclecode/ccat4ai" 8 | echo "" 9 | echo "Uninstalling manual installation..." 10 | 11 | # Check common installation locations 12 | UNINSTALLED=false 13 | 14 | # Check ~/bin (preferred location in new install script) 15 | if [ -f "$HOME/bin/ccat4ai" ]; then 16 | rm -f "$HOME/bin/ccat4ai" 17 | echo "Removed ccat4ai from $HOME/bin" 18 | UNINSTALLED=true 19 | fi 20 | 21 | if [ -f "$HOME/bin/ccat" ]; then 22 | rm -f "$HOME/bin/ccat" 23 | echo "Removed ccat from $HOME/bin" 24 | UNINSTALLED=true 25 | fi 26 | 27 | # Check traditional locations (old install script) 28 | if [ -f "/usr/local/bin/ccat" ]; then 29 | sudo rm -f "/usr/local/bin/ccat" 30 | echo "Removed ccat from /usr/local/bin" 31 | UNINSTALLED=true 32 | fi 33 | 34 | if [ -f "$HOME/.local/bin/ccat" ]; then 35 | rm -f "$HOME/.local/bin/ccat" 36 | echo "Removed ccat from $HOME/.local/bin" 37 | UNINSTALLED=true 38 | fi 39 | 40 | if [ "$UNINSTALLED" = false ]; then 41 | echo "Could not find any ccat4ai installation." 42 | echo "If you installed it to a custom location, please remove it manually." 43 | echo "For a complete cleanup, run:" 44 | echo " ./cleanup-ccat4ai.sh" 45 | exit 1 46 | fi 47 | 48 | echo "CodeCat4AI has been uninstalled successfully!" 49 | echo "" 50 | echo "For a complete cleanup (including Homebrew), run:" 51 | echo " ./cleanup-ccat4ai.sh" -------------------------------------------------------------------------------- /ccat.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | VERSION="0.1.0" 4 | 5 | # Display version if requested 6 | if [ "$1" = "--version" ]; then 7 | echo "ccat version $VERSION" 8 | exit 0 9 | fi 10 | 11 | # Check if we have enough arguments 12 | if [ -z "$1" ]; then 13 | echo "Usage: $(basename "$0") [output-name] [subdir] [include-patterns] [exclude-patterns]" 14 | echo "Example: $(basename "$0") https://github.com/user/repo myproject src \"*.py,*.js\" \"node_modules,venv\"" 15 | exit 1 16 | fi 17 | 18 | output="${2:-codebase}" 19 | home="${3:-.}" 20 | incl="${4:-}" 21 | excl="${5:-}" 22 | orig_dir=$(pwd) 23 | repo=$(basename "$1" .git) 24 | 25 | # Clone if needed 26 | if [ ! -d "$repo" ]; then 27 | git clone -q "$1" || exit 1 28 | trap "cd '$orig_dir' && rm -rf '$repo'" EXIT 29 | fi 30 | 31 | cd "$repo" || exit 1 32 | set -f 33 | 34 | # Build find commands for include/exclude patterns 35 | find_cmd_incl="" 36 | if [ -n "$incl" ]; then 37 | find_cmd_incl="( -name ${incl//,/ -o -name } )" 38 | fi 39 | 40 | find_cmd_excl="" 41 | if [ -n "$excl" ]; then 42 | find_cmd_excl="! -name ${excl//,/ -a ! -name }" 43 | fi 44 | 45 | # Generate full content file 46 | find "$home" -type f $find_cmd_incl $find_cmd_excl -exec sh -c 'file --mime-type -b "$1" | grep -q text && cat "$1"' sh {} \; > "../$output.md" && tree -a "$home" >> "../$output.md" 47 | 48 | # Generate mini content file (function/class definitions only) 49 | find "$home" -type f $find_cmd_incl $find_cmd_excl -exec sh -c 'file --mime-type -b "$1" | grep -q text && grep -Eh "^[[:space:]]*(class|def|module|function|struct|enum|interface)[[:space:]]+" "$1"' sh {} \; > "../mini.$output.md" && tree -a "$home" >> "../mini.$output.md" 50 | 51 | set +f 52 | 53 | echo "Done! Files created: $output.md, mini.$output.md" -------------------------------------------------------------------------------- /cleanup-ccat4ai.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Cleanup script for ccat4ai testing 4 | # This script completely removes ccat4ai from your system 5 | # so you can test the installation process from scratch 6 | 7 | echo "=== Starting ccat4ai cleanup ===" 8 | 9 | # Uninstall the formula if it's installed 10 | echo "Uninstalling ccat4ai formula..." 11 | brew uninstall ccat4ai 2>/dev/null || echo "ccat4ai formula not installed" 12 | 13 | # Untap the repository 14 | echo "Removing tap..." 15 | brew untap unclecode/ccat4ai 2>/dev/null || echo "unclecode/ccat4ai tap not found" 16 | 17 | # Clean up potential symlinks 18 | echo "Removing symlinks..." 19 | rm -f ~/bin/ccat 2>/dev/null || true 20 | rm -f /usr/local/bin/ccat 2>/dev/null || true 21 | rm -f /opt/homebrew/bin/ccat 2>/dev/null || true 22 | 23 | # Remove lock files 24 | echo "Removing lock files..." 25 | sudo rm -f /opt/homebrew/var/homebrew/locks/ccat.formula.lock 2>/dev/null || true 26 | sudo rm -f /opt/homebrew/var/homebrew/locks/ccat4ai.formula.lock 2>/dev/null || true 27 | 28 | # Clean up cache files 29 | echo "Cleaning Homebrew cache..." 30 | rm -f ~/Library/Caches/Homebrew/ccat4ai--* 2>/dev/null || true 31 | rm -f ~/Library/Caches/Homebrew/downloads/*ccat4ai* 2>/dev/null || true 32 | 33 | # Clean up Homebrew cache 34 | echo "Running brew cleanup..." 35 | brew cleanup ccat4ai 2>/dev/null || true 36 | 37 | # Verify cleanup 38 | echo "Verifying cleanup..." 39 | which ccat4ai 2>/dev/null && echo "WARNING: ccat4ai still found in PATH" || echo "ccat4ai not found in PATH - Good!" 40 | which ccat 2>/dev/null && echo "WARNING: ccat still found in PATH" || echo "ccat not found in PATH - Good!" 41 | brew list | grep ccat4ai && echo "WARNING: ccat4ai still installed" || echo "ccat4ai not found in brew list - Good!" 42 | 43 | echo "=== Cleanup complete ===" 44 | echo "You can now run the following to test installation:" 45 | echo "brew tap unclecode/ccat4ai" 46 | echo "brew install ccat4ai" -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CodeCat4AI (ccat) 2 | 3 | [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) 4 | [![Bash](https://img.shields.io/badge/Shell-Bash-blue.svg)](https://www.gnu.org/software/bash/) 5 | [![Twitter Follow](https://img.shields.io/twitter/follow/unclecode?style=social)](https://twitter.com/unclecode) 6 | 7 | A lightning-fast tool to concatenate entire repositories into markdown files for AI processing. 8 | 9 | > **🌟 SPECIAL ANNOUNCEMENT 🌟** 10 | > **If this repository reaches 1000 stars in 7 days, I will make CodeCat4AI available as a free online service accessible via a single link!** 11 | > *Show your support by starring this repo if you find it useful!* 12 | 13 | ## Why CodeCat4AI? 14 | 15 | I noticed people keep looking for tools to convert a repo into one file to attach to their favorite LLM. Finding no simple solution, I created this 5-line bash script to do the job efficiently! 16 | 17 | ## Features 18 | 19 | - **Fast**: Quickly processes repositories of any size 20 | - **Simple**: Just a 5-line bash script - no complex dependencies 21 | - **Flexible**: Works with both remote and local repositories 22 | - **Smart**: Automatically detects text files 23 | - **Dual Output**: Generates both full and compact versions 24 | - **Clean**: Handles temporary files and cleanup automatically 25 | 26 | ## Installation 27 | 28 | ### Using Homebrew (macOS) 29 | 30 | ```bash 31 | # Install from Homebrew 32 | brew tap unclecode/ccat4ai 33 | brew install ccat4ai 34 | ``` 35 | 36 | This will install the tool as `ccat4ai`. 37 | 38 | ## Usage 39 | 40 | ```bash 41 | # Basic usage - output defaults to "codebase" 42 | ccat4ai [repository_url_or_path] [output_name] 43 | ``` 44 | 45 | The second parameter `[output_name]` is optional and defaults to `codebase` if not provided. 46 | 47 | ### Local vs Remote Repositories 48 | 49 | - If a URL is provided (starts with http://, https://, or git@), the tool clones the repository temporarily 50 | - If just a name is provided (like "crawl4ai"), the tool assumes it's a local directory in the current path 51 | - If a path is provided, the tool uses that local repository 52 | 53 | ### Examples 54 | 55 | ```bash 56 | # Process a remote repository with custom output name 57 | ccat4ai https://github.com/unclecode/crawl4ai crawl4ai 58 | 59 | # Process a remote repository with default output name 60 | # Creates codebase.md and mini.codebase.md 61 | ccat4ai https://github.com/unclecode/crawl4ai 62 | 63 | # Process a local repository by name (if in current directory) 64 | ccat4ai crawl4ai 65 | 66 | # Process a local repository by path 67 | ccat4ai ~/projects/crawl4ai 68 | ``` 69 | 70 | ### Output 71 | 72 | The tool generates two files: 73 | - `[output_name].md` - Full version with all text files concatenated 74 | - `mini.[output_name].md` - Compact version with only function/class definitions 75 | 76 | Both files include a directory tree structure at the end. 77 | 78 | ### Using a Shorter Command Name 79 | 80 | After installation, you can create a shorter `ccat` command if preferred: 81 | 82 | ```bash 83 | # Create ~/bin directory if it doesn't exist 84 | mkdir -p ~/bin 85 | 86 | # Create the symlink 87 | ln -sf $(which ccat4ai) ~/bin/ccat 88 | 89 | # Add ~/bin to your PATH (if not already done) 90 | echo 'export PATH="$HOME/bin:$PATH"' >> ~/.zshrc # or ~/.bashrc 91 | 92 | # Apply changes to current terminal 93 | source ~/.zshrc # or ~/.bashrc 94 | ``` 95 | 96 | Then you can use the shorter command: 97 | ```bash 98 | ccat https://github.com/unclecode/crawl4ai output-name 99 | ``` 100 | 101 | ## Manual Installation 102 | 103 | You can also download and use the script directly without Homebrew: 104 | 105 | ```bash 106 | # Clone the repository 107 | git clone https://github.com/unclecode/ccat4ai.git 108 | 109 | # Option 1: Run directly from the cloned directory 110 | cd ccat4ai 111 | chmod +x ccat.sh 112 | ./ccat.sh https://github.com/user/repo output-name 113 | 114 | # Option 2: Create a symlink in your bin directory 115 | mkdir -p ~/bin 116 | ln -sf "$(pwd)/ccat.sh" ~/bin/ccat4ai 117 | echo 'export PATH="$HOME/bin:$PATH"' >> ~/.zshrc # or ~/.bashrc 118 | source ~/.zshrc # or ~/.bashrc 119 | ``` 120 | 121 | ## Uninstallation 122 | 123 | ```bash 124 | # If installed with Homebrew 125 | brew uninstall ccat4ai 126 | brew untap unclecode/ccat4ai 127 | 128 | # If you created a symlink 129 | rm -f ~/bin/ccat4ai 130 | rm -f ~/bin/ccat # If you created the shorter alias 131 | 132 | # For a complete cleanup, use our cleanup script: 133 | curl -s https://raw.githubusercontent.com/unclecode/ccat4ai/main/cleanup-ccat4ai.sh | bash 134 | ``` 135 | 136 | 137 | ### Examples 138 | 139 | ```bash 140 | # Process a remote repository with custom output name 141 | ccat4ai https://github.com/unclecode/crawl4ai crawl4ai 142 | 143 | # Process a remote repository with default output name 144 | # Creates codebase.md and mini.codebase.md 145 | ccat4ai https://github.com/unclecode/crawl4ai 146 | 147 | # Process a local repository by name (if in current directory) 148 | ccat4ai crawl4ai 149 | 150 | # Process a local repository by path 151 | ccat4ai ~/projects/crawl4ai 152 | 153 | # If you created the ccat symlink: 154 | ccat https://github.com/unclecode/crawl4ai 155 | ``` 156 | 157 | ### Output 158 | 159 | The tool generates two files: 160 | - `[output_name].md` - Full version with all text files concatenated 161 | - `mini.[output_name].md` - Compact version with only function/class definitions 162 | 163 | Both files include a directory tree structure at the end. 164 | 165 | ## About the Author 166 | 167 | Created by [Unclecode](https://github.com/unclecode), author of the popular [Crawl4AI](https://github.com/unclecode/crawl4ai) library. 168 | 169 | If you find this tool useful, please ⭐ [CodeCat4AI](https://github.com/unclecode/ccat4ai) and [Crawl4AI](https://github.com/unclecode/crawl4ai) on GitHub! 170 | 171 | ## License 172 | 173 | MIT --------------------------------------------------------------------------------