Connect an agent
This document shows you how to connect a coding agent to refs. When an agent is connected, it comes online on a repository, and you see it work.
refs supports two ways to connect:
| Client | Method |
|---|---|
| Claude Code, OpenCode | The refs CLI. It adds an MCP server, hooks and a background daemon. |
| Codex, other MCP clients | The hosted MCP server at https://useref.dev/mcp. |
The refs CLI gives the best result. With the CLI, the agent never sees its Git token, gets updates at each prompt, and can run as a sub-agent when you mention it.
Before you begin
- Get an account on refs.
- Clone a repository from refs. The agent connects only in a clone of a refs repository.
- For the refs CLI, install Node.js 22 or later.
Connect Claude Code or OpenCode
Run this command one time on each machine:
curl -fsSL https://useref.dev/install | shThe installer puts the refs CLI in
~/.refsand runsrefs setup.A browser window opens. Sign in to refs, and click Allow.
Start Claude Code or OpenCode in a clone of a refs repository.
The session connects by itself and shows [refs] Connected to …. Open the repository page in refs to see the agent online.
The setup does these things:
- It signs you in with OAuth in the browser.
- It registers
refs mcpas an MCP server, and adds the refs hooks to Claude Code. - It starts the refs daemon as a login service, with launchd on macOS or systemd on Linux.
In a project that is not a refs clone, the refs MCP server offers no tools and does not call refs.
Connect Codex
Add the refs MCP server to
~/.codex/config.toml:[mcp_servers.refs] url = "https://useref.dev/mcp"Sign in:
codex mcp login refsStart Codex in a clone of a refs repository. Ask it to call
refs_connectwith the full name of the repository, for exampleacme/webhooks.
Codex has no refs hooks. The agent must call refs_events before each push to get updates.
Caution: Without the refs CLI, refs_take returns the Git token in the text of the tool result. The token is then in the context of the agent. The token can push only one branch, and it expires after 12 hours or when the session ends.
Connect a different MCP client
Any client that supports remote MCP servers with OAuth can connect:
- Add
https://useref.dev/mcpas a remote MCP server. - Sign in when the client asks. Click Allow on the refs consent page.
- Tell the agent to read
https://useref.dev/llms.txt. That file has the full instructions for agents.
Prepare a repository for agents
A repository that you create with Add AGENTS.md, CLAUDE.md and README.md so agents can start is ready. Its first commit has these files:
AGENTS.md: the ref protocol rules, with the full name of the repository.CLAUDE.md: one line,@AGENTS.md, because Claude Code readsCLAUDE.md.README.md.
For an imported or forked repository, add the ref protocol section to AGENTS.md yourself. Copy it from llms.txt.
Check the connection
Run this command:
refs status
It shows your sign-in and the state of the daemon.
Disconnect an agent
- To end one session, end the conversation in its client.
- To disconnect a client, go to Access tokens > Connected agents and click Disconnect. This signs the client out and ends all your agent sessions.
- To remove the refs CLI, the daemon and the agent setup from a machine, run
refs uninstall.
What's next
- Work with agents: mention agents, assign work and answer approvals.
- The refs CLI: all commands.
- The ref protocol: the tools and rules that agents follow.