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. code2prompt
Option 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
code2prompt
command based on your selections and options. - Displays the generated command for review.
- Executes the
code2prompt
CLI tool as a subprocess.
- Constructs the
- Output Display: Shows
stdout
andstderr
from thecode2prompt
execution directly in the GUI.
- Python 3: (Python 3.9+ recommended, as
tkinter
is standard). code2prompt
CLI 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 fortkinter
or_tkinter
(unlikely on most desktop setups), you may need to install it for your Python distribution (e.g.,sudo apt-get install python3-tk
on Debian/Ubuntu).
- Save the Script: Save the provided Python code as
code2prompt_tkinter_helper.py
in 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
tkinter
module for the GUI and standard modules likeos
,pathlib
,subprocess
, andargparse
(thoughargparse
is 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
code2prompt
Options:- On the right-hand side, fill in the desired options for the
code2prompt
command:- 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 (defaultcode2prompt
behavior). - Template File: Path to a custom
.hbs
template 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
--exclude
arguments forcode2prompt
based on your deselections in the tree. - Construct the full
code2prompt
command. - Display this command in the "code2prompt Output" area.
- Execute the command.
- Determine the necessary
-
View Output:
- The
STDOUT
andSTDERR
from thecode2prompt
execution 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_str
variable within the script if needed. - Exclusion Logic: The helper primarily works by building a list of
--exclude
arguments forcode2prompt
. If you deselect a folder, that folder's relative path is added to the exclude list.code2prompt
then 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.
code2prompt
Path: This helper assumescode2prompt
is installed and available in your system's PATH. If not,subprocess
will fail to find it.
This helper tool aims to streamline the process of generating targeted prompts from large codebases using the powerful code2prompt
CLI.