CLI Commands
Kosh provides a unified command-line interface for building, serving, and managing your static site. All operations are handled through thekosh command.
Core Commands
init
Initialize a new Kosh site with the default directory structure.name(optional) - Name of the directory to create. Defaults to current directory.
new
Create a new blog post with pre-filled frontmatter.title(required) - Title of the new post. Quotes optional for multi-word titles.
- Creates a slugified filename from the title
- Adds frontmatter with current date
- Triggers a build to verify the new post
build
Build the static site with full optimization.Watch for file changes and rebuild automatically. Keeps the process running and monitors
content/, theme files, and configuration for changes.Write CPU profile to the specified file for performance analysis.
Write memory profile to the specified file for performance analysis.
Override the base URL from configuration. Useful for deployment to different environments.
Include posts marked as
draft: true in the build output.Override the theme specified in configuration.
- Loads configuration from
kosh.yaml - Parses markdown files with frontmatter
- Renders HTML using templates
- Minifies CSS, JS, and HTML
- Compresses images to WebP (if enabled)
- Generates sitemap, RSS, search index
- Creates PWA manifest and service worker
- Outputs to configured
outputDir(default:public/)
serve
Start a local preview server.Enable development mode with live reload. This mode:
- Builds the site before serving
- Watches for file changes and rebuilds automatically
- Skips PWA generation for faster builds
- Auto-detects
baseURLashttp://localhost:2604if empty - Enables browser live reload on changes
Host or IP address to bind the server to.
Port number to listen on.
Include draft posts when serving in development mode.
Override base URL from configuration.
- Incremental Builds: Only changed files are rebuilt (typically <100ms)
- Live Reload: Browser automatically refreshes on changes
- Watched Paths:
content/,themes/,static/,kosh.yaml - Fast Iteration: PWA generation skipped for speed
clean
Clean build output and optionally cache.Also clean the
.kosh-cache/ directory, forcing a full rebuild on next build.Clean all versions including versioned folders (for documentation sites).
| Command | Removes | Preserves |
|---|---|---|
kosh clean | Root files in outputDir | Version folders (v1.0, v2.0, etc.) |
kosh clean --all | Entire outputDir | Nothing |
kosh clean --cache | Root files + .kosh-cache/ | Version folders |
kosh clean --all --cache | Everything | Nothing |
cache
Manage the BoltDB cache for incremental builds.cache stats
Show cache statistics and performance metrics.cache gc
Run garbage collection to remove orphaned cache entries.Show what would be deleted without actually deleting.
Alias for
--dry-run.cache verify
Check cache integrity and detect corruption.- Lists any corrupted or missing cache entries
- Reports hash mismatches
- Suggests cleanup actions
cache rebuild
Clear the cache and trigger a full rebuild.cache clear
Delete all cache data without rebuilding.cache inspect
Show detailed cache entry for a specific file.version
Manage documentation versions and show build information.version (no args)
Show current documentation version info fromkosh.yaml.
version <name>
Freeze the current latest version and start a new version.- Creates snapshot of current content in
content/v4.0/ - Updates
kosh.yamlwith new version entry - Marks v5.0 as
isLatest: true - Rebuilds site with new version structure
version —info
Show Kosh build information and optimizations.Global Flags
These flags work with thebuild and serve commands:
| Flag | Type | Description |
|---|---|---|
-baseurl <url> | string | Override base URL from config |
-drafts | flag | Include draft posts |
-theme <name> | string | Override theme from config |
Graceful Shutdown
All long-running commands (serve --dev, build --watch) support graceful shutdown:
- Press
Ctrl+Cto trigger shutdown - The process waits up to 5 seconds for cleanup
- Cache is safely closed
- Temporary files are removed
Exit Codes
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Build error, invalid command, or missing arguments |
Common Usage Patterns
Common Usage Patterns
Command Aliases
| Alias | Command |
|---|---|
kosh help | Show usage information |
kosh --help | Show usage information |
kosh -help | Show usage information |
kosh --version | Show build info (same as version --info) |
kosh -version | Show build info (same as version --info) |