# Update a session

> Update one of your sessions: attach it to an issue or pull request, or change its branch, head commit or title.

<div class="g1t-endpoint"><span class="g1t-method" data-method="patch">PATCH</span><code>/repos/{owner}/{name}/sessions/{id}</code></div>

Only the fields given change. An empty body is a heartbeat: every call keeps the session active and renews the claims made from it. A session reads as idle after 15 minutes without one and ends (`end_reason` timed_out) after 2 hours; a heartbeat brings a timed-out one back. Attaching a pull request moves the entries recorded so far into that pull request's session. A subagent's `task`, `prompt`, `model` and `result` (what it reported, up to 8,000 characters) can be set too; a subagent that ended takes them and stays ended. Returns the session; one ended with [`end_session`](/reference/api/sessions/end-session/) is refused with `409`.

Send `{}` as a heartbeat. Each call renews the session's claims and brings back one that timed out. Refused with `404` for a session that is not yours, and `409` for one you ended.

- **Authentication:** Required. Send an [access token](/reference/api/#authentication) as `Authorization: Bearer`.
- **MCP tool:** [`session`](/reference/mcp/#session) with `action` `update`, and the same inputs
- **Scope:** An access token needs [`pull_requests:write`](/guides/authentication/#scopes).

## Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `owner` | string | Yes | The workspace that owns the repository. |
| `name` | string | Yes | The repository's name. |
| `id` | string | Yes | The session's id (ses_…), from [`start_session`](/reference/api/sessions/start-session/) or [`list_sessions`](/reference/api/sessions/list-sessions/). |

## Body parameters

Send a JSON object. Names are `snake_case`, as in responses; the `camelCase` spelling is accepted too.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `issue` | integer | No | The issue it works on. |
| `pull` | integer | No | The pull request it works on. |
| `branch` | string | No | The branch it works on. |
| `title` | string | No | What it is doing, in a few words. Up to 200 characters. |
| `head_commit` | string | No | The commit it is at, such as after a push. |
| `result` | string | No | What it reported when it finished: a subagent's final message. Kept up to 8,000 characters. Never a tool's output. |
| `agent_type` | string | No | For a subagent: its kind, as the harness names it (Explore, security-reviewer). |
| `task` | string | No | For a subagent: the task it was given, in a few words. Up to 200 characters. |
| `prompt` | string | No | For a subagent: the prompt its parent gave it. Kept up to 4,000 characters. |
| `model` | string | No | The model it runs on, when known. |

## Example request

```sh
curl -X PATCH https://api.g1t.sh/repos/flagon-io/hello/sessions/id \
  -H "Authorization: Bearer $G1T_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "pull": 14,
    "head_commit": "9f2c4e1a7b3d5f60812a4c6e8b0d2f4a6c8e0b13"
  }'
```

## Example response

A successful request answers `200` with:

```json
{
  "id": "ses_01m4b2c3d4e5f6g7h8j9k0m1n2",
  "repo_id": "rep_01m3m5q6p0e2qaw6mmjahk0qrr",
  "issue": 12,
  "pull": 14,
  "branch": "greet-caller",
  "actor": {
    "id": "usr_01kkntcg1eeb98j62xjm7eh09p",
    "username": "syntaqx"
  },
  "harness": "claude_code",
  "harness_session_id": "5b0c1f9e-3d2a-4e8b-9f61-0c7d2a9e4b13",
  "title": "Make the greeting name the caller",
  "state": "active",
  "head_commit": "9f2c4e1a7b3d5f60812a4c6e8b0d2f4a6c8e0b13",
  "started_at": "2026-10-12T14:02:11.204Z",
  "last_seen_at": "2026-10-12T14:31:40.518Z",
  "ended_at": null,
  "end_reason": null
}
```

## Errors

A failed request answers with one of these statuses and a body like `{"error": {"code": "not_found", "message": "Repository not found."}}`. See [errors](/reference/api/#errors).

| Status | Code | When |
| --- | --- | --- |
| 401 | `unauthenticated` | A token is required, or the one sent is not valid. |
| 403 | `forbidden` | The token is valid but not allowed to do this, such as a member-only change, or a token without the scope it needs. |
| 404 | `not_found` | It does not exist, or you cannot see it. |
| 409 | `conflict` | The request conflicts with the current state. |
| 422 | `invalid` | The input is not valid. `message` says which field and why. |
