Skip to main content

Overview

Directory mode (also called folder mode or workspace mode) allows you to edit multiple markdown files within a directory. You get a file tree sidebar, multi-file tabs, and URL-based file routing.

Opening a Directory

1

Open a directory

Pass a directory path to the open command:
Or simply run markdown-os with no arguments to open the current directory:
2

Browse the file tree

The left sidebar shows all markdown files in the directory recursively. Click any file to open it in a new tab.
3

Work with multiple files

Open up to 15 files simultaneously in tabs. Each tab maintains its own edit history and scroll position.
Directory mode requires at least one markdown file (.md or .markdown) anywhere in the directory tree. Empty directories are rejected.

Directory Validation

Before starting the server, Markdown-OS validates your directory:
The validator:
  • Resolves ~ (home directory) and relative paths
  • Confirms the path exists and is a directory
  • Recursively scans for at least one markdown file

File Tree

Structure

The file tree is a nested JSON structure returned by /api/file-tree:
Folders appear before files at each level, sorted alphabetically (case-insensitive). The file tree includes a search box that filters files and folders by name:
Use the search box to quickly find files in large documentation projects. Only matching files and their parent folders are shown.

Collapsible Folders

Folders can be collapsed and expanded. Folder state persists in localStorage:

Multi-file Tabs

Tab Limits

Directory mode supports up to 15 open tabs simultaneously:
When you reach the limit, you must close an existing tab before opening a new file.
Attempting to open more than 15 tabs shows an error message. Close unused tabs to free up space.

Tab Features

Active Tab Indicator
The currently active tab is visually highlighted:
Dirty State Indicator
Unsaved changes show a dot before the filename:
The dot color is theme-dependent (usually yellow/orange). Close Buttons
Each tab has an × close button. Closing a dirty tab prompts for confirmation:
Smart Naming
When multiple files share the same basename, tabs show disambiguating parent folders:

Tab Persistence

Open tabs and scroll positions are stored in sessionStorage:
When you reload the page:
  • Previously open tabs reopen automatically
  • The last active tab is selected
  • Scroll positions are restored per tab
  • Unsaved content is lost (browser refresh limitation)
sessionStorage is per-tab in your browser. Opening the same directory in a new browser tab starts with a clean slate.

URL Routing

Directory mode uses URL query parameters to identify the active file:
The file parameter is a POSIX-style path relative to the workspace root.
1

Clicking a file in the tree

Updates the URL query parameter and loads the file content
2

Clicking a tab

Updates the URL to match the tab’s file path
3

Browser back/forward buttons

Listens to popstate events and switches tabs accordingly
4

Direct URL access

Opening ?file=guides/intro.md directly opens that file in a new tab
This enables:
  • Bookmarking specific files
  • Sharing links to documentation pages
  • Using browser history to navigate between files

File Handlers

Directory mode uses a DirectoryHandler that caches FileHandler instances per file:
Path Security
All file paths are validated to prevent directory traversal:
Attempts to access ../../../etc/passwd or similar paths are rejected.

External File Changes

In directory mode, the watchdog observer monitors the entire directory tree recursively:
WebSocket notifications include a file field to identify which file changed:
The client only reloads the file if it’s currently open in a tab.

Images in Directory Mode

Images are stored in an images/ directory at the workspace root:
All markdown files reference images using the same relative path:
This works from any file in the workspace because images are served at /images/{filename} by the server.

API Endpoints

GET /api/mode

Returns the current server mode:

GET /api/file-tree

Returns the nested directory structure (folder mode only).

GET /api/content?file=path/to/file.md

Returns file content and metadata:
The relative_path field is added in folder mode for client routing.

POST /api/save

Saves content to a specific file:
The file field is required in folder mode.

Keyboard Shortcuts

Directory mode adds tab navigation shortcuts:
  • Cmd/Ctrl + 1-9 - Switch to tab 1-9
  • Cmd/Ctrl + W - Close current tab
  • Cmd/Ctrl + T - Focus file tree search
All standard editor shortcuts also work. See the Editor Features guide.

Performance Considerations

Large Directories
The file tree scans all markdown files recursively using rglob("*"):
Directories with thousands of files may experience slower initial load times. Memory Usage
Each open tab caches file content, scroll position, and edit history in memory. With the 15-tab limit, memory usage remains reasonable even for large files.
WebSocket Connections
All browser tabs connected to the same server share a single WebSocket connection per tab. The WebSocketHub broadcasts file changes to all connected clients: