I want to feed a Git repository to a large language model so it can give better feedback when I ask questions about the code. To do that, I need to merge all Python files in the repo (including those in subfolders) into a single Markdown file.

The format I’m thinking of is similar to the Linux tree command for the structure, followed by the content of each file. For example:

merged_python_files.md

├── a.py
a.py content between triple quotes
└── subfolder
    └── b.py
b.py content between triple quotes

I’d like a Python script that can recursively traverse the repo, collect all .py files, and produce this Markdown file automatically.