utopia-ia/elffuss-braid public
AGENTS.md
Instructions for coding agents. Part 1 is for when someone asks you to install braid in a project and set it up for agents. Part 2 is for working on braid itself, in this repository.
Braid is a version control system for repositories where many agents land changes at the same time. Each agent works in a workspace of its own over one shared store, and landing on the main branch is one short step that agents take in turn: no fetch, rebase and push loop. Git stays at the edges: braid imports a project's whole history from git, and sends what lands back to the project's git remote.
Keep git as the source of truth: the project's git remote holds everything that matters, and nothing lives only in braid.
1. Installing braid and setting it up in a project
Read this part whole before you run anything, and run its commands exactly as they are written.
Install
Braid builds from source with cargo. It needs:
- Rust 1.89 or newer (
rustc --versionsays which; https://rustup.rs installs it), a C compiler (cc), git, and a POSIX shell such as bash: every command here is written for one. - Linux, macOS or another Unix-like system. Windows is not tested yet: use WSL there.
- The network, and permission to write in cargo's directory,
~/.cargo. A sandboxed harness blocks both by default: ask the user to allow them, or to run the command themselves.
cargo install --locked --git https://github.com/KikoCis/elffuss-braid --tag v0.1.0 elffuss-braid-cli
It compiles braid and its dependencies from source, which takes a while:
give the command a long timeout, or run it in the background, since a
command cut short starts again from the beginning. It puts a braid binary
in cargo's bin directory, ~/.cargo/bin unless CARGO_HOME says
otherwise. If that directory is not on PATH, call braid as
"$HOME/.cargo/bin/braid" wherever this file says braid: a harness may
not keep a changed PATH from one command to the next. Running the same
command again replaces an older braid with this version.
Is it installed, and set up here?
In the project root, on its main branch:
braid --version # "braid 0.1.0", or newer, once it is installed
braid cat-object "$(git branch --show-current):AGENTS.md" | grep -q '^<!-- braid:start -->' && grep -q '^name = .' .braid/config && grep -q '^email = .' .braid/config && echo "braid is set up here"
- Before braid is installed,
braid --versionfails with "command not found", as it does while cargo's bin directory is not onPATH. An older braid, or one that saysagentsis not a subcommand, needs the install command again. - The second line prints "braid is set up here" once the setup below is
finished: braid's copy of the branch has the braid section of
AGENTS.md, committed, and.braid/confignames who signs. Then skip to "Every agent session, from then on". If it fails instead, set the project up as below, whether braid says "not inside a braid repository", where it was never set up, or an earlier setup stopped half way: every line of the setup is safe to run again.
Set up a project
First read the project's AGENTS.md, CLAUDE.md and the like for rules
about git: branches, pull requests, how to commit. Look too for what braid
does not run, or does not check out as git does:
- git hooks, in
.git/hooksor wheregit config core.hooksPathsays (the*.samplefiles git puts in.git/hooksnever run, and do not count); - submodules, which
.gitmoduleslists: each one is an empty directory in every workspace; - filters,
filter=in.gitattributes: a workspace holds the bytes git stores, so Git LFS's pointer files rather than their content, and what git-crypt encrypts stays encrypted; - a main branch that takes changes only through pull requests.
Tell the user what you found, and if any of it clashes with agents landing
on the main branch, ask how to go on before you set anything up. Where the
hooks run checks, such as tests or a linter, offer to write those commands
into AGENTS.md, outside the braid section, so that every session runs
them before it lands.
Then list the project's git remotes (git remote -v): what agents land
reaches the user's checkout through one, which the commands here call
origin; if it has another name, write that instead. With no remote at
all, what agents land stays in braid: offer to make one (see "No remote?"
below). And if the project has no CLAUDE.md, ask whether to add one,
since Claude Code reads CLAUDE.md rather than AGENTS.md: with a yes,
run touch CLAUDE.md before the commands below, and braid agents init
makes it include AGENTS.md.
Then work in the root of the project's git checkout, on its main branch,
with nothing to commit (git status shows no staged or modified files;
untracked files do not matter) and nothing new to pull
(git pull --ff-only; skip it when the branch has no upstream, which is
when git rev-parse --abbrev-ref '@{u}' fails). In a shallow clone, run
git fetch --unshallow first: braid imports the whole history. Run the
lines of each block below one at a time, and stop at the first one that
fails. Every line is safe to run again, so once the cause is fixed, start
again from the first line of its block.
test -d .braid || braid init # .braid/: the store and the agents' workspaces
mkdir -p "$(git rev-parse --git-path info)"
grep -qsxF .braid "$(git rev-parse --git-path info/exclude)" || echo .braid >> "$(git rev-parse --git-path info/exclude)"
test -f .braid/config || printf 'name = %s\nemail = %s\n' "$(git config user.name)" "$(git config user.email)" > .braid/config
if grep -q '^name = .' .braid/config && grep -q '^email = .' .braid/config; then braid git import . && braid agents init; else echo 'braid: .braid/config has no name or no email: ask the user who signs' >&2; false; fi
The second and third lines make git ignore every
.braidin this checkout, and only in this one: braid's directory, and the.braidfile that marks each workspace, so that nothing of braid's is ever committed with git..braid/confignames who signs the changesets agents make, here the same person as git's commits. The last line imports the project's whole history, every local branch and tag, and then writes the rules for agents intoAGENTS.md, but only once the file has a name and an email. Until then it stops and says so, as it does when git has nouser.nameoruser.email: every commit and landing would fail with "no author", and thegit commitbelow would fail too. Ask the user for the name and the e-mail address to use. With their answer, set them for this checkout, and let the setup write the file anew:git config user.name "<name>" git config user.email "<email>" rm .braid/config # then run the setup again from its first lineMost harnesses read
AGENTS.md. Claude Code readsCLAUDE.mdinstead, and Gemini CLIGEMINI.md:braid agents initadds the line@AGENTS.mdto each of them that exists, so that they read the section too. In Claude Code, each braid command asks for permission unless the project allows it: offer to add"Bash(braid:*)"topermissions.allowin.claude/settings.local.json, the user's own settings for this checkout, which are never committed: braid is set up in this checkout only.braid agents initwrites a section intoAGENTS.md, creating the file if there is none, between a<!-- braid:start -->line and a<!-- braid:end -->line. The section tells every agent session to work in a workspace of its own and to land through braid, and names the branch agents land on:main,master, or the project's only branch. With several, it asks for--branch <name>, which must name a branch the project has.--dry-runshows what it would write. Text outside the markers is never touched, and running it again rewrites the section in place.
Commit what braid agents init wrote, so that every workspace and every
clone has the rules, then import that commit too. From this commit on,
agents in every clone of the project read the section: tell the user so
before you commit. Where braid agents init found the files as they
should be already, there is nothing to commit, and the git commit line
does nothing.
git add AGENTS.md
if [ -f CLAUDE.md ]; then git add CLAUDE.md; fi
if [ -f GEMINI.md ]; then git add GEMINI.md; fi
git diff --cached --quiet || git -c user.useConfigOnly=true commit -m "Set up braid for agents"
braid git import . # braid's copy of the branch takes the commit
braid cat-object "$(git branch --show-current):AGENTS.md" | grep -q '^<!-- braid:start -->' && grep -q '^name = .' .braid/config && grep -q '^email = .' .braid/config && echo "braid is set up here"
The last line is the check from "Is it installed, and set up here?": it
prints "braid is set up here" once the commit is in braid. With
user.useConfigOnly, git refuses to commit rather than make up a name and
an address from the machine; where it says "Author identity unknown", set
them as above, then run this block again. If AGENTS.md, CLAUDE.md or
GEMINI.md is a symbolic link, braid agents init writes the file it
points to, and names it: git add that file as well.
The commit stays in this checkout until it is pushed: the next
braid git sync takes it to the git remote, with what agents land, and
other clones get the rules from there (see "Keeping the git remote up to
date"). Tell the user so, and offer to sync now.
Every agent session, from then on
The section in the project's AGENTS.md tells each session what to do,
with the branch it names where the commands here say main. In short:
Only where braid is set up. A checkout with no
.braiddirectory in its root (a fresh clone, CI, another machine) does not use braid: agents there work with git, as the project's other rules say, and set braid up only when the user asks. With.braidbut nobraidcommand, braid is not onPATH:"$HOME/.cargo/bin/braid"may be there, or it needs installing.Never edit files,
git add,git commitorgit pushin the project root. It is the shared checkout, where the user works. Every session works in a workspace of its own, under.braid/work/.Start with a workspace named for the session: 1 to 64 ASCII letters, digits,
.,_or-, starting with a letter or a digit.braid workspace listshows the names taken, and a name that is taken is refused. Wherever it runs in the project,braid workspace addputs the workspace in.braid/work/<name>of the project root, and it refuses a branch the project does not have. Then edit, build and test only in that directory. A workspace is a whole checkout of the branch, so builds in it start from scratch.braid workspace add agent-1 --track main cd .braid/work/agent-1 # from the project rootNo git in the workspace. A workspace holds a
.gitfile that points nowhere, sogitfails there with "not a git repository" instead of acting on the shared checkout around it, wheregit stash,reset,checkout,restore,clean,addorcommitwould change the user's files. Do not get around it withgit -CorGIT_DIR. A build or test script that finds the project with git (git rev-parse --show-toplevel) fails in a workspace too: run its steps yourself. To see what an edit changed, compare the file with the workspace'sbase, whichbraid status --jsongives, from the workspace's root:braid cat-object <base>:<path> | diff -u - <path>. To undo an edit, write the base's version back withbraid cat-object <base>:<path> > <path>; a file the workspace added has none, so delete it.Record and land from the workspace.
--agent(orBRAID_AGENT) names the session in the op log and in every changeset it makes; pass it every time, since a harness may not keep variables between commands. If the shell does not keep its directory either, add--workspace agent-1and run the commands from the project root. The hints braid prints, andnextin its JSON, repeat the--agentand--workspacegiven.braid --agent agent-1 status --json braid --agent agent-1 commit -m "Say what changed and why" braid --agent agent-1 land --jsonThere is no staging area:
commitrecords every change in the workspace, or only the paths it is given (braid --agent agent-1 commit -m "..." <path>...), so readbraid statusbefore each commit.landrefuses while anything is left uncommitted ("the workspace has uncommitted changes ...; commit them first"). Building or running the project writes files too: those that.gitignoredoes not list are new files like any other. Delete them, or list them in.braidignore, which must then list itself too, or it is a new file to commit: for Python's__pycache__/, runprintf '%s\n' .braidignore __pycache__/ >> .braidignorein the workspace's root. Only.gitignoreand.braidignoreapply in a workspace, not.git/info/excludeor a global excludes file: anything else that must stay local goes in.braidignoretoo. Braid runs no git hooks, so before you land, run the checks that the project'sAGENTS.mdorCLAUDE.mdgives.landputs the workspace's changesets onmain, as a fast-forward or rebased onto whatever landed first.Before a new task,
braid --agent agent-1 updatebrings the workspace ontomain.status --jsonsays how far behind it is (behind_by).When the session finishes, what it landed is on braid's
mainonly. The user's checkout and the git remote get it withbraid git sync, thengit pull --ff-only, both from the project root (see "Keeping the git remote up to date", which also says what to do when either fails). The session tells the user so, and offers to run them: when to sync is the user's call. Wheregit remote get-url originfails, the project has no remote of that name: the session asks the user which of thosegit remotelists to sync with, or, where it lists none, says so and offers to make one first (see "No remote?").Done: once everything has landed,
braid workspace remove agent-1from the project root. It refuses while the workspace holds work that has not landed.Every command takes
--json. Exit status 2 is a conflict, and 1 a failure, which braid prints as text on standard error, with nothing on standard output, even with--json; onlygit syncandfsckprint their report as well when they exit with 1.Changesets are signed by
BRAID_AUTHOR("Name <email>"), or else by thenameandemailin.braid/config. With neither,commit,landandupdatefail with "no author", andbraid statuslists it first among what stops a commit: the session asks the user who signs, and writes the answer into.braid/configin the project root (the one file there that a session may edit) asname = <name>andemail = <email>lines. The merges thatbraid git syncmakes are signed otherwise: by the--agentthat ran the sync, with the email in.braid/config.New files that look like secrets (
.env*,*.pem,id_*) or are larger than 1 MiB are held back untilbraid track <path>:commitrefuses, naming them, and--forceleaves them out. Neverbraid tracka secret: move it out of the workspace.
Conflicts
When another agent landed a change to the same lines first, land exits
with status 2 and leaves main where it was, and update exits with 2 as
it writes the conflicts into the files. Exit status 2 also means a command
line braid could not parse, which prints only an error, so read the JSON:
a conflict's outcome is conflicts. Each conflict names its sides:
base, branch (what main holds now) and workspace (the session's
own change), and next says what to run.
braid --agent agent-1 update # exit status 2: conflict markers in the files
# edit the files until no marker is left; `braid status` lists what still blocks
braid --agent agent-1 commit # keeps the change's message; -m gives another
braid --agent agent-1 land --json
braid resolve <path> settles conflicts that are not about content, such
as a file deleted on one side and changed on the other. Never
commit --force while a rebase is in progress: it would commit the
conflict markers as they are.
Keeping the git remote up to date
Landings change braid's main, not git's. braid git sync brings the two
together: it fetches the remote's branch and imports it, then fast-forwards
braid's branch when only the remote moved, pushes braid's branch when only
braid moved, and when both moved, merges them and pushes the merge. The
push is a fast-forward, with a lease on what was just fetched, so the
remote's history is never rewritten. Braid runs no git hooks. It runs the
git binary with your environment, so it needs the network and the
credentials git push uses. Run it from the project root, when the
remote should have what landed: who runs it, and when, is the user's
call. Braid pushes to the remote's address, so the shared checkout's own
record of the remote (origin/main) does not move: git pull --ff-only
brings the checkout up to date. The commands here say main: write the
branch that the section names.
braid --agent agent-1 git sync "$(git remote get-url origin)" --branch main --dry-run --json
braid --agent agent-1 git sync "$(git remote get-url origin)" --branch main
git pull --ff-only # the shared checkout follows
With
--json,outcomeis one ofup_to_date,created,fast_forwarded,pushed,merged,conflicts,remote_movedorrejected.--dry-runwrites nothing.--agentnames the session in the op log, and in the merge a sync makes.Each changeset reaches git as a commit of its own, with an
agentheader that names the agent that made it.Exit status 1 with
remote_moved: someone pushed meanwhile; sync again. Withrejected, also exit status 1, the remote refused the push, as a protected branch does: ask the user. They may let braid push there, or have it push to a branch of its own, with--remote-branch <name>, to open a pull request from.Exit status 2 with
conflicts: braid and the remote changed the same lines. Nothing moved and nothing was pushed. Merge them in git, in the shared checkout, and sync again:git init --bare .braid/export.git # a scratch repository, which git ignores braid git export .braid/export.git --ref main git fetch .braid/export.git main git merge --ff-only FETCH_HEAD # the shared checkout takes braid's main git fetch origin main git merge --no-edit origin/main # the remote's: git stops at conflicts # if it stopped: fix those files and git add them, then git commit --no-edit --cleanup=strip git push origin main braid --agent agent-1 git sync "$(git remote get-url origin)" --branch main rm -rf .braid/export.gitBraid knows the commits it exported, so the sync after the push fast-forwards braid's
mainto the merge. Merge in this order, with braid's branch as the first parent: braid follows a branch's first parents to tell what a workspace has landed, so the workspaces carry on from the merge.If
git pull --ff-onlyrefuses, the shared checkout has commits of its own that the remote does not have, and what to do with them is the user's call.git pull --rebaseputs them on top of what braid pushed; thengit push, and a sync brings them into braid.
No remote? Any bare repository will do. With the user's yes, these lines,
run in the shared checkout on its main branch, make one next to the
project, named after it (../<project>.git, by an absolute path, which
braid reads the same from any directory), and push the main branch to it.
If something has that name already, choose another.
git init --bare -b "$(git branch --show-current)" "$PWD.git"
git remote add origin "$PWD.git"
git push -u origin "$(git branch --show-current)"
Across machines: BraidHub
Braid's store lives in one checkout. For agents on several machines, a repository can live on BraidHub, a braid server where people and agents sign in with GitHub and land on the same main branch, and which can keep a GitHub repository as its mirror. Its own guide for agents, https://braidhub.elffuss.com/agents.md, says how to sign in, publish a project, clone one, and when to ask the user first.
Undoing
braid op loglists every operation (imports, landings, syncs), newest first, with the agent that made it.braid --agent agent-1 undoreverts the newest one that is not undone yet, whoever made it, so read the log first. A landing undone leaves its changeset in the workspace that made it, ready to land again. A sync undone moves braid's refs back, but not the git remote: what it pushed stays there.- A change that landed under other changes cannot be undone that way. There is no revert command yet: land a change that puts the files back.
- To take braid out of a project: land what the workspaces hold, sync it
and run
git pull --ff-only; remove each workspace (braid workspace remove <name>, which refuses while work has not landed); delete.braid/, the.braidline of the file thatgit rev-parse --git-path info/excludenames, the braid section ofAGENTS.md(its two marker lines and everything between them) and the@AGENTS.mdline it added toCLAUDE.mdandGEMINI.md; and commit that with git. Thencargo uninstall elffuss-braid-cliremoves the command.
What not to do
- Do not edit files,
git add,git commit,git pushorgit pullin the shared checkout while you work: only setting up, syncing, merging a sync conflict and naming who signs in.braid/configtouch it, as above. - Do not run git in a workspace, or get around the
.gitfile that stops it there. - Do not share a workspace between sessions, or work in another session's workspace.
- Do not run
braid undowithout readingbraid op logfirst. - Do not
braid git exportinto the shared checkout or into the remote: it overwrites git refs of the same names.braid git syncis the way to the remote. - Do not
commit --forcepast conflict markers, and neverbraid tracka secret. - Do not delete
.braid/while a workspace holds work that has not landed and been synced: the workspaces and their changesets live there. - Do not force-push the branch braid syncs with, and do not keep anything only in braid.
2. Working on braid itself
Braid is written in Rust, edition 2024, and needs Rust 1.89 or newer. CI pins the toolchain to 1.99.0.
| Path | What it is |
|---|---|
crates/format | Object ids and the hashed format (frozen; see docs/spec/format-v1.md). No I/O. |
crates/engine | Change lists, merges, landing, ancestry and blame. No I/O. |
crates/store | The store: objects in shared segments, refs in the op log. |
crates/git | The git bridge, through gitoxide. |
crates/repo | A repository on disk: discovery, names, git import, export and sync. |
crates/wc | Workspaces: checkouts, status, commit, land and update. |
crates/cli | The braid command; braid agents init is crates/cli/src/agents.rs. |
crates/hubproto | The BraidHub protocol the client speaks: names, tokens, scopes, the object stream and the JSON bodies; docs/hub.md is its prose. |
crates/sim | Deterministic simulation of many agents landing at once. |
docs/ | The design, the format specification and the hub's protocol (docs/hub.md, docs/hub-agents.md). |
site/ | braid.elffuss.com, in English and Spanish; site/agents.md is part 1 of this file. |
Build and test
cargo build
cargo test --workspace
The tests and the quick benchmark read this repository's whole history: in
a shallow clone, run git fetch --unshallow first.
Before every commit
All of these must pass:
cargo fmt --all
cargo +1.99.0 clippy --workspace --all-targets --locked -- -D warnings
cargo clippy --workspace --all-targets -- -D warnings
cargo test --workspace
RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --all-features --locked
cargo deny check
cargo +1.89 check --workspace --all-targets
cargo +1.99.0 check -p elffuss-braid-format -p elffuss-braid-engine --target wasm32-unknown-unknown --locked
python3 docs/spec/check_vectors.py
python3 bench/run.py --quick
scripts/privacy-check.sh
CI runs all of them but the unpinned clippy, which catches the lints of
newer toolchains early, and it also runs each fuzz target for a minute with
cargo-fuzz, on nightly. The WebAssembly check needs its target
(rustup +1.99.0 target add wasm32-unknown-unknown), and the vector check
b3sum (cargo install b3sum --locked).
Rules
From CONTRIBUTING.md, in short:
- No code from git or any other GPL project: braid is Apache-2.0. The git
bridge uses gitoxide. Dependencies must be compatible with Apache-2.0
(
deny.tomllists the licences accepted). - The hashed formats (
crates/format, sections 1 to 5 of the spec) are frozen. Changing the bytes of an id, a tree or a changeset needs a new format version, with the spec and its golden vectors updated in the same change. - Tests come with the change, and a bug fix comes with a test that fails without it.
- Performance claims are ratios against git on the same machine, with the
script that reproduces them (
bench/run.py). Never publish absolute timings or describe the hardware. - Every source file starts with
SPDX-License-Identifier: Apache-2.0andCopyright (c) 2026 UtopiaIAin a comment. - Code and documentation are in English. The site has every text in English
and in Spanish (see
site/README.md). - The repository is public: no absolute paths, user names, real e-mail
addresses (use
example.org), hardware or timings in anything committed. - Part 1 of this file and
site/agents.mdsay the same thing, and a test checks it: change both together. The install command names the tag of the version inCargo.toml, and the test checks that too: a release bumps both.