Skip to main content
The pkg/kiwi package runs a full KiwiFS server, with its REST API, web UI, search, and versioning, inside your Go process. Use it to ship a knowledge base as part of your own binary, or to mount KiwiFS next to your application’s routes.

Install

Terminal

Quick start

main.go
kiwi.New creates the directory if needed and initializes a git repository there when versioning is git. It also watches the directory, so files you edit on disk are committed and indexed.
kiwi.New doesn’t read .kiwi/config.toml. The embedded server uses the options you pass and the defaults below. Features configured only in config.toml, such as vector search or backup sync, aren’t available when embedding.

Options

Search engine: "sqlite" (default) for full-text search with BM25 ranking, or "grep" for index-free substring matching.
Versioning strategy: "git" (default), "cow" for copy-on-write snapshots, or "none".
Authentication. Use "apikey" with a key to require Authorization: Bearer <key> on API requests. The default is "none".
Origins allowed to call the API from a browser, such as "https://app.example.com".

Server methods

Returns the HTTP handler for the REST API and web UI. Use it to serve KiwiFS from your own http.Server or router. The embedded server doesn’t expose the /mcp endpoint that kiwifs serve adds.
Returns the write pipeline for reading and writing pages from Go. See Read and write pages from Go.
Serves Handler() on addr with http.ListenAndServe. It blocks until the listener fails.
Stops KiwiFS’s background schedulers. It doesn’t stop a listener started with ListenAndServe. For graceful shutdown, run your own http.Server as shown below.
Stops the file watcher and releases search indexes, vector stores, and git resources. Call it once before your program exits.

Mount next to your own routes

The web UI loads its assets from absolute paths, so mount KiwiFS at the root and put your own routes on paths it doesn’t use. KiwiFS serves its API under /api/kiwi/.
main.go
If you only need the API, you can mount it under a prefix with http.StripPrefix. The web UI won’t work under a prefix.

Read and write pages from Go

Pipeline() gives you the same write path the REST API uses. Every write is committed to git, indexed for search, and broadcast to connected clients.
Write through pipe.Write, pipe.PatchFrontmatter, pipe.Append, pipe.Rename, and pipe.Delete. Writing through pipe.Store directly skips the commit, the index update, and the event broadcast.

Graceful shutdown

Serve Handler() from an http.Server you control, shut that down first, then close KiwiFS.
main.go
Always call Close() before exiting. Skipping it can leave pending commits unflushed and search indexes in an inconsistent state, which kiwifs reindex can repair.

REST API

The endpoints Handler() serves.

Files as truth

Why every write goes through the pipeline.
Last modified on October 19, 2026