Repository navigation
Server Management
One shared memory server on 127.0.0.1:8765 serves every session: Claude Code, Codex, Antigravity and Claude Desktop alike. You rarely need to manage it by hand.
- Every harness connects through
kg mcp, a small stdio bridge. It starts the server when it is down and waits out restarts, so the tools stay connected throughkg updateorkg restart. - The SessionStart hooks start it too, and wait for it, so a cold start still gets its preload.
- On Linux with a systemd user session,
kg setupinstalls a user service that starts it at login.
Nothing stops or restarts a running server except kg itself: your own kg stop/kg restart, or kg setup and kg update when they bring it to a new version. A stopped server comes back as soon as a session or kg mcp needs it.
kg status # running? which version, how many sessions, from where
kg start | stop | restart # through systemctl when the service is enabled
kg logs [-f] # the server log, or the journal under the service
kg doctor # check every piece the memory depends on
kg update # upgrade kg, restart the server on it, update the plugins
kg editor [stop] # visual editor at http://localhost:8766
kg commit # commit the storage git repository now
kg version # this kg's versionkg serve runs the server in the foreground; it is what the systemd unit runs. kg mcp is the stdio bridge the harnesses launch; you don't run it yourself.
Concurrent starts are serialised, so a harness and its hook starting at the same moment share one server. A second server on the same storage directory refuses to run. A failed start records its cause in ~/.local/state/knowledge-graph/last_start_error; the hooks report that cause instead of retrying every session, and the next successful kg start or kg restart clears it.
-
Under the systemd service, the server writes to the journal.
kg logsreads it there (journalctl --user -u kg-memory.service;-ffollows). -
Otherwise, a server started by
kg start,kg mcpor a hook writes~/.local/state/knowledge-graph/mcp_server.log, andkg logstails that file.
Set KG_LOG_LEVEL=DEBUG for more detail (Configuration says where to set it).
kg setup installs and enables ~/.config/systemd/user/kg-memory.service, which runs kg serve and restarts it on failure. While the service is enabled, kg start, kg stop and kg restart go through systemctl --user, and kg start also stops any stray server the service doesn't own (one started by an older plugin or by hand). Check it with systemctl --user status kg-memory and kg status.
The unit's environment is fixed when setup writes it: PATH, CODEX_HOME and every KG_* variable are copied from the environment kg setup ran in. Later changes to your shell profile don't reach it, and rerunning setup leaves a working unit as it is. To change a variable, edit the Environment= lines in the unit, then:
systemctl --user daemon-reload && kg restartOn macOS, and on Linux without a systemd user session, there is no service: the first session (or kg mcp) starts the server, and it keeps running in the background until you stop it.
kg uninstall disables and removes the service.
| What | Where |
|---|---|
| Memory (plain JSON) |
~/.knowledge-graph/ (KG_STORAGE_ROOT), see Data and Backup
|
| PID file, last start error, setup backups | ~/.local/state/knowledge-graph/ |
| Server log, when kg started the server | ~/.local/state/knowledge-graph/mcp_server.log |
| Visual editor log and PID |
~/.local/state/knowledge-graph/visual_editor.log, editor.pid
|
| A server on a port other than 8765 | its own port-<N>/ inside ~/.local/state/knowledge-graph/
|
The kg command and server code |
uv's tool environment (uv tool dir) |
| Systemd user unit (Linux) | ~/.config/systemd/user/kg-memory.service |
The server speaks MCP on / and serves a REST API for the hooks and the visual editor. The ones useful by hand:
| Endpoint | Purpose |
|---|---|
POST / |
MCP Streamable HTTP (what kg mcp forwards to) |
GET /health |
Health check with version and session count |
GET /api/graph/read |
REST read (visual editor); reload=true forces a re-read from disk |
GET /api/nodes/{level}/{id} |
Read one node (promotes an archived node to active) |
GET /api/nodes/{level}/{id}/score |
Read-only archival score breakdown |
POST /api/nodes/rename |
Rename a node and update every reference to it |
GET /api/projects |
Stored project graphs, independent of any harness's history |
The rest are for the hooks (session bootstrap, prompt and tool events, Antigravity's hook bridge) and the editor (node and edge create/delete, progress, session stats, and WS /ws for live updates).
Every request must carry a local Host header (localhost, 127.0.0.1 or ::1); other hosts get 421, which closes the DNS-rebinding route around browser protections. HTTP requests a browser marks as cross-site, or that carry a non-local Origin, are refused, and WebSocket upgrades need a local or absent Origin. There is no authentication beyond that: the trust boundary is the processes on your machine. See SECURITY.md.
-
Start with
kg doctor. It names each broken piece and the fix;kg setupapplies the fixes it can. -
Tools offline.
kg mcpstarts the server and retries on its own, so offline tools mean a start that fails.kg startprints why, andkg logsshows the rest. -
The session says the last start failed. The hooks found
last_start_errorand stopped retrying. Fix the cause it names, thenkg start. -
A
KG PREFLIGHT:line in the log names an incompatible dependency or a second server on the same storage. For a dependency, runkg updateoruv tool install --reinstall kg-memory; the same fixes a tool environment broken by an OS Python upgrade. -
kg statusshows another version thankg version. The running server predates the installed kg:kg restart. -
Port 8765 is taken by another program. Set
KG_HTTP_PORTfor the server and every client (Configuration). - A variable you set has no effect. Under the systemd service, set it in the unit (above), not your shell profile.
-
Graph looks stale after editing the JSON by hand while the server runs: the server keeps graphs in memory.
curl -s 'http://127.0.0.1:8765/api/graph/read?reload=true&project_path=<root>'forces a re-read from disk. Safer still,kg stopbefore editing andkg startafter (Data and Backup). -
A harness still on a 0.11 plugin connects by URL and needs
/mcp→ Reconnect (Claude Code) or a new session (Codex) after a restart;kg updatemoves it tokg mcp.
If the memory itself is lost or damaged, restore from the rolling backup or git history first (Data and Backup). Without backups, /kg-scout can rebuild lessons from your Claude Code, Codex and Antigravity session history (Skills Reference).
Agents have the same recipes in the kg-ops skill: "run /kg-ops and fix the memory server" is a complete instruction.