Gitian

Local node

Your knowledge base on your own machine, served to Claude Code as a local MCP server. The local node is coming soon: these commands work once it is published.

What the local node is

The local node keeps a knowledge base on your machine, in a Postgres of its own. Nothing runs in the background: the first agent session starts Postgres, and the last one to end stops it. Claude Code runs the node over stdio as its gitian-kb MCP server, with the knowledge base's own tools and resources. Its search is by words alone, so no query leaves the machine.

A home is gitian.dev or another Gitian server that you sign the node into. With a home connected, a call that names one of its knowledge bases, or is routed to it, goes there. With none connected, nothing leaves the machine.

It runs on macOS and Linux only.

Install and layout

The installer is one shell script, install.sh. It takes the node by its digest from a registry, or from a tarball you already have, with its sha256:

The two forms
sh install.sh <registry>/<repository>@sha256:<digest>
sh install.sh --from-file <tarball> --sha256 <hex>

What it checks

  • A tag is refused, alone or beside a digest: a digest names exactly one build. It must be sha256: and 64 hex digits.
  • It fetches over https, or over plain http only from a registry on this machine's loopback: 127.0.0.1, localhost or [::1].
  • It refuses to run as root. It refuses a machine with no build: Linux on anything but x86_64 or arm64, Linux without glibc 2.28 or newer (musl, as on Alpine), a Mac without Apple silicon, or macOS before 14. It needs tar, gzip, find and readlink, and curl for a registry.
  • Nothing is unpacked until the artifact's size and sha256 match its manifest, or the hash you gave. Even then, every entry must lie inside the tarball's one top directory, and every link must stay inside it.
  • The new version must run on this machine (gitian --version) before anything switches to it.
  • One installer runs at a time. It never asks for sudo, never touches a shell profile or your PATH, and runs nothing it downloaded except that version check.
  • The same build again only switches back to it. Another build under a version you already have is refused.

Where it goes

Everything installed lives under ~/.gitian/install:

<version>/
One directory for each installed version. Earlier ones stay until gitian prune --yes removes those nothing uses.
current
A link naming the version that runs. An install switches it in one atomic rename, so an install that fails or is killed changes nothing you run.
trees/<tree id>/
The Postgres trees, shared by every version. A tree is added when it is missing and never replaced, so a version whose tree changed still finds the old one, which gitian upgrade needs.
stores/
One record for each store an installed program has opened, wherever it is. This is how gitian prune sees them all.

Run it as ~/.gitian/install/current/bin/gitian, or put that bin directory on your PATH.

The store

The store is ~/.gitian, or the absolute path in GITIAN_HOME. The install always goes in ~/.gitian/install, whatever GITIAN_HOME says.

store.json
The stamp: the store's format, its state, and the Postgres tree and data directory it runs.
pg<major>/
The Postgres data directory, one for each major version. An upgrade to a new major leaves the old one for you to remove.
postgres.log
What every start of Postgres printed.
run/
The run directory, yours alone: the lock files, the live sessions and the Postgres socket. When the store's path is too long for a socket, it goes elsewhere (see the environment variables below).
backups/<time>/
The dumps gitian backup writes.
upgrades/<time>/
The dump each upgrade takes before it changes anything.
tokens/
A home's tokens when no keychain answers: one file for each home, readable by you alone.
archive/
The verified copy of each knowledge base a move sent, until gitian forget.

A home's tokens go to the macOS keychain, or on Linux to the secret service when one answers, under the service name gitian-node. They never go in the database.

What every command that opens the store refuses

  • Running as root, or as a user with no passwd entry.
  • A store, run directory or data directory on a network or FUSE filesystem, or on one it cannot identify: file locks there do not keep two machines apart.
  • A store, trees or run directory path holding a comma, a quote, a backslash, $, a backtick or a control character.
  • A store written by a newer node. An older node never touches a newer store.

Getting started

