# Merge Selected Project Files into One AI-Ready Text Block

> Open one HTML file, choose a project folder (read locally, never uploaded), tick files, set filters, and copy one clean, labelled block of code.

URL: https://thuyavan.netlify.app/scripts/code-consolidator
Updated: 2026-10-07

## Problem
Giving AI models code context means opening and copy-pasting files one by one, including noise like imports and comments that waste the context window.

## Solution
A browser app that reads a project folder locally, lets you tick files in a tree, and consolidates them with language-aware sanitisation.

## Result
A perfectly formatted, AI-ready or doc-ready aggregate generated in seconds.

## Input
- A local project folder chosen through the browser (never uploaded)

## Output
- A Consolidated tab containing the merged, formatted code with a Copy button

## Optional output
- Multiple consolidated tabs to compare filter settings
- Numbered files and relative-path headers

## System flow
Select folder (webkitdirectory, local only) -> Explorer tree (Recursive DFS · bulk select) -> Smart Sanitize (Comments · imports · spacing) -> Merge (80-char = delimiters + headers) -> Consolidated tab (Copy to clipboard)

## How it works
- **Project explorer:** Recursive tree, folder-level bulk selection and automatic expansion.
- **Tab-based viewer:** Double-click any file for a read-only preview; every run opens a new tab.
- **Smart Sanitize:** Separate toggles for single-line, multi-line and inline comments plus import stripping.
- **Space optimiser:** Collapses blank lines to reduce token count.
- **Structured output:** Headers with folder, file and relative path; optional sequence numbers.

## Configuration
- `Include Relative Path`: Helps the AI understand project architecture.
- `Remove Comments / Imports`: Saves tokens on limited context windows.
- `Excess Space Remover`: Collapses multiple empty lines.

## How to run
Step 1:

    # Select Project Folder
Step 2:

    # Tick the related files (e.g. model, repository, controller)
Step 3:

    # Choose filters → Generate Consolidated Code → Copy

## Impact
- Minutes of copy-pasting become seconds.
- Runs entirely client-side, so code stays private.
- Saves AI tokens through comment and import removal.

## FAQ
**How do I give ChatGPT the context of many files at once?**
Select the related files in the tree and generate a consolidated block with path headers, then paste it into the chat.

**Are my files uploaded anywhere?**
No. It uses the browser folder-selection API and processes everything locally.

**Can it remove comments and imports to save tokens?**
Yes. Smart Sanitize strips single-line, multi-line and inline comments, import lines and extra blank lines.

