Code Bundler
Bundle selected project files and folders into one structured, AI-friendly file, receive a matching Git-style patch, and review the applied result directly in VS Code.
Version 2.0.1
Version 2.0.1 improves patch compatibility and reliability while preserving the patch-first workflow introduced in version 2.0.0. Patch application now tolerates common AI-generated formatting differences without weakening source-hash validation or ambiguous-context safeguards.
Main Features
AI-Friendly Project Bundling
- Select multiple files, folders, or a mixed selection.
- Recursively scan selected folders.
- Detect UTF-8 and UTF-16 text files.
- Skip binary files and common generated directories.
- Preserve every included file as a complete file without display-only line-number prefixes.
- Include a project tree, file index, language, size, and SHA-256 metadata.
- Generate a stable content-based bundle ID from selected file paths and contents.
- Write
code-bundle-<bundle-id>.txt and request the matching code-change-<bundle-id>.patch.
- Copy the generated bundle file to the system clipboard when supported.
Bundle Queue
- Add files or folders from Explorer or an editor tab.
- Add multiple Explorer selections in one action.
- Deduplicate queued items automatically.
- Display the queue count in the status bar.
- Bundle, inspect, remove, or clear queued items.
- Restore the queue when the workspace is reopened.
Patch Detection and Application
When a local file is opened, Code Bundler offers to apply it only when:
- its extension is
.patch;
- it contains a
# code-bundler-patch-version: header;
- it contains a
# bundle-id: header; and
- it contains a
diff --git a/ section.
Choose Apply to validate and apply the patch. Choose Open Normally or dismiss the prompt to leave it open without applying it. After a successful Apply, the patch tab closes automatically. It remains open if Apply fails.
Apply and Review AI Changes
- Apply
modify, create, delete, and pure rename operations.
- Validate source-file SHA-256 values after normalizing CRLF line endings to LF.
- Derive hunk counts from parsed diff lines instead of failing on inaccurate count metadata.
- Match hunk context while tolerating CRLF/LF differences and trailing spaces.
- Search up to 30 nearby lines when the declared hunk location does not match.
- Apply a relocated hunk only when its normalized context has one unambiguous match.
- Recognize standard and repeated-backslash
No newline at end of file markers.
- Review changes by file or individual hunk.
- Accept or reject the current file, individual hunks, or all remaining changes.
- Preview changes using editor decorations, hover details, and a dedicated Diff view.
- Display a ✦ marker on pending files and parent folders.
- List pending files in the native AI Changed Files Explorer view.
- Show only file names in that view, use the active file icon theme, and show relative paths on hover.
- Restore rejected changes automatically.
Requirements
- Visual Studio Code 1.125.0 or newer.
- An open folder or workspace containing the project.
Usage
1. Create a Bundle
From Explorer, select files or folders, right-click, and choose Code Bundler: Pack Selected Files and Folders. You can also run the command from the Command Palette and choose inputs from the picker.
The extension creates code-bundle-<bundle-id>.txt in the workspace root. The same selected paths and contents produce the same bundle ID.
2. Send the Bundle to an AI Assistant
Attach or paste the generated bundle and describe the requested change. Ask the AI to follow the AI Patch Response Protocol inside the bundle and return code-change-<bundle-id>.patch.
Example request:
Read the complete attached bundle using Python or equivalent file tools.
Implement the requested changes and follow the AI Patch Response Protocol.
Return the matching downloadable .patch file only.
3. Apply the Patch
You can apply a patch in any of these ways:
- Open a qualifying
.patch file and choose Apply.
- Right-click a
.patch file and choose Code Bundler: Apply Change Bundle.
- Run Code Bundler: Apply Change Bundle from the Command Palette and select a
.patch or .diff file.
Before applying, Code Bundler validates the patch header, paths, and normalized source hashes. Hunk counts are derived from parsed lines, and context matching tolerates line-ending differences and trailing spaces. If a declared hunk position does not match, Code Bundler searches up to 30 nearby lines and applies the hunk only when one unambiguous normalized match is found.
4. Review Applied Changes
After Apply succeeds:
- affected files are updated and saved;
- AI Changed Files appears in Explorer;
- pending files and their parent folders display ✦;
- editor decorations and CodeLens actions show reviewable changes.
Use AI Changed Files to switch between pending files. Hover a file name to see its relative path. Use file-level or hunk-level actions to accept or reject changes. The review ends when no pending files remain.
Every patch starts with:
# code-bundler-patch-version: 1
# bundle-id: <bundle-id>
Modified, deleted, and renamed files also require the original source hash:
# original-sha256 src/example.ts: <sha256-from-bundle>
diff --git a/src/example.ts b/src/example.ts
--- a/src/example.ts
+++ b/src/example.ts
@@ -1,2 +1,2 @@
-const enabled = false;
+const enabled = true;
export default enabled;
Patch requirements:
- use workspace-relative
a/ and b/ paths;
- use
/dev/null for the missing side of create or delete operations;
- preserve leading indentation, meaningful line content, and whitespace-only lines;
- prefer accurate hunk locations and counts, although version 2.0.1 can recover from common count, line-ending, trailing-space, and nearby-position differences;
- use
\ No newline at end of file when a file side does not end with a line break;
- include only changed text files;
- do not use Markdown fences in the returned patch file;
- use a pure rename section for renames because rename-with-content-change is not supported.
If Apply Fails
Verify that:
- the selected file has a
.patch or supported .diff extension;
- the patch version and bundle ID headers are present;
- every modified, deleted, or renamed file has the correct
original-sha256 header;
- source files have not changed since bundling;
- paths are workspace-relative and do not escape the workspace;
- the hunk context exists at the declared position or at one unambiguous location within 30 nearby lines;
- the normalized context still matches after ignoring CR characters and trailing spaces;
- another review session is not already active.
If the project changed after bundle generation, create a fresh bundle and request a new patch.
Included and Skipped Content
Code Bundler includes detected text files such as source code, configuration, scripts, Markdown, JSON, YAML, and XML. It skips generated bundle and patch files, common binary formats, dependencies, Git metadata, and common build-output directories such as node_modules, .git, dist, out, build, and coverage.
Clipboard Support
File clipboard copying is supported on Windows and macOS. Bundle generation still completes if clipboard copying is unavailable or fails.
License
MIT
Acknowledgements
Inspired by Kevin Yang.