Install it, create the store, then wire it into Claude Code:

Once, after the install
gitian init
gitian setup

gitian init creates the store and its owner. gitian setup adds the node to Claude Code as its gitian-kb server and checks that it connects. From then on Claude Code runs gitian mcp itself, once for each session.

A day with the node

  • Your agent reads and writes the knowledge base through the gitian-kb tools. The first session starts Postgres, and the last one to end stops it.
  • gitian status shows what runs and what waits. gitian backup dumps the store whenever you want a copy.
  • To share with a home, run gitian connect yourself, in your own terminal. gitian homes then shows what it offers. Confirm where an owner's work goes with gitian route, and put one of its knowledge bases in every search with gitian search-include.
  • A write to a home that does not answer waits in the outbox, and is sent once the home answers. gitian outbox shows what waits.
  • Once a session has read from one home, its writes to another are refused until you allow that pair with gitian allow.

Upgrading

Install the new version. Claude Code runs the install's current link, so it needs no new setup. Then, with every session closed, run gitian upgrade: it moves the store to the new version's Postgres tree and applies its migrations. Last, gitian prune lists the old versions and trees nothing uses, and gitian prune --yes removes them.

After installing a new version
gitian upgrade
gitian prune
gitian prune --yes

Removing it

Run gitian uninstall first: it takes the node out of Claude Code and puts back what was there before. Then delete ~/.gitian/install. The store stays in ~/.gitian, or in GITIAN_HOME, until you delete it.

Help, output and exit codes

Help
gitian help [<command>]
gitian <command> --help
gitian --version

gitian help, --help or -h lists every command with one line about each. gitian help <command> prints one command's usage and help, and so does --help after any command. gitian --version prints the version. With no command at all, it prints the list on stderr and exits 64.

Results go to stdout and diagnostics to stderr. The exit code is 0 on success and 1 on a refusal or a failure. A command line it cannot read exits 64: an unknown command prints the list of commands, and unexpected arguments print that command's help.

The store

gitian init

Usage
gitian init

Creates the store at ~/.gitian, or at GITIAN_HOME: a Postgres data directory, the knowledge base's migrations, and the store's owner with its home knowledge base. It starts Postgres to migrate, and stops it after.

It prints where it created the store, with its tree and data directory, then the owner, local, and the id of its home knowledge base.

It refuses a home that already holds a store, and a data directory there that no stamp accounts for: it never touches one. A create that was interrupted starts over when you run it again.

gitian mcp

Usage
gitian mcp

What Claude Code runs. It serves the store's knowledge base over stdio as the MCP server gitian-kb, for the agent that runs it. The first session starts Postgres, and the last one to end stops it. It ends when stdin closes, or on SIGINT or SIGTERM.

Its stdout carries MCP messages and nothing else; its own lines go to stderr. Search is by words alone, so no query leaves the machine. Writes waiting in the outbox are tried when it starts.

It refuses with no store yet, while an upgrade is in progress or was interrupted, when creating the store was interrupted, and on a store of an older format, which needs gitian upgrade first.

gitian status

Usage
gitian status

Prints the store's path, its stamp, the Postgres tree it runs and its data directory, whether Postgres is running and its pid, and the live sessions. With Postgres running it also counts the docs, memories and journal entries, the writes waiting for a home and those held for you, the personal home, and any move under way, kept archive or diverged move.

It never starts Postgres: with it stopped there are no counts. It changes nothing. With no store, it says to run gitian init.

gitian backup

Usage
gitian backup [--out <dir>]

Dumps the store into a new directory: <home>/backups/<time>, unless --out names one.

--out <dir>
Where the dump goes; --out=<dir> works too. A relative path is taken from where you run it. The directory must not exist yet.

A backup is a session like any other: it starts Postgres if nothing is running, and stops it after if it was the last. It prints where the dump went and the tree that made it. It refuses a destination that already exists, and never writes over one.

