# Comment on a commit

> Comment on a commit, as a whole or, with path and line, on one line of a file the commit changed (a line of the file as the commit left it).

<div class="g1t-endpoint"><span class="g1t-method" data-method="post">POST</span><code>/repos/{owner}/{name}/commits/{sha}/comments</code></div>

Anyone who can read the repository may, unless it has turned commit comments off (allow_commit_comments on [`update_repo_settings`](/reference/api/repositories/update-repo-settings/)). The commit's author and anyone mentioned are notified. Publishes commit_comment.created.

`line` needs `path`, a file the commit changed, and counts lines of that file as the commit left it. A repository with `allow_commit_comments` off answers `403`; a commit it does not have, `404`. See [Commit comments](/guides/pull-requests/#commit-comments).

- **Authentication:** Required. Send an [access token](/reference/api/#authentication) as `Authorization: Bearer`.
- **MCP tool:** [`repository`](/reference/mcp/#repository) with `action` `comment_on_commit`, and the same inputs
- **Scope:** An access token needs [`issues: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. |
| `sha` | string | Yes | The commit's hash, as [`list_commits`](/reference/api/repositories/list-commits/) gives it. |

## Body parameters

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

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `body` | string | Yes | Markdown. |
| `path` | string | No | A file the commit changed, from the repository's root, to comment on one of its lines. |
| `line` | integer | No | With path: the line, as the commit left the file, counted from 1. |

## Example request

```sh
curl -X POST https://api.g1t.sh/repos/flagon-io/hello/commits/9f2c4e1a7b3d5f60812a4c6e8b0d2f4a6c8e0b13/comments \
  -H "Authorization: Bearer $G1T_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "body": "Should an empty name fall back to \"world\"?",
    "path": "src/main.rs",
    "line": 12
  }'
```

## Example response

A successful request answers `200` with:

```json
{
  "id": "ccm_01m4a2r7k3d9f1h5j8n2q6t0w4",
  "repo_id": "rep_01m3m5q6p0e2qaw6mmjahk0qrr",
  "commit": "9f2c4e1a7b3d5f60812a4c6e8b0d2f4a6c8e0b13",
  "path": "src/main.rs",
  "line": 12,
  "author": "ana",
  "body": "Should an empty name fall back to \"world\"?",
  "created_at": "2026-10-01T19:02:11.208Z",
  "updated_at": 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. |
