All guides Agentic Society How-To

Operating your brain · Guardrail 01

Keep your repo alive inside your Company Brain

You put your brain in cloud storage so everything syncs. Then you put code in there too. One morning git says the repository is corrupt. Here is why, and the guardrail that turns it into a thirty-second problem.

🛟 Repo guardrail Read time ~12 min Last verified Aug 14, 2026
Level 1 · Use it

What actually goes wrong, in plain words, and what "safe" looks like. No setup needed. Start here.

Level 2 · Build it

Six steps to install the guardrail in any repo, with a check after each one.

Level 3 · Under the hood

The one rule that makes automatic cleanup safe, and what it deliberately does not solve.

Appendix

Recovery when it happens anyway, a glossary, and the wider habit this belongs to.

One rule for this whole guide

Wherever we name a tool we use, you will see a 🔁 Swap box with alternatives. We are showing you what worked for us, not prescribing it. This problem is identical on OneDrive, Dropbox, Box and iCloud Drive, and the fix is the same.

● Level 1 · Use it

The setup that quietly breaks

Almost everyone who builds a Company Brain arrives at the same arrangement, because each step is individually sensible.

Each step is fine. Together they put a database inside a file syncer, and those two disagree about what to do when the same file changes in two places at once.

The collision, in one sentence

Your .git folder is a database with strict internal filenames. Cloud storage resolves conflicts by renaming files. When it renames something inside that database, git can no longer find its own history.

Laptop agent commits Desktop you pull Cloud sync renames on conflict INSIDE .GIT was: objects/ab/4f9c2e now: objects/ab/4f9c2e 2 git: “object not found”

A single space in a filename, in the one folder where a space can never legitimately appear.

What it looks like when it hits you

It rarely announces itself as a sync problem. It shows up as git suddenly behaving as though your project has amnesia.

The mistake that turns a scare into a loss

The obvious fix is a script that deletes every oddly named file inside .git. Do not do that. Cloud storage sometimes renames the original rather than adding a copy next to it, so those "junk" files can be your only copy of a real git object. Deleting them is what actually destroys the repository. We learned this the expensive way: a cleanup like that removed 29 real objects from one of our repos, and it could no longer rebuild its own history.

What "safe" feels like instead

The goal is not to prevent this. You cannot, short of moving the code out of cloud storage entirely. The goal is that it becomes boring: caught automatically, impossible to miss, and cheap to undo.

The working rule, worth memorizing

The remote is the source of truth. The synced folder is a replaceable view of it. Nothing irreplaceable ever lives only in that folder.

If that stays true, corruption is an inconvenience. If it stops being true, corruption is data loss. Everything in this guide exists to keep it true.

🔁
We use Google Drive for the Company Brain and the local mount. Alternatively: OneDrive or SharePoint, Dropbox, Box, iCloud Drive. All of them resolve conflicts by renaming, so this guide applies unchanged. If you are on a corporate OneDrive with Files On-Demand, you will also meet the "file is a placeholder" variant, which the same session check catches.
● Level 2 · Build it

Install the guardrail in six steps

Roughly twenty minutes for the first repo, about three for every repo after that. Do them in order. Step 1 is the one people skip, and it is the one that prevents actual data loss.

1

Get everything irreplaceable out of the repo folder

~10 min · do this before touching git

If the repository ever needs to be deleted and re-cloned, anything that exists only in that folder dies with it. That is usually the real loss, not the git history. Ask what is in there that the remote has never seen:

git status --porcelain --ignored | grep '^!!' | sed 's/^!! //' \
  | grep -vE '^(dist/|node_modules/|\.git/|build/|target/)' | grep -v '__pycache__'

Sort every result into one of three homes:

What it isWhere it belongsWhy
Working documents, client material, invoices, exportsA sibling folder outside the repoStill syncs, but stops living inside a folder you may have to delete
Real project sourceCommit itThen the remote has it, which is the entire safety net
Machine-local secrets and configLeave in place, never commitPer-machine by design. Write down which ones a new machine needs
You'll know it worked when: the command returns only machine-local secrets, and you can name every one of them.
2

Prove the remote is real and current

~2 min

Everything below treats the remote as the backup. If there is no remote, or there is work sitting unpushed, fix that first.

git remote -v && git status --short && git log --oneline origin/main..HEAD
You'll know it worked when: a remote is listed and the last command prints nothing, meaning the remote has everything you have.
🔁
We use GitHub as the remote. Alternatively: GitLab, Bitbucket, Azure DevOps, or a self-hosted git server. Any remote works. What matters is that one exists and that you push to it.
3

Add the two scripts and the hooks

~3 min · copy-paste from the Starter kit below

Put clean-drive-drift.sh and repo-parity-check.sh in scripts/guardrails/, and the four hook files in .githooks/. Both scripts are plain bash and git, with no dependencies to install, so they work for any tool or person. Then activate them:

chmod +x scripts/guardrails/*.sh .githooks/*
git config core.hooksPath .githooks

Hooks live in the repo rather than inside .git, which is what lets them travel to every clone and every machine.

You'll know it worked when: git config core.hooksPath prints .githooks.
4

Tell every tool that touches the repo, not just the one you use

~4 min

The git hooks already cover everybody, because git runs hooks no matter who invoked the command. This is the extra layer, and it is the one that differs per tool:

  • Claude Code: a SessionStart hook in the project's .claude/settings.json that runs the cleanup and then the parity check.
  • Anything that reads AGENTS.md (Codex, Cursor and friends): they have no session-hook mechanism, so the instruction goes in the file they already read at the start. The block is in the Starter kit.
  • A human, or any tool you cannot configure: the same single command, ideally wired to a make check or npm script.
Do not wire only your own tool

A repo that documents this in CLAUDE.md but not AGENTS.md is protected for one tool and silently unprotected for every other one. Put the same block in both.

You'll know it worked when: opening the project in each tool prints the parity verdict before any work starts.
🔁
We use Claude Code as the primary harness. Alternatively: Codex, Cursor, Copilot, Aider, Windsurf, or no agent at all. The guardrail is plain bash on purpose, so nothing here depends on which agent you run.
5

Verify by breaking it on purpose

~2 min · do not skip this

Do not assume the install works. Reproduce the exact failure and watch the guardrail handle it. This takes a real git object, renames it the way cloud sync would, and checks that it comes back:

OBJ="$(find .git/objects -type f ! -name '* *' ! -path '*pack*' | head -1)"
mv "$OBJ" "$OBJ 2"                                 # simulate the rename
scripts/guardrails/clean-drive-drift.sh --fix      # must say RESTORED, not removed
[ -e "$OBJ" ] && echo "PASS: object restored" || echo "FAIL: object lost"
git archive HEAD >/dev/null && echo "PASS: repo intact"
This is the whole test

If the script removes that object instead of restoring it, you are running the naive version, and it will eventually delete something real. Stop and re-copy the script from the Starter kit.

You'll know it worked when: you see restored -> in the output, then both PASS lines.
6

Write the rule down where agents read it

~2 min

An undocumented guardrail gets bypassed by the next tool, or by you in six weeks. Paste the block from the Starter kit into AGENTS.md and CLAUDE.md. It needs to say three things: run the parity check first every session, never commit a filename ending in a space and a number, and if git reports corruption then stop rather than trying to repair in place.

You'll know it worked when: a brand-new session, in any tool, runs the check without being told to.
SESSION START parity check is this folder trustworthy? AFTER PULL post-merge, post-checkout restore anything sync renamed BEFORE COMMIT pre-commit no junk file rides into history BEFORE PUSH pre-push + fsck damage cannot leave the machine

Four moments, four automatic checks. You never have to remember to run any of them.

● Starter kit

Download the skill and hand it to your agent

You do not have to copy anything out of this page. Everything above ships as one package: the skill, the prompt, the written SOP, the three scripts, and the four hooks.

git-in-drive

One folder. Drop it into your agent's skills directory, or just point any tool at it. Plain bash and git, nothing to install.

Download git-in-drive

Inside the downloadWhat it is
SKILL.mdThe skill itself. An agent reads this and does the whole install, reporting each step.
PROMPT.mdThe same install as a fill-in-the-blanks prompt, for any tool that cannot load skills.
SOP.mdThe written procedure, to drop straight into your own Company Brain.
scripts/The cleaner that restores instead of deleting, the session parity check, and the safe mount reset.
hooks/pre-commit, pre-push, post-merge, post-checkout. These are what cover every tool.

Then say this

Unzip it, put the folder where your agent looks for skills, and ask for it by name from inside the repo you want to protect.

install the skill (Claude Code)

  
then, from inside the repo you want to protect

  
Two steps you should watch, whoever does the work

Your agent will report each step. Read two of them yourself. Step 1 lists everything in the folder your remote has never seen, which is what dies in a re-clone; decide where those go rather than letting anything move them for you. Step 5 renames a real git object and checks the guardrail puts it back. If it deletes it instead, stop, because that is the version that loses repositories.

Not using an agent?

The package works fine by hand. SKILL.md carries the same six steps with the exact commands, and SOP.md is the version to keep. It is about three minutes per repo.

🔁
We use Claude Code, so the skill lives in .claude/skills/. Alternatively: paste PROMPT.md into Codex, Cursor, Copilot or Aider, or follow SKILL.md yourself at a terminal. The guardrail is plain bash on purpose, so nothing here depends on which tool you run.

Prefer just the written procedure? Download the SOP as Markdown on its own.

● Level 3 · Under the hood

Why this is safe to run automatically

Optional reading. This is the reasoning that lets a script delete things inside your git database without you watching it.

+ The one rule that makes automatic cleanup safe

Git never puts a space in the filenames it creates inside .git. So a spaced name in there is always sync junk, never something git made. That single fact is what makes automation possible at all.

But "it is junk" does not mean "delete it", because there are two very different situations that look identical at a glance:

What you find inside .gitWhat actually happenedCorrect action
4f9c2e 2 exists, 4f9c2e is missingSync renamed the original. This file is your only copy.Restore it. Rename it back.
4f9c2e 2 exists, 4f9c2e is presentSync added a duplicate alongside an intact original.Delete the duplicate.

Nothing inside .git is ever deleted unless a correctly named file survives next to it. That is the difference between a working repository and a re-clone, and it is the entire reason this guide exists.

Found a spaced name inside .git e.g. objects/ab/4f9c2e 2 Does the same name without the “ 2” exist? NO YES RESTORE it this is the original, renamed Delete the duplicate the original is intact

The left branch is the one a naive cleanup gets wrong, and it is the one that costs you the repository.

+ Why a parity check, and not just a cleanup

Corruption is the loud failure. The quiet one is worse: the folder is intact but stale, or holds commits nobody pushed, and an agent reads it and reports the contents as current. Nothing errors. You just act on the wrong information.

So before trusting the folder, the check answers four questions and refuses to shrug at any of them: is the object store readable, does this match the remote, is the working tree clean, and are there conflict copies. Exit code 0 means all four passed. Anything else prints which one failed and the command that fixes it.

+ What this deliberately does not solve

Two machines editing the same file at the same time. No hook catches that. The parity check will tell each machine it has diverged, but by then the conflict already exists. The habit that prevents it is boring and effective: push before you walk away.

The root cause. The only arrangement that removes this class of problem entirely is one clone per machine on local disk, with cloud storage holding your brain and documents but not the git repository. That is more multi-machine, not less, because git itself becomes the sync layer, which is what git is for. If the parity check starts firing often, treat that as the signal that the convenience is now costing more than it saves.

🔁
We keep repos inside the mount because it makes them visible to the whole Company Brain across machines. Alternatively: clone to local disk and keep only documents in the cloud folder, or use a devcontainer or remote workspace. If your team is one person on one machine, cloning outside the synced folder is genuinely the simpler answer.
● Appendix

When it happens anyway

One day the check will report real damage. This is the calm version of that morning.

1. Confirm no gc, no prune 2. Clone fresh alongside the old one 3. Carry across local-only files 4. Rename old bin it next week

Everything already pushed is safe. That is what makes this a chore rather than a catastrophe.

Plain-language glossary

TermIn plain words
Repository (repo)A project folder that git is tracking, including its full history.
.git folderThe hidden database inside a repo that holds every version of every file. Damage here is what this guide is about.
ObjectOne item in that database: a file version, a folder listing, or a commit. Named by its content, so a renamed object is a missing object.
Remote / originThe copy of the repo on a hosting service. In this guide, the thing you can always fall back to.
Conflict copyThe extra file cloud storage creates when two machines change the same thing, usually named with a trailing space and a number.
Local mountThe folder on your computer that mirrors your cloud storage, so normal programs and agents can open the files.
Git hookA script git runs automatically at a certain moment, such as before a commit or before a push.
fsckGit's own integrity check. It walks the history and reports anything missing or broken.
Working treeThe visible files you actually edit, as opposed to the history stored in .git.

Read further

git fsck · verifying the object databasegit-scm.com Git hooks · what runs whengit-scm.com Git internals · how objects are storedgit-scm.com Claude Code · session and tool hooksdocs.claude.com Claude Code · CLAUDE.md project memorydocs.claude.com
The habit this belongs to

Every guardrail in the Agentic OS follows the same shape: assume the failure will happen, make it loud, and make recovery cheap. You are not trying to build a system that never breaks. You are trying to build one where breaking costs thirty seconds and nobody loses a day.