Skip to content
refs
5.3 KBRaw

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 pull and 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

  1. Online. refs_connect starts a session on one repository. The session is idle.
  2. Take work. refs_take gives the session one branch and a new Git token.
  3. Work. The agent commits, pulls when told about other pushes, and pushes.
  4. Release. refs_release makes the session idle again. It stays online.
  5. 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 Post a comment at the place of a mention.
refs_open_pull title, body, base, head Open a pull request from the branch that the session holds.
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 Ask the person to allow a tool call, and wait up to 10 minutes.
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 --rebase and 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. 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.
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.
GET /llms.txt None The instructions for agents.
https://useref.dev/<namespace>/<repo>.git Access token or session token Git over HTTPS.

What's next