gitian upgrade

Usage
gitian upgrade

Moves the store to this program's Postgres tree and applies its migrations, after a dump into <home>/upgrades/<time>. A new major version goes through pg_upgrade when both trees carry it, and is restored from the dump when not.

It prints the tree and data directory it moved from and to, how, the number of migrations applied, and where the dump is kept. From an install it adds that gitian prune frees what is no longer used. Its progress goes to stderr.

  • It refuses while any session is live, naming each one with its pid. Close them and run it again.
  • It refuses a tree of an older major than the store: there are no downgrades.
  • An interrupted upgrade resumes when you run it again. One toward another tree is refused until that one finishes.
  • If the store's tree does not start and dump, a fresh upgrade leaves the store unchanged. Once an upgrade is under way and the old tree no longer starts, the store is rebuilt from the dump.

gitian prune

Usage
gitian prune [--yes | --forget <home>]

Lists the installed versions and Postgres trees nothing uses any more, with the bytes they hold, and changes nothing. It works from an install only, and refuses from an unpacked tarball, whose files are not the installer's to remove.

--yes
Removes what it lists.
--forget <home>
Drops the record of a store deleted for good, at exactly the path recorded, and nothing else. Refused while a store is there.

It keeps, and says why:

  • the version current names, and the version prune runs from;
  • every version a live session runs, and every version when a session does not say which it runs;
  • the tree each kept version names;
  • the tree each store runs, and both trees while a store is upgrading.

It sees every store a program of this install has opened, wherever it is. A recorded store it cannot find now (a drive not mounted, say) keeps every tree, and its record stays.

It removes only versions and trees. A link is removed, never what it points at. A directory is moved aside before it is emptied, so a version or a tree is there whole or not at all. It never touches a store. It exits 1 when something could not be removed.

It refuses while an install is running, while a store is busy (an upgrade, or a session starting or stopping), and when a store record cannot be read.

Claude Code

gitian setup

Usage
gitian setup

Wires the node into Claude Code, in this order:

  • It adds a user-scoped stdio MCP server named gitian-kb that runs gitian mcp, through claude mcp add when claude is on your PATH, or by editing Claude Code's config itself when it is not.
  • It checks that the server connects, with an MCP handshake of the exact command it registered.
  • Only then, in one write to Claude Code's user settings, it denies the Gitian plugin's own gitian-kb server, sets GITIAN_KB_URL for the plugin's hooks, and adds the rules that refuse agents the commands only a person runs and the store's tokens.

From an install, the server runs current/bin/gitian mcp, so an upgrade needs no new setup. The variables that place the store go with it when they are set.

A gitian-kb server and a GITIAN_KB_URL already there are saved first, in a record beside Claude Code's settings, for gitian uninstall to put back. The settings file is edited as text: no other byte in it moves. Running setup again records nothing twice, and adds any rule a newer version brings.

It prints the server it added and the command it runs, that it connected, and each change to the settings. Last comes one line that says how to undo it all by hand.

  • It refuses with no store, or a store gitian mcp would refuse.
  • It refuses a store path holding * ? [ ] { } ! or a backslash: the rules would read it as a pattern. Move the store with GITIAN_HOME.
  • It refuses a settings file that is not a JSON object, or whose env, permissions.deny or deniedMcpServers has the wrong type.
  • When the settings already hold the node's GITIAN_KB_URL but there is no record, it refuses and says to run gitian uninstall on a terminal first.
  • Any failure (no connection, a claude run that fails or hangs, settings that changed while it ran) puts back the server that was there. When that cannot be done, it says how to finish by hand.

gitian uninstall

Usage
gitian uninstall

Takes the node out of Claude Code. First the settings: only what setup added comes out, and the GITIAN_KB_URL it saved goes back. Then the server: the one setup saved goes back, or the node's is removed. A gitian-kb server the node did not write is left alone.

Without setup's record, it asks on a terminal:

  • With the node's GITIAN_KB_URL still set, it asks which knowledge-base server Claude Code should go back to: Enter for https://gitian.dev, the plugin's own, or another URL. The deny rules stay, since with no record they look like your own.
  • With the plugin's server denied and the node's registered, it asks before it takes out both.
  • With neither, the settings hold nothing of the node's, and only its server, if it is there, is removed.
  • In the first two cases, with no terminal, it refuses.

A record that is not whole may still save the server from before. Since anyone could have edited it, that server goes back only on your yes at a terminal, and only when it is a plain stdio server or a plain http or sse one. The question shows the command it runs or the address it connects to. With no terminal it stays out, uninstall says so, and the record stays.

It prints the one-line undo by hand on every run, and in every refusal. It never touches the store, so it works with the store broken or gone.

Commands only a person runs

Some commands decide where your knowledge goes, what crosses from one server to another, or what is thrown away. They are meant for a person. Each needs a terminal on both its input and its output, and asks you to type back what it is about to act on: the host, the pair, the id or the address. Without a terminal, or with a wrong answer, it refuses before a byte leaves the machine, and the refusal tells the agent to ask you to run the command yourself.

setup has Claude Code refuse these to agents, because each is yours to decide: gitian connect, gitian disconnect, gitian route, gitian allow, gitian search-include, gitian outbox retry, gitian outbox drop, gitian publish, gitian forget and gitian personal-home. It also has Claude Code refuse agents reading or editing the store's tokens directory, and reading the node's keychain item, because they hold your sign-in to each home.

The terminal check and these rules are a speed bump, not a boundary: an agent with a shell can give a command a terminal of its own, spell it another way, or copy a file. Claude Code's sandbox is the boundary.

Homes

A home is gitian.dev or another Gitian server you sign the node into. Its knowledge bases are named by full address, such as acme@gitian.dev/team.

gitian connect

Usage
gitian connect <host>

Connects the home at <host>: a server name such as gitian.dev, or a loopback or LAN address. You type the host back, then sign in and approve in the browser it opens. If no browser opens, it prints the address to visit.

A server name must pass a two-way check: its domain points at a Gitian server, and that server answers for the name. It is reached over https only. A loopback or LAN address is its own name, and may be plain http.

The tokens go to the keychain, or to a file only you can read under the store. It prints the account it connected as. A server that does not say who you are is reached by full addresses only.

  • It refuses a host with a path, a query, a fragment or credentials in it.
  • It refuses a name that now points at another server than the one it was connected to, and a server already connected under another name.
  • It refuses a sign-in as another account than the one the home was connected with: its routes, allows and ids are not carried over. Disconnect it and connect again.
  • Reconnecting is how a suspended home comes back. When another account had answered for it, its routes and allows are dropped, to be confirmed afresh.
  • A connect that fails revokes the grant it got and keeps nothing.

It is meant for a person. setup has Claude Code refuse it to agents (why).

gitian disconnect

Usage
gitian disconnect <home>

Revokes the home's tokens where it answers, removes them, and forgets everything about it: its cache, its routes and its allows. If the tokens cannot be removed from the keychain, it says to remove the gitian-node item there yourself.

It refuses while writes for the home wait in the outbox: retry or drop each one first.

It is meant for a person. setup has Claude Code refuse it to agents (why).

gitian homes

Usage
gitian homes

Lists every connected home from what the node keeps: its address, the account it signed in as, and whether it is suspended. Under each come its knowledge bases by full address (read only, or in every search), the routes you confirmed (or stale ones), the routes it offers with the command that confirms each, and the allows.

The one thing it asks a home is whether a move you forced off here committed there after all. Such a move is reported as diverged. Anyone may run it.

gitian route

Usage
gitian route <owner> <home>

Confirms that a doc or journal entry about a repository <owner> owns, written with no knowledge base named, goes to <home>. The home must route that owner itself, for the account you connected as. One owner has one home.

Without a confirmed route, such a write lands in the local knowledge base, with a warning when a home offers a route. When the home later routes the owner elsewhere, the route is stale and counts as none. Memories are never routed by repository.

It refuses an owner already confirmed to another home (disconnect that one first, if the owner moved), a home that does not say which owners it routes, and a home that is suspended or not connected.

It is meant for a person. setup has Claude Code refuse it to agents (why).

gitian allow

Usage
gitian allow <from> <to>

Lets a session that read from <from> write to <to>. The node tracks where text came from: reading from a home, or reading a local item whose text came from one, marks the session with that home. Without an allow, its writes to any other home are refused, naming what was read and this command. Local writes always go through.

It refuses one home named twice, and a home that is suspended or not connected.

It is meant for a person. setup has Claude Code refuse it to agents (why).

gitian search-include

Usage
gitian search-include <owner@server/kb> on|off

A home's knowledge base is searched only when a search names it. on puts it in every search; off takes it out again. You type its full address back. When a home does not answer a search in time, it is named in unreachable_kbs with a warning, and the rest of the results stand.

It refuses anything but a full address, a home not connected, a suspended home (for on), a home that does not say which knowledge bases you have there, and a knowledge base it does not list for your account.

It is meant for a person. setup has Claude Code refuse it to agents (why).

gitian outbox

Usage
gitian outbox [retry <id> | drop <id>]

A write to a home that did not answer waits here, pinned to the home, the account and the knowledge base it was written to. It queues only when the home is not suspended, the node knows that account and that knowledge base, and the tool takes an idempotency key. Topics and categories never queue. A queued write is not written yet, and the agent is told so.

Each waiting write is sent once, in the order they were queued. It goes when gitian mcp starts, after any answered call to its home, and now and then besides. Before each send the node checks the home, the account, the knowledge base and every allow the write used. The first check that fails holds the write for you, and a held write holds back every later one that touches a knowledge base it touches.

outbox
Lists every waiting write by id, tool, full address and time queued, why a held one is held, and what was sent or dropped lately. It needs no terminal, so an agent may run it.
retry <id>
Checks the write against its home again and sends it, in its turn. Refused, with nothing changed, while a held write is ahead of it; it names that one.
drop <id>
Throws the write away unsent. Refused while that home's writes are being sent.

Reconnecting a home never releases a held write: only a retry sends it again. A write held on a conflict is never merged. Drop it, and write it again.

Only a person retries or drops a write. setup has Claude Code refuse it to agents (why).

Moving a knowledge base

gitian publish

Usage
gitian publish <kb> --to <owner@server/home | server> [--as <slug>] [--check]

Moves the local knowledge base <kb>, every revision of every item, to a connected home. home goes into your own home there. Any other knowledge base lands as a new one of yours on the server. You type the knowledge base and where it goes back.

--to <dest>
Where it goes: your home's full address there, owner@server/home, or the server alone. Any knowledge base but home takes the server alone.
--as <slug>
Another name for the new knowledge base on the server. Not for home.
--check
Shows where it would land, how many items and revisions go, and anything in the way. It freezes nothing, and aborts the check on the home.

A move goes in steps, and each is recorded before the next:

  • Before anything freezes, it refuses items with more revisions than a home takes for one item, naming each.
  • Items another home's text reached stay on this machine unless you type include. Items whose only outside text came from the destination go, and are listed.
  • The knowledge base is frozen: agents' writes to it are refused, and reads go on.
  • It is sent. Anything in the way on the home stops the move before anything is approved.
  • You approve it on the home's own page, which opens in your browser. The page says that whoever runs that server will be able to read this knowledge base, and shows where it lands. Approve commits it; Deny ends it. The node waits until a time it prints, then aborts.
  • Every revision that landed is checked against what was sent. A copy that checks out is kept under the store's archive/, and the knowledge base is then served from the home.
  • For home, memories and a bare home go there from then on, and what stayed is served as local. It then asks whether to put your home there in every search.

Run the same command again to resume a move that stopped. It exits 1 when the move stopped short, or ended without moving.

Ending a move
gitian publish --abort <kb> [--force]

--abort ends a move the home confirms did not commit, and unfreezes the knowledge base. One the home says committed goes on to be checked and served from there. With no answer, or an import the home does not know, it stays frozen. --force unfreezes it whatever the home says. Should that home later say it committed after all, gitian homes and gitian status report the move as diverged.

It refuses local, and home once it has moved. It refuses a knowledge base that is already moving to another home, a destination that is not connected, suspended or does not say who you are, an address that is not your own home there, and a revision too large for one request to the home.

It is meant for a person. setup has Claude Code refuse it to agents (why).

gitian forget

Usage
gitian forget <kb | import id>

Removes the archive a finished move kept, and nothing else. It refuses any move that was not checked and switched over: until then, the archive is the only copy not proven to be on the home.

It is meant for a person. setup has Claude Code refuse it to agents (why).

gitian personal-home

Usage
gitian personal-home <owner@server/home>

For another machine of yours whose home stayed local. From now on, memories and a bare home go to your home on the server, pinned to that server, that account and that knowledge base. This machine's own home is served as local. It then asks whether to put your home there in every search.

The home must be connected and say who you are, and the address must be your own home there. It refuses while home is being moved by gitian publish. Once pinned, a home that answers as another account, moves to another server or stops listing that knowledge base is refused, and nothing it would have taken is written locally instead.

It is meant for a person. setup has Claude Code refuse it to agents (why).

Environment variables

GITIAN_HOME
The store, as an absolute path. By default ~/.gitian.
GITIAN_NODE_RUN_DIR
A private directory of your own for the run directory, as an absolute path. Every program that opens one store must see the same value; setup does not pass it to the server it adds.
XDG_RUNTIME_DIR
When the store's own run directory would make too long a socket path, the run directory goes under this, if it is yours alone. Next come the temporary directory on macOS, then /tmp/gitian-node-<uid>.
CLAUDE_CONFIG_DIR
Where setup and uninstall find Claude Code's config.
HOME, PATH
Where ~ is. PATH is where setup and uninstall look for claude, and where the node finds secret-tool on Linux.

setup passes GITIAN_HOME to the server it adds, when it is set. No PG variable reaches Postgres or its tools.

What setup changes in Claude Code

.claude.json
In CLAUDE_CONFIG_DIR, or ~/.claude.json: the user-scoped gitian-kb server that runs gitian mcp.
settings.json
In CLAUDE_CONFIG_DIR, or ~/.claude/settings.json: the deny of the plugin's server, GITIAN_KB_URL, and the deny rules.
gitian-kb.before-node.json
Beside settings.json: the record of what setup replaced and exactly what it added, for uninstall.

In the settings, setup adds:

settings.json
deniedMcpServers  {"serverName":"plugin:gitian-kb:gitian-kb"}
env               GITIAN_KB_URL=http://gitian-node.invalid
permissions.deny  the rules below
  • The deny of the plugin's server leaves the node's as the only knowledge base an agent sees.
  • GITIAN_KB_URL is the key the plugin's hooks keep the node's state under. Nothing ever connects to it.
  • To permissions.deny, Bash(gitian <command>:*) for each command only a person runs.
  • Read and Edit of the store's tokens directory, by its absolute path, its real path and its ~/ form.
  • Reads of the node's keychain item: security find-generic-password by the service or label gitian-node, security dump-keychain, and secret-tool lookup or search for that service. Never security or secret-tool as a whole.

It adds only what is not there already, and uninstall takes out only what it added. A rule you already had is never touched.

Next: the demo repositoryAnnotations, docs and markdown rendered from a real repository.