Sharing repository file context

While tools like Cursor should be able to satisfy everything you might want to do in a repository, to build, to enhance, to fix, to investigate, whatever -- you might want a second opinion.

Gemini is especially handy here, with its million+ token window.

You still need a way to pass in a bunch of files, with names and content.

After doing this a few times, I started using a helpful script.

Check out this Gist, in case you need to do the same, and modify it to fit your needs.

#!/bin/bash

# --- Configuration ---
output_file="/Users/agam/tmp/combined_output.md"
exclude_dir_names=(".venv" ".git" "node_modules" "__pycache__")
# --- End Configuration ---

# Optional: Delete the old output file first
# rm -f "$output_file"

echo "Starting file processing."
echo "Output file: $output_file"
echo "Excluding directories named: ${exclude_dir_names[@]}"
echo "Excluding output file path: ./$output_file"

# --- Build the find command ---
find_cmd=("find" ".")

# 1. Build the exclusion part
prune_conditions=()
prune_conditions+=("-path" "./$output_file")
for dir_name in "${exclude_dir_names[@]}"; do
  prune_conditions+=("-o" "-name" "$dir_name" "-type" "d")
done

# Add the grouped prune conditions - Use literal '(' and ')' as arguments
# CORRECTED LINE: Removed backslashes from \( and \)
find_cmd+=("(" "${prune_conditions[@]}" ")" "-prune")

# 2. Add the action part (what to do if NOT pruned)
# CORRECTED LINE: Removed backslashes from \( and \)
find_cmd+=("-o" "(" "-type" "f" "-print0" ")")

# --- Execute the find command and process the results ---
# Using process substitution for debugging the command if needed:
# echo "Running command:" >&2
# printf "'%s' " "${find_cmd[@]}" >&2
# echo >&2

"${find_cmd[@]}" | while IFS= read -r -d $'\0' file; do
  # Optional: Print progress to standard error (terminal)
  # echo "Processing: $file" >&2

  echo "$file"      # Print the file path (to stdout -> goes to output file)
  echo '```'        # Print the opening backticks
  cat "$file"      # Print the file content
  echo             # Ensure a newline exists before closing backticks
  echo '```'        # Print the closing backticks
  echo             # Optional: Add a blank line for separation
done > "$output_file" # Redirect all loop stdout to the output file

# Check find's exit status
if [ $? -ne 0 ]; then
    echo "Warning: find command may have encountered errors." >&2
fi

echo "Processing finished. Output saved to: $output_file"