Skip to main content

KTrex

KTrex is an interactive, terminal-based directory and file structure builder. It lets you create, navigate, undo, save, load, and reuse project layouts directly from a curses TUI, safely and deterministically.

Think: mkdir + tree + undo + presets + resume, all in one tool.


Features

  • Interactive terminal UI (keyboard driven)
  • Move through the tree with a cursor, expand and collapse folders
  • Create directories and files visually
  • Safe undo (never deletes non-empty directories)
  • Presets (builtin or external JSON)
  • Save a project structure to JSON and load it back
  • Non-destructive by design (no overwrites, no forced deletes)
  • Works offline, zero runtime dependencies
  • Non-interactive mode for scripts: list and apply presets from the command line

Installation

pip install KTrex

Editable install (for development)

git clone https://github.com/K2K22K2K22/KTrex.git
cd KTrex
pip install -e .

Usage

Start the interactive interface in any directory:

ktrex

You are dropped into a TUI that shows your project tree on the left and the actions on the right.

You can also name the directory up front, or use . for the current one:

ktrex my-project
ktrex .

Command line options

ktrex [directory] [--version] [--list-presets] [--apply PRESET]
  • --version prints the version and exits.
  • --list-presets prints the bundled preset names and exits.
  • --apply PRESET builds the preset in the directory and exits, without opening the interface. Defaults to the current directory when no directory is given.
ktrex --list-presets
ktrex --apply python_package my-lib

Exit code is 0 on success and 1 when the directory or preset is invalid.


Controls

Key Action
Tab Switch focus between tree and menu
↑ / ↓ Move the cursor (tree or menu)
→ / Space Expand a folder
← / Backspace Collapse a folder, or go to parent
Enter Enter a folder, or run the action
PageUp / PageDown Move a page
Home / End Jump to the top or bottom
Mouse Wheel Scroll the tree
Quit Exit KTrex safely

Actions Explained

Create Directory

  • Creates a new directory in the current location
  • Enters the new directory

Create File

  • Creates a file in the current directory
  • Does not change navigation

Undo

  • Reverts the most recent create action
  • Removes files and empty directories only
  • Never deletes non-empty directories

Load Preset

  • Loads a structure by name or file path
  • Presets are additive, never destructive

Save Structure

  • Serializes the entire project tree to a JSON file
  • Useful for reuse, backups, or AI-generated layouts

Load Structure

  • Loads a previously saved structure JSON
  • Applies safely without removing existing files

Go Back

  • Navigates to the parent directory
  • Cannot escape the project root

Help

  • Shows the built-in documentation and keybindings

Presets

Built-in presets

ml_project
python_package
web_project

Usage:

Load Preset -> ml_project

External presets

Load Preset -> /path/to/custom_preset.json

The preset format is documented below.


Preset / Structure Format

KTrex uses a simple, declarative JSON format:

{
  "name": "project",
  "type": "dir",
  "children": [
    {
      "name": "src",
      "type": "dir",
      "children": [
        { "name": "main.py", "type": "file" }
      ]
    }
  ]
}

The same format is used by presets, saved structures, and generated layouts.


Safety Guarantees

KTrex is designed to be safe by default:

  • Never overwrites files
  • Never deletes non-empty directories
  • Never writes outside the project root
  • Skips symbolic links and unreadable directories instead of crashing
  • Rolls back a failed apply so disk and undo history stay in sync

License

This project is licensed under the MIT License. You are free to use, modify, and distribute this software with proper attribution.

See the LICENSE file for details.


Sponsor

If you find this project useful and want to support its development:

Ko-Fi

Your support helps keep this project alive and actively maintained.

Metadata

Release files for KTrex 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for KTrex 0.2.1
File Size Uploaded
ktrex-0.2.1.tar.gz 17.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for KTrex 0.2.1
File Interpreter ABI Platform
ktrex-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 32.9 kB

Release files / ktrex-0.2.1.tar.gz

Download URL ktrex-0.2.1.tar.gz
Size 17.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f34b8067041a4bf19a91e5a2f9e90a49317e92c69f929b55071fe98728e5cf8f
BLAKE2b-256 checksum
How to use checksums
8095ad597131d4907289d87b30d4e489e23d089bb9ca6eb4c92be836cc25caef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / ktrex-0.2.1-py3-none-any.whl

Download URL ktrex-0.2.1-py3-none-any.whl
Size 15.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ce1ebf22332bd44738eba3971bbb9ddfdbe0f64f55accb9f918894bb112deb58
BLAKE2b-256 checksum
How to use checksums
8783f149ac4bce4dc7e8dcec3eab391018594c8a3d571d38cf6fd064ef4fb030
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release history Release notifications | RSS feed

0.3.0

2 release files

0.2.5

2 release files

0.2.2

2 release files

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.69

2 release files

0.1.5

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page