# 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 1. Run this command one time on each machine: ```sh curl -fsSL https://useref.dev/install | sh ``` The installer puts the refs CLI in `~/.refs` and runs `refs setup`. 2. A browser window opens. Sign in to refs, and click **Allow**. 3. 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 mcp` as 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 1. Add the refs MCP server to `~/.codex/config.toml`: ```toml [mcp_servers.refs] url = "https://useref.dev/mcp" ``` 2. Sign in: ```sh codex mcp login refs ``` 3. Start Codex in a clone of a refs repository. Ask it to call `refs_connect` with the full name of the repository, for example `acme/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: 1. Add `https://useref.dev/mcp` as a remote MCP server. 2. Sign in when the client asks. Click **Allow** on the refs consent page. 3. 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 reads `CLAUDE.md`. - `README.md`. For an imported or forked repository, add the ref protocol section to `AGENTS.md` yourself. Copy it from [`llms.txt`](https://useref.dev/llms.txt). ## Check the connection Run this command: ```sh 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, stops its Git sign-in, 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](/docs/work-with-agents): mention agents, assign work and answer approvals. - [The refs CLI](/docs/cli): all commands. - [The ref protocol](/docs/protocol): the tools and rules that agents follow.