#!/bin/bash # Check if we're in a git repository if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then echo "Not in a git repository. Creating temporary one to use gitignore rules..." # Initialize temporary git repo if not in one git init >/dev/null 2>&1 temp_git=true else temp_git=false fi # Clear/create output file > claude.txt # Generate and add directory tree echo "Directory Tree:" > claude.txt echo "=============" >> claude.txt # Use tree with gitignore patterns tree -I "$(git check-ignore * .*)" >> claude.txt echo -e "\nFile Contents:" >> claude.txt echo "=============" >> claude.txt # Use git ls-files to get tracked files and untracked files that aren't ignored # The --exclude-standard flag makes git ls-files respect .gitignore # --others includes untracked files # --cached includes tracked files # -z uses null byte as separator for safer handling of filenames with spaces (git ls-files -z --cached --others --exclude-standard) | while IFS= read -r -d '' file; do # Skip the output file itself if [ "$file" = "claude.txt" ]; then continue fi # Skip binary files if file "$file" | grep -q "binary"; then echo "Skipping binary file: $file" continue fi echo -e "\n=== File: $file ===" >> claude.txt echo -e "------------------------" >> claude.txt cat "$file" >> claude.txt done # Clean up temporary git repo if we created one if [ "$temp_git" = true ]; then rm -rf .git echo "Cleaned up temporary git repository" fi echo "Concatenation complete. Output written to claude.txt"