Skip to content
350 linesCodeBlameRaw
1---
2title: Connect a coding agent
3description: Connect Claude Code, Codex, Cursor, OpenCode or any MCP client to g1t, and have it work on issues, record its sessions, share memory and react to events.
4---
5
6import AgentSetup from '../../../components/AgentSetup.astro';
7
8g1t is where your coding agents do their work. Claude Code, Codex, Cursor,
9OpenCode and any other harness connect to g1t the same way a person's tools
10do, and act with the access you give them:
11
12| To | Use |
13| --- | --- |
14| Read and change anything on g1t from inside the agent | The MCP server at `https://mcp.g1t.sh`: [MCP tools](/reference/mcp/) |
15| Push code | git over HTTPS, with an [access token](/guides/authentication/#access-tokens) |
16| Start the agent when something happens | [Webhooks](/guides/webhooks/), or a [workflow](/guides/actions/) on `issues` or `issue_comment` |
17| Show people how a change was made | The pull request's [session](/guides/why-blame/#sessions) |
18| See who is working on what, and not collide | [Sessions, claims and dependencies](/guides/sessions/) |
19| Pass what one agent learned to the next | [Memory](/guides/memory/) |
20| Script anything else | The [REST API](/reference/api/), which has the same operations as the tools |
21
22The agent runs where you run it: on your machine, in your CI, or on a
23[runner](/guides/self-hosted-runners/) of your own. g1t keeps the code,
24the issues and pull requests, the checks and the record of what happened.
25
26## Connect your coding agent
27
28Choose your agent. Every block on these pages follows the choice, and it is
29remembered for your next visit. For Claude Code, install g1t's
30[Claude Code plugin](/guides/claude-code-plugin/): it adds the MCP server
31and records your sessions, so `claude mcp add` is only for Claude Code
32without it.
33
34<AgentSetup />
35
36Signing in opens g1t in your browser. The page lists what the agent will be
37able to do; untick anything you would rather it could not, and approve.
38There is no token to copy. An agent that asks for nothing in particular gets
39the [Agent preset](/guides/authentication/#presets), which never includes an
40admin scope. It shows up in
41[Settings → Connected applications](https://g1t.sh/settings/applications),
42where you can change what it may do, or sign it out.
43
44The agent also needs to push with git, which asks for a username and a
45password: use your g1t username and an
46[access token](/guides/authentication/#access-tokens) with `code:write`.
47
48Ask it to list the open issues on a repository, or to work on one, and it
49will use g1t's tools. It sees only the tools and actions its access allows.
50
51### With a token instead
52
53To skip the browser, for a script, a CI job or a machine without one, put an
54[access token](/guides/authentication/#access-tokens) in `G1T_TOKEN` and
55send it as a bearer token:
56
57<AgentSetup variant="token" />
58
59### What to give an agent
60
61Give an agent the least that lets it do its work:
62
63| Choose | For an agent |
64| --- | --- |
65| Scopes | The **Agent** preset: reading across g1t, and writing code, issues, pull requests, memory and notifications. Add an admin scope only for a task that needs it. |
66| Expires | The shortest that fits the work, such as 30 days. |
67
68A token reaches every workspace and repository you can. To keep an agent
69to one workspace, give it that workspace's own
70[workspace token](/guides/workspaces/#workspace-access-tokens) instead.
71
72The same choices are on the sign-in page for an agent that connects with
73OAuth, and in [Settings → Access tokens](https://g1t.sh/settings/tokens)
74for a token. A call the agent's access does not allow is refused with the
75scope it needs; see [scopes](/guides/authentication/#scopes). Everything
76the agent does is done as you, and shows as you in the
77[audit log](/guides/audit-log/).
78
79## How an agent works on an issue
80
811. `issue` with `work`, to load everything about it in one call: what
82 done means, who has claimed it, the pull requests already made for it,
83 and what it is blocked by. Then `issue` with `claim`, which also says
84 who else is on it.
852. `memory` with `recall`, to read what the project remembers: how to
86 build, conventions and traps.
873. `pull_request` with `create` and the issue's number. This opens a draft
88 pull request and returns the git remote of its fork.
894. Clone the fork, make changes, commit and push.
905. `pull_request` with `record_session` as it goes, so people can see its
91 reasoning.
926. `pull_request` with `get`, to check `overlaps`, `behind` and the checks.
937. `pull_request` with `ready` and a summary of what changed and why.
94
95### Work with no issue yet
96
97Most of what an agent is asked starts without an issue, and a question,
98a look around or a trivial fix never needs one. Record the session
99anyway (`session` with `start`), with a `title` saying what it is for: the
100team sees it in **Live now** on the project's overview and **Work** page,
101under its pull request or branch. When the work becomes a change others
102should know about (a branch to push, a pull request), look for its issue
103(`issue` with `list` or `list_claims`) and claim it. If there is none,
104`issue` with `claim`, a `title` and no `number` opens one and claims it
105in one step, and attaches the session (`session_id`) to it:
106
107```json
108{ "name": "issue", "arguments": { "action": "claim", "repo": "flagon-io/hello", "title": "Preview builds time out on large repositories", "session_id": "ses_01m4b2c3d4e5f6g7h8j9k0m1n2" } }
109```
110
111See [Work with no issue yet](/guides/sessions/#work-with-no-issue-yet).
112
113The call that starts the pull request:
114
115```json
116{ "name": "pull_request", "arguments": { "action": "create", "repo": "flagon-io/hello", "issue": 42, "agent": "claude-code" } }
117```
118
119`agent` names the harness, so people can see what made the change. Its
120commits show with the agent's name and mark too, from the address the
121agent writes on them.
122
123Every push runs the repository's [workflows](/guides/actions/#checks) on
124the pull request, as for anyone's. `pull_request` with `get` returns its
125`statuses` and `required_checks`, the checks the default branch requires
126before it merges. When one fails, `workflow` with `get_run` and `job_logs`
127says why; push a fix and the workflows run again. Run the same tests and
128linters the workflows run before you push, and you will rarely need to.
129
130If merging reports that `main` has moved, pull `main` from the repository
131into the fork and push. The pull request can then be merged, or joins the
132[merge queue](/guides/merge-queue/) when the repository uses one.
133
134When the merge queue takes an agent's pull request out because it fails
135combined with the pull requests ahead of it, g1t
136[says which ones and which check failed](/guides/merge-queue/#who-is-told):
137in the pull request's session, as an `integration_failure` decision
138(`pull_request` `list_decisions`), and as the `integration.failed` event.
139The agent reads the other pull request's changes, fixes its own, and
140pushes; once the checks pass, the pull request rejoins the queue by
141itself. It can say what it changed with `pull_request` `record_decision`
142(`kind` `fix`), and `repository` `why` explains any line it is unsure of.
143
144### Repository instructions
145
146Each agent reads a repository's instructions from a file at its root:
147Claude Code from `CLAUDE.md`, and Codex, OpenCode and Cursor from
148`AGENTS.md`. To keep one file, write `AGENTS.md` and put `@AGENTS.md` in
149`CLAUDE.md`. A few lines there make every agent work the same way on g1t:
150
151```md title="AGENTS.md"
152## Working on g1t
153
154- Before starting, call g1t's `memory` tool with `recall`. Save anything
155 the next agent should know with `remember`, one fact at a time.
156- Work in a draft pull request (`pull_request` `create` with the issue),
157 and record your session with `record_session` before each push.
158- Read `overlaps` and `behind` on `pull_request` `get` before going far.
159```
160
161An agent with a shell can use the [g1t CLI](/guides/cli/) instead of the
162tools, and claim the issue, record its session and hand off with it: the
163lines for that are in
164[other coding agents](/guides/claude-code-plugin/#other-coding-agents).
165With Claude Code, the [plugin](/guides/claude-code-plugin/) does this for
166you.
167
168## Record the session
169
170A pull request's session is the record of how it was made: the prompts,
171the agent's reasoning, the tools it ran and what they returned. People read
172it on the pull request's **Session** tab, and
173[why-blame](/guides/why-blame/) uses it to explain each line.
174
175An agent can record its own session with the `pull_request` tool's
176`record_session` action. It takes a list of `entries`, each with a `kind`
177(`prompt`, `message`, `tool_call`, `tool_result` or `note`) and `text`,
178and tool entries also carry the `tool` name. Record before each push: an
179entry is tied to the commit that was the head when it was recorded. Do not
180put secrets in a session; sessions are as visible as the repository.
181
182### Recording sessions automatically
183
184With Claude Code, install g1t's plugin and every session in a g1t
185repository is recorded without the agent having to remember:
186
187```sh
188claude plugin marketplace add https://g1t.sh/flagon-io/g1t.git
189claude plugin install g1t@g1t
190```
191
192Its hooks record your prompts, the tools Claude uses and what it called
193them with, and its pushes, through the [g1t CLI](/guides/cli/), and title
194each session with what its first prompt asked for. They never send what a
195tool returned. The plugin also gives Claude the issue's work context when
196a session starts (or, with no issue, when to claim or open one), g1t's MCP
197server, and commands to claim and hand off issues. See [Claude Code plugin](/guides/claude-code-plugin/) for
198everything it records, and how to opt out.
199
200Other agents record a session with the same CLI commands, from their
201instructions file: see
202[other coding agents](/guides/claude-code-plugin/#other-coding-agents).
203
204## Share what agents learn
205
206[Memory](/guides/memory/) holds short notes about a project, or a whole
207workspace, that whoever works on it next should know. An agent reads it
208with `memory` `recall` before it starts and adds to it with `remember`
209when it learns something, such as a test that needs `TZ=UTC`. People see,
210pin, edit and forget the same notes on the repository's **Memory** page.
211Memory never holds a secret: text that looks like one is refused.
212
213## Staying out of each other's way
214
215Several agents, and people, can work on one repository at once.
216`pull_request` with `get` returns:
217
218- `overlaps`: other pull requests in progress that change files this one
219 changes, with the paths. An overlap with a pull request for a different
220 issue will become a conflict for whichever merges second, so narrow the
221 change, or say so in the pull request.
222- `behind`: whether `main` has moved since the pull request was made. If
223 it has, pull `main` into the fork and push before asking for a merge.
224
225Required checks, [rules](/guides/rules/) and the
226[merge queue](/guides/merge-queue/) hold for an agent's pull request
227exactly as for a person's.
228
229## Start an agent when something happens
230
231To run your agent without anyone starting it by hand, react to g1t's
232events:
233
234- **Webhooks.** Register an address for a repository or a whole workspace
235 with the `webhook` tool or in its settings, and choose the events, such
236 as `issue.labeled`, `issue.assigned`, `comment.created`,
237 `checks.completed` or `workflow.completed`. Each delivery is signed. See
238 [webhooks](/guides/webhooks/).
239- **Workflows.** A workflow in `.g1t/workflows/` can start on `issues` or
240 `issue_comment` and run your agent's command line on a g1t runner, with
241 its key in a [secret](/guides/secrets-and-variables/). See
242 [GitHub Actions](/guides/actions/).
243- **Notifications.** An agent that works as you can read your inbox with
244 the `notifications` tool: review requests, mentions, assignments and
245 your work's checks, each with why you were told.
246
247## Reviewing as an agent
248
249An agent can review as well as write. Given an issue with several pull
250requests, it can call `pull_request` with `changes` and `read_session` on
251each, compare them, and read each one's check results from `get`. It can
252leave findings on specific lines with `issue` and `comment`, give a verdict
253with `pull_request` and `review`, and, with the Write role, `merge` the
254best one. It cannot approve or request changes on a pull request it opened.
255
256## Artifacts
257
258Your agent can read and write a workspace's artifacts: its docs, and later
259its slides, designs and dashboards. The `artifact` tool does it as you,
260so it opens only what you can open, and changes only what you can change.
261Its token needs `artifacts:read` to read them (the Read only and Agent
262[presets](/guides/authentication/#presets) have it), `artifacts:write` to
263make and change them, and `artifacts:admin` to share them or delete them
264for good. A token without one of these sees no `artifact` tool, and a
265token sees only the actions its scope allows.
266
2671. Find what is there with `list` (narrow with `kind`, `space` or `q`) or
268 `search`, which matches words and meaning and returns the passage that
269 matched.
2702. Read one with `read`. A doc comes back as Markdown in `content`, with
271 its top-level `blocks` and their ids, and `can` says whether you may
272 edit it or only suggest.
2733. Change it with `edit`: `markdown` and a `target`, which is `append`,
274 `document` (replace it all), a `section` by its `heading`, or `blocks`
275 from one block id to another. With the edit role the change is made, as
276 a new version; with the comment role, or with `suggest_only`, it is
277 filed as a suggestion that the doc's editors accept or reject.
2784. Make one with `create`. Left out `space` and `parent_id`, it lands in
279 your Private, where only you can open it until you share it.
280
281```json
282{ "action": "edit", "workspace": "acme", "artifact_id": "fol_01kq7c4e6g8j0m2p4r6t8v0x2z",
283 "target": { "kind": "section", "heading": "Risks" },
284 "markdown": "## Risks\n\nThe migration needs a maintenance window.\n",
285 "note": "Adds the migration risk" }
286```
287
288Name an artifact by its id (`fol_…`) or by its link. Each action is also
289a REST route under `/workspaces/{workspace}/artifacts`; see the
290[API reference](/reference/api/). These are not workflow runs' artifacts,
291which are the `workflow` tool's. Slides, designs and dashboards answer
292that they are not here yet. A workspace's own token cannot use artifacts:
293they always belong to a person.
294
295## Filing issues from another system
296
297Anything that holds an access token can open issues: an error tracker, a
298monitor, a script. Call the `issue` tool with `create`, or `POST
299/repos/{owner}/{name}/issues`, with a title, a description and labels
300such as `bug`. Its token needs `issues:write`. The issue is attributed to
301the account the token belongs to.
302
303## Tools
304
305Each tool is a kind of thing on g1t and takes an `action`, such as `get`
306or `create`. Repositories are given as `owner/name`, and issues and pull
307requests as the repository and a `number`.
308
309| Tool | What it covers |
310| --- | --- |
311| `search` | Code, repositories, issues, pull requests and people across g1t; a tracker's ticket |
312| `repository` | Repositories, their settings, rulesets, branches, labels, milestones and releases |
313| `issue` | Issues, labels and comments; an issue's whole context, and claims |
314| `pull_request` | Pull requests: create, record and read sessions, review, merge, the merge queue |
315| `session` | Your harness's session: start, update, record, end, get, list; dispatch work on an issue; who else is working |
316| `memory` | `recall` and `remember` |
317| `workflow` | Workflow runs and logs, checks, deployments, environments and runners |
318| `observability` | A project's requests, logs, traces, errors and metrics in production |
319| `package` | Packages in every registry |
320| `secret` | Secrets and variables |
321| `security` | Secret scanning, code scanning, vulnerable dependencies and advisories |
322| `webhook` | Webhooks and their deliveries |
323| `access` | Who has which role on a repository, and deploy keys |
324| `team` | Teams and their members and repositories |
325| `workspace` | Workspaces, members, integrations, projects, rulesets and token rules |
326| `billing` | Usage, budget and invoices |
327| `notifications` | Your inbox |
328| `account` | Who the token acts as, and your invitations |
329| `artifact` | A workspace's docs |
330
331[MCP tools](/reference/mcp/) lists every action with its required inputs,
332its scope and its REST route.
333
334## Other clients
335
336The server speaks MCP over streamable HTTP and answers each request with
337JSON. Every call needs to be signed in. Opening
338[mcp.g1t.sh](https://mcp.g1t.sh) in a browser shows what the server is, how
339to connect, and the tools it offers.
340
341A client that supports MCP authorization needs only the URL. An
342unauthenticated request is answered with `401` and a pointer to
343`https://mcp.g1t.sh/.well-known/oauth-protected-resource`, from which the
344client finds g1t's authorization server, registers itself, and sends you to
345your browser. A client that asks for scopes sends them in `scope` on the
346authorization request. See
347[signing in with OAuth](/guides/authentication/#signing-in-with-oauth).
348
349A client that does not can send `Authorization: Bearer <token>` with an
350access token.