A Python desktop application built with tkinter to provide a graphical user interface for interacting with the code2prompt CLI tool. This helper makes it easier to select files and folders from a project and configure various code2prompt options before generating a prompt.
- Project Directory Selection: Easily browse and select your target project folder.
- Interactive File/Folder Tree:
- Displays a tree view of your project's structure (files and directories).
- Shows file sizes.
- Allows users to visually select/deselect items.
- Clicking a folder toggles the selection state for the folder and all its children.
- Buttons for "Select All" and "Deselect All".
- Initial Filtering: Automatically excludes common large/unwanted directories (e.g.,
node_modules,.git,venv) from the initial scan for better performance. code2promptOption Configuration:- Specify an output file for the generated prompt (otherwise copies to clipboard).
- Use a custom Handlebars template file.
- Option to display token count, with selection of tokenizer encoding (cl100k, p50k, etc.).
- Toggle line numbers in code blocks.
- Toggle wrapping code in markdown code blocks.
- Add additional custom glob patterns for exclusion.
- Command Generation & Execution:
- Constructs the
code2promptcommand based on your selections and options. - Displays the generated command for review.
- Executes the
code2promptCLI tool as a subprocess.
- Constructs the
- Output Display: Shows
stdoutandstderrfrom thecode2promptexecution directly in the GUI.
- Python 3: (Python 3.9+ recommended, as
tkinteris standard). code2promptCLI Tool: Must be installed and accessible in your system's PATH.- Installation instructions: Code2Prompt GitHub (or wherever you got it).
tkinter: Usually included with standard Python distributions. If you encounter an import error fortkinteror_tkinter(unlikely on most desktop setups), you may need to install it for your Python distribution (e.g.,sudo apt-get install python3-tkon Debian/Ubuntu).
- Save the Script: Save the provided Python code as
code2prompt_tkinter_helper.pyin a convenient location on your system. - No External Python Libraries (beyond standard library for Tkinter): This script is designed to use Python's built-in
tkintermodule for the GUI and standard modules likeos,pathlib,subprocess, andargparse(thoughargparseis used in the script but the GUI version doesn't take CLI args itself anymore for the project path).
-
Run the Script: Open your terminal or command prompt, navigate to the directory where you saved
code2prompt_tkinter_helper.py, and run:python code2prompt_tkinter_helper.py
The GUI window will appear.
-
Select Project Folder:
- Click the "Browse..." button next to "Project Folder".
- Navigate to and select the root directory of the codebase you want to process.
- The path will appear in the input field.
-
Scan Project:
- Once a path is selected, the "Scan Project" button will become enabled. Click it.
- The script will scan the directory (respecting initial hardcoded excludes like
node_modules,venv,.git, etc.) and populate the "Files & Folders" tree view.
-
Select/Deselect Files and Folders:
- The tree view displays your project structure.
[X]or[ ]indicates selection status.[D]for directories,[F]for files.- File sizes are shown.
- To toggle selection: Single-click on any item (file or folder) in the tree.
- If you click a folder, that folder and all its children (files and subfolders) will have their selection status toggled.
- "Select All" Button: Marks all scanned items (that passed initial filtering) for inclusion.
- "Deselect All" Button: Marks all scanned items for exclusion.
- The visual
[X]/[ ]prefix in the tree will update to reflect the current selection status.
- The tree view displays your project structure.
-
Configure
code2promptOptions:- On the right-hand side, fill in the desired options for the
code2promptcommand:- Output File: If you want the prompt saved to a file, enter the filename (e.g.,
my_project_prompt.md). Leave blank to copy to clipboard (defaultcode2promptbehavior). - Template File: Path to a custom
.hbstemplate if you're using one. - Display Token Count: Check this to enable token counting.
- Tokenizer Encoding: If token count is enabled, select your desired encoding (defaults to
cl100k). - Add Line Numbers: Check to add line numbers to code blocks.
- No Markdown Codeblock: Check to disable wrapping code in markdown ``` fences.
- Additional Excludes: Add any further comma-separated glob patterns for exclusion (e.g.,
*.test.js,docs/**/*.png).
- Output File: If you want the prompt saved to a file, enter the filename (e.g.,
- On the right-hand side, fill in the desired options for the
-
Generate & Run Command:
- Once you are satisfied with your file/folder selections and options, click the "Generate & Run code2prompt" button.
- The application will:
- Determine the necessary
--excludearguments forcode2promptbased on your deselections in the tree. - Construct the full
code2promptcommand. - Display this command in the "code2prompt Output" area.
- Execute the command.
- Determine the necessary
-
View Output:
- The
STDOUTandSTDERRfrom thecode2promptexecution will be displayed in the "code2prompt Output" text area. - A success or failure message will also be shown. If an output file was specified and the command was successful, it will confirm the file was written.
- The
- Initial Excludes: The script has a hardcoded list of common directories/files to exclude from the initial scan (e.g.,
node_modules,.git). You can modify this list directly in theinitial_excludes_strvariable within the script if needed. - Exclusion Logic: The helper primarily works by building a list of
--excludearguments forcode2prompt. If you deselect a folder, that folder's relative path is added to the exclude list.code2promptthen handles recursively excluding its contents. - Performance: For very large projects, the initial scan and tree population might take a few moments. The tree interaction itself should be responsive.
code2promptPath: This helper assumescode2promptis installed and available in your system's PATH. If not,subprocesswill fail to find it.
This helper tool aims to streamline the process of generating targeted prompts from large codebases using the powerful code2prompt CLI.
