File claims
A claim gives one session the right to write one file. Before your agent edits a file, the kit’s hook asks the coordinator to claim the file’s path for your session. If another session holds that path, the coordinator refuses, and the hook stops the edit before the file changes.
Claims cover file paths only. Zentri does not claim functions, types, or other symbols. When two sessions change the same symbol in different files, live overlap detection tells them.
Claims are one of the three catches. They catch two running sessions that edit the same file.
How it works
Section titled “How it works”One holder per path
Section titled “One holder per path”The coordinator keeps claims in the file_claims table. Each row names a project, a session, a path, the mode write, and an expiry time. A partial unique index, file_claims_one_active_idx, allows at most one unreleased row for each project and path. The database enforces that rule. A bug in the claim code can refuse a claim wrongly, but it cannot give one path to two sessions.
Path normalization
Section titled “Path normalization”The coordinator stores and compares each path in one form, which Normalize in pkg/paths produces. Normalize takes these steps:
- It turns
\into/and applies Unicode NFC. - It rejects an absolute path or a drive letter.
- It drops empty and
.segments and resolves... - It folds case when the project was created with
case_insensitive_paths.
Normalize also rejects a path that names the repository root, contains a NUL byte, is not valid UTF-8, escapes the repository root, or is longer than 1024 bytes.
Grants, denials, and expiry
Section titled “Grants, denials, and expiry”A claim request names one or more paths. The coordinator decides each path on its own, so one request can grant some paths and deny others. The response has a granted list of claims and a denied list. Each claim carries id, project_id, session_id, path, mode, acquired_at, and expires_at. Each denial carries the path and its holder. A holder carries session_id, user_id, user_handle, intent_id, intent_summary, acquired_at, and expires_at. The intent_summary is one line of at most 160 characters from the holder’s intent.
A claim expires 30 minutes after the coordinator grants or renews it. These rules keep claims alive or end them:
zt startruns a heartbeat next to the agent every minute. Each beat moves the expiry of every live claim of the session to at least 30 minutes from now.- A claim request for a path the session already holds renews that claim the same way.
- The sweeper in
zentri-server serveruns every--sweep-interval, 1 minute by default. It releases each claim whose expiry passed. - A claim request for a path whose claim expired releases the old claim first, then grants the path.
The claim rate limit is counted in Postgres, one token bucket per session in claim_rate_buckets. Every coordinator on the database draws from the same bucket, and a restart does not reset it. A request is charged in its own transaction, so a request that fails costs nothing.
Release
Section titled “Release”Each released row records a release_reason.
release_reason |
When the coordinator sets it |
|---|---|
explicit |
The agent calls zentri_release_file, or the session, its owner, or an admin calls POST /v1/sessions/{session_id}/claims/release. |
session_end |
The session reaches done, failed, or abandoned. zt done ends a session as done. The coordinator marks a session abandoned after 10 minutes with no heartbeat. |
waiting_human |
The session moves to waiting_human. A waiting session holds no claims, and its claim requests get 409 session_waiting until it runs again. |
expired |
The expiry passed with no renewal. |
A claim request from a session that ended gets 409 session_ended.
Refusals and notices
Section titled “Refusals and notices”Each denial names the holder, so the agent knows whom to ask. The coordinator also writes a notice to both sessions. The notice kind depends on whether the requesting session already changed the file.
| Notice kind | Written when | The requesting session reads | The holder reads |
|---|---|---|---|
claim_conflict |
A claim is denied before an edit. | <path> is held by @ana's session. Do not write it another way. |
@ben's session asked for <path>, which you hold. Release it when you are done. |
unclaimed_edit |
A claim with already_edited is denied. The file has changed. |
You edited <path>, which @ana's session holds. Do not edit it again until that session releases it. |
@ben's session edited <path>, which you hold, without a claim. Check the file before you write it. |
Notices reach the agent in a short digest at the end of hook output and tool results. Live overlap detection describes the digest.
Limits
Section titled “Limits”| Limit | Value | When it is exceeded |
|---|---|---|
| Paths in one HTTP claim request | 500 | 400 invalid_request |
Paths in one zentri_claim_file call |
50 | The tool refuses the arguments. |
Paths in one zentri_release_file call |
500 | The tool refuses the arguments. |
| Live claims per session | 500 | 429 claim_quota_exceeded |
| Claim requests per session | A burst of 60, then 1 a second. A pure renewal is free. | 429 claim_rate_limited |
| Path length | 1024 bytes | The path is refused. |
| Retries when a path changes hands | 3 | 409 claim_contended |
A request counts as a pure renewal when the session already holds every path in it.
How kits claim before an edit
Section titled “How kits claim before an edit”The kit that zt start writes for your agent runs zentri hook <agent> <event> at these points:
| Agent | Before an edit | After a shell command | When the hook itself fails |
|---|---|---|---|
| Claude Code | PreToolUse on Edit, Write, NotebookEdit |
PostToolUse on Bash |
The edit is refused (onFailure: block). |
| Codex | PreToolUse on apply_patch and Bash |
PostToolUse on Bash |
Codex lets the edit through. |
| OpenCode | execute.before on edit, write, and patch |
execute.after on the shell tool |
The plugin rejects the edit. |
| Generic MCP | No hook | No hook | Not applicable. |
Your agent runs with your own credentials. Zentri never collects, proxies, stores, or resells model access or consumer subscription tokens. The hook sends the coordinator the paths and the session token.
The pre-edit hook takes these steps:
- It reads the tool call and finds the paths the edit changes. It resolves symlinks and drops paths outside the worktree, under
.zentri/, or with a.gitsegment. - It claims the paths. It retries connection errors, timeouts, 5xx answers, and 429 answers for about 8 seconds, and it always decides within 10 seconds. Each agent gives the hook 30 seconds.
- If every path is granted, it allows the edit and adds the notice digest to the agent’s context.
- If a path is held, it denies the edit with this message, then the digest:
Zentri: another session holds a file this edit would change.- src/report.go is held by @ana (session 6fce6c79, working on "eng 301 add csv export reports page")Work on something else, or ask the holder to release it, then retry. Do not write the file another way.The message lists at most 5 held files, then - and N more. The hook also denies the edit when it cannot read the tool call and when it panics. When the coordinator answers 401, 403, 404, or 409, the hook denies with a message such as Zentri refused this edit: the session may have ended (HTTP 409).
When the coordinator is unreachable
Section titled “When the coordinator is unreachable”Edits fail closed. When the coordinator does not answer within the retry budget, the hook denies with this message:
Zentri coordinator unreachable. Wait and retry this edit. Do not write the file another way.A lead can set the project’s edits_fail_open. With it set, the hook lets the edit through and tells the agent so:
Zentri coordinator unreachable, and this project lets edits go ahead anyway (edits_fail_open). Zentri did not claim the edit to src/report.go, so another session may be changing the same file. Tell the user.zt start copies edits_fail_open into the session’s state file, mode 0600, next to the session token file. The hook reads the flag there and not from .zentri/session.json, because the agent can write its own worktree. If the hook cannot trust the state file, it denies. A change to edits_fail_open applies to sessions that start after the change. In an openshell sandbox, the hook reads the flag only from ZENTRI_EDITS_FAIL_OPEN, and only when the root-owned marker /etc/zentri/sandbox exists.
Fail-open applies only when the coordinator does not answer. When the coordinator answers that another session holds the file, the hook denies the edit.
After a shell command
Section titled “After a shell command”A shell command can change files without an edit tool. After each shell command, the post-shell hook runs git status --porcelain=v1 -z --untracked-files=all and claims every changed path with already_edited set, in batches of 500. When another session holds a changed file, both sessions get an unclaimed_edit notice, and the agent reads this instruction:
Zentri: your last shell command changed files that another session holds.- src/report.go is held by @ana (session 6fce6c79, working on "eng 301 add csv export reports page")Revert those files now (git checkout -- <path> for a tracked file; delete a new one), and leave them alone until the holder releases them.The post-shell hook never blocks. If the coordinator does not answer within 3 seconds, the hook prints a warning and the agent goes on.
At commit time
Section titled “At commit time”For git commands in the agent’s environment, the kit points core.hooksPath at .zentri/git-hooks in the worktree. Each script there runs the repository’s own hook first. The pre-commit script then runs zentri hook git pre-commit, which claims the staged paths with already_edited set and warns about held files:
zentri: warning: this commit changes files another session holds:- src/report.go is held by @ana (session 6fce6c79, working on "eng 301 add csv export reports page")zentri: committing anyway; talk to the holder before you push.The pre-commit hook never blocks the commit, and git commit --no-verify skips it. When the coordinator does not answer within its 5-second budget, the hook prints zentri: the coordinator did not answer within 5s; committing without checking staged files. The same hook sends the snapshot that live overlap detection reads.
In the merge check
Section titled “In the merge check”The merge check, the GitHub check run zentri/merge-check, is the gate. It applies two claim rules to the files a pull request changes:
| Rule | Fails when | Branches checked |
|---|---|---|
unclaimed |
The session has no claim row, live, released, or expired, on a changed path. | zentri/ session branches |
held |
Another session holds a live claim on a changed path. | Every branch |
A branch outside zentri/ is checked for held only. A coordinator error fails the check. See the GitHub check.
Use it
Section titled “Use it”With a kit for Claude Code, Codex, or OpenCode, you do not claim files by hand. The hooks claim each file before an edit. An agent with no hooks calls zentri_claim_file before it edits.
To claim a file over HTTP with your session’s token, run these commands. $API is the coordinator’s URL, and the token file holds the session token (zt_s_...).
S=$(zt status --json | jq -r '.sessions[0].local.session_id')F=$(zt status --json | jq -r '.sessions[0].local.token_file')curl -s -H @<(printf 'Authorization: Bearer %s\n' "$(cat "$F")") -d '{"paths":["cmd/main.go"]}' $API/v1/sessions/$S/claims | jqTo release it, post to the release endpoint. The body takes either paths or "all": true, never both. The response is {"released": [...]}.
curl -s -H @<(printf 'Authorization: Bearer %s\n' "$(cat "$F")") -d '{"paths":["cmd/main.go"]}' $API/v1/sessions/$S/claims/release | jqTo free every file of a stuck session, an admin sends the same request with a user token. zt has no release command.
curl -s -H 'Authorization: Bearer zt_u_...' -d '{"all":true}' $API/v1/sessions/$S/claims/release | jqTo let edits go ahead during an outage, a lead or an admin sets edits_fail_open on the project. $P is the project ID.
curl -s -X PATCH -H 'Authorization: Bearer zt_u_...' -d '{"edits_fail_open":true}' $API/v1/projects/$P | jqTo list claims, call GET /v1/sessions/{session_id}/claims for one session or GET /v1/projects/{project_id}/claims for the project. The HTTP API reference lists every endpoint. The MCP tools reference lists zentri_claim_file and zentri_release_file.
Limitations
Section titled “Limitations”- Codex lets an edit through when the hook binary is missing or crashes. Claude Code and OpenCode refuse the edit.
- A generic MCP agent has no hooks, so claims are advisory there. Nothing stops a write the agent did not claim. The git pre-commit hook still warns.
- With the
local-devlauncher, the agent runs as your user. It can remove its hooks or edit its state file. Theopenshelllauncher puts the kit in root-owned files that the agent cannot change. See sandboxing. - The pre-commit hook only warns, and
--no-verifyskips it. The merge check is the gate. zthas no command to release claims. Use the HTTP endpoint orzentri_release_file.- A merge check verdict is a snapshot. A pull request that passed stays green after another session claims one of its files, until the next push or a re-run.
- The only claim mode is
write. Zentri has no shared or read claims.
Related pages
Section titled “Related pages”- Live overlap detection covers plans, snapshots, symbol overlaps, and the notice digest.
- The three catches places claims next to the other two catches.
- Sessions and forks explains sessions and their states.
- Sandboxing explains how the
openshelllauncher keeps the hooks in place. - Claude Code, Codex, OpenCode, and generic MCP describe each kit.
- The GitHub check describes the merge check.
- Two sessions runs two sessions on one project.
- The MCP tools reference and the CLI reference list tools and commands.