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 Or simply run
open command: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:- 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:
Search
The file tree includes a search box that filters files and folders by name:Collapsible Folders
Folders can be collapsed and expanded. Folder state persists inlocalStorage:
Multi-file Tabs
Tab Limits
Directory mode supports up to 15 open tabs simultaneously:Tab Features
Active Tab IndicatorThe currently active tab is visually highlighted:
Unsaved changes show a dot before the filename:
Each tab has an
× close button. Closing a dirty tab prompts for confirmation:
When multiple files share the same basename, tabs show disambiguating parent folders:
Tab Persistence
Open tabs and scroll positions are stored insessionStorage:
- 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:file parameter is a POSIX-style path relative to the workspace root.
Navigation Sync
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 accordingly4
Direct URL access
Opening
?file=guides/intro.md directly opens that file in a new tab- Bookmarking specific files
- Sharing links to documentation pages
- Using browser history to navigate between files
File Handlers
Directory mode uses aDirectoryHandler that caches FileHandler instances per file:
All file paths are validated to prevent directory traversal:
../../../etc/passwd or similar paths are rejected.
External File Changes
In directory mode, the watchdog observer monitors the entire directory tree recursively:file field to identify which file changed:
Images in Directory Mode
Images are stored in animages/ directory at the workspace root:
/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:relative_path field is added in folder mode for client routing.
POST /api/save
Saves content to a specific file:file field is required in folder mode.
Keyboard Shortcuts
Directory mode adds tab navigation shortcuts:Cmd/Ctrl + 1-9- Switch to tab 1-9Cmd/Ctrl + W- Close current tabCmd/Ctrl + T- Focus file tree search
Performance Considerations
Large DirectoriesThe file tree scans all markdown files recursively using
rglob("*"):
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: