Gather all your codebase into one file for easy sending to GPT models

Hi All,

If you use any of the models for coding, you’ll often get into the bad habit of having everything in one long file… simply because it’s simpler to Copy/Paste that to the model over and over while building and debugging.

When you have lots of code files in many folders it gets to be an issue trying to get the model to understand your codebase, so I created this little python script that generates a GPT model friendly directory tree and adds every file from your project including sub folders to one file which you can then copy paste to the Playground/ChatGPT.

It has common non code folders excluded and some files, but it’s easy to adjust in the script, it also has a files to include list if you only want certain files in there.

I know that GitHub co-pilot and cursor etc have made this a lot simpler recently, but sometimes you just want to have a back and forth with the model on your code and this has been useful to me.

Enjoy!

(Example output from the script)

Directory Tree:
all_code/
│   ├── full_code.txt
│   ├── README.md
│   ├── test.py
│   ├── .git/ [EXCLUDED]
│   ├── demo_folder/
│   │   ├── another_file.js




# ======================
# File: test.py
# ======================

def greet(name):
    return f"Hello, {name}!"

if __name__ == "__main__":
    print(greet("World"))
    def farewell(name):
        return f"Goodbye, {name}!"

    print(farewell("World"))

# ======================
# File: demo_folder\another_file.js
# ======================

// another_file.js

// Function to add two numbers
function add(a, b) {
    return a + b;
}

// Function to subtract two numbers
function subtract(a, b) {
    return a - b;
}

// Function to multiply two numbers
function multiply(a, b) {
    return a * b;
}

// Function to divide two numbers
function divide(a, b) {
    if (b === 0) {
        throw new Error("Division by zero is not allowed.");
    }
    return a / b;
}

// Example usage
console.log("Add: " + add(5, 3));         // Output: Add: 8
console.log("Subtract: " + subtract(5, 3)); // Output: Subtract: 2
console.log("Multiply: " + multiply(5, 3)); // Output: Multiply: 15
console.log("Divide: " + divide(5, 3));     // Output: Divide: 1.6666666666666667
8 Likes

Awesome, thank you! This is really helpful. :hugs:

2 Likes

nice, funny enough, i made a repo with the same name but never open sourced it, it’s really useful when working with multiple files but not too many files!

1 Like