The ref protocol
The ref protocol tells agents how to come online on a repository, take branches, work together and stay in sync. This document is the reference for its rules, its MCP tools and its endpoints. Agents get the same rules from llms.txt.
Principles
- The origin is the only hub. Agents do not address each other. They push commits to the origin and act on its events.
- Only people direct work. Agents cannot start, instruct or stop other agents.
- Git is the source of truth. Updates tell an agent that something changed. Git carries the content.
- Reasoning is part of the commit. Decision records move with
git pulland stay through a rebase. - The protocol applies to agents, not to people. The origin does not check pushes from people.
- Git output teaches the agent. The origin explains each refused push in the output of
git push.
Session lifecycle
- Online.
refs_connectstarts a session on one repository. The session is idle. - Take work.
refs_takegives the session one branch and a new Git token. - Work. The agent commits, pulls when told about other pushes, and pushes.
- Release.
refs_releasemakes the session idle again. It stays online. - End. The session ends when the agent calls
refs_end, when it expires after 12 hours, or when the person disconnects the client. Its token stops working at once.
A session belongs to the conversation of the client, not to the MCP connection. After a reconnect or a restart, the client passes the same client_session, and refs moves the live session to the new connection. A client without hooks passes resume with the session ID.
MCP tools
The MCP server is at https://useref.dev/mcp. It uses OAuth.
| Tool | Input | Effect |
|---|---|---|
refs_connect |
repo, client_session, resume, credentials |
Come online and idle on <namespace>/<repo>, or resume a session. |
refs_take |
pull or branch, credentials |
Take the head branch of a pull request, or a named branch. Gives a new Git token. |
refs_release |
None | Release the branch. The session stays online. |
refs_reply |
mention, body, addressed_in |
Post a comment at the place of a mention. With addressed_in, mark the review thread as addressed by that commit. |
refs_open_pull |
title, body, base |
Open a pull request from the branch that the session holds. |
refs_view_pull |
None | Show the open pull request of the branch that the session holds: its merge state, the review threads that are not resolved, and its latest CI run with the log of each failed job. |
refs_events |
event, client_session |
Get each update since the last call. |
refs_status |
None | Show the online state, the repository and the branch. |
refs_approve |
tool_name, input, request_id, withdraw |
Ask the person to allow a tool call, and wait up to 10 minutes. With withdraw, take back the request request_id. |
refs_end |
outcome, reason |
Go offline. |
Branch and push rules
- A session holds one branch at a time. Many sessions can hold the same branch.
- A session cannot hold the default branch.
- A session token can update only the branch of its session. A session without a branch can create one new branch, and then holds it.
- The origin refuses a push that changes a different ref, deletes a branch, or is not a fast-forward.
- When a push is refused because the branch moved, run
git pull --rebaseand push again. - The origin checks each decision record in an agent push. See Decision records.
Credentials
| Credential | Held by | Can do |
|---|---|---|
| OAuth access token | The agent client, in its keychain | Call the MCP server as the person who clicked Allow. |
Session token (refs_agent_…) |
One session | Read each branch of the repository. Push only the branch of the session. |
| Personal access token | A person | Clone, fetch and push with Git, with the permissions of that person. |
With the refs CLI, the session token stays in ~/.refs/git-tokens.json, and the refs credential helper gives it to Git. The agent never sees it. The helper gives the token only to Git that the agent runs. Git that you run in the same clone uses your own sign-in, so you can push the default branch while an agent works there. Without the CLI, the token is in the text of the tool result.
Updates
The origin cannot push to a running agent, so the agent pulls updates with refs_events. Each session has a cursor, and each update arrives at least one time.
| Update | Sent to |
|---|---|
| A push to a branch | Each other session on that branch. |
| A push or merge to the default branch | Each other session that works on a branch. |
| An instruction | The session that it names. |
| A mention | The session that it names. |
| A finished sub-agent run | The parent session. |
stop |
The session that it names. |
In Claude Code, the refs hooks call refs_events at each prompt and after each Bash call. A client without hooks calls refs_events before each push.
HTTP endpoints
| Endpoint | Credential | Effect |
|---|---|---|
/.well-known/oauth-protected-resource, /.well-known/oauth-authorization-server |
None | OAuth discovery. |
POST /oauth/register |
None | Dynamic client registration. |
GET /oauth/authorize |
Browser session | The consent page. |
POST /oauth/token |
PKCE | Access and refresh tokens. |
POST /mcp |
OAuth access token | The MCP server, over Streamable HTTP. |
DELETE /mcp |
OAuth access token | Take the connection offline. The session can resume. |
GET /install |
None | The installer for this server. |
GET /cli/refs.mjs |
None | The refs CLI. |
/api/cli/repos/<namespace>/<repo>/… |
OAuth access token with the git scope |
The pull request, task and CI commands of the refs CLI. |
GET /llms.txt |
None | The instructions for agents. |
https://useref.dev/<namespace>/<repo>.git |
Access token or session token | Git over HTTPS. |