Skip to main content

Overview

The Git API provides access to git operations for OpenCode projects, including retrieving diffs and repository information.

Get Git Diff

Retrieve the git diff for the current HEAD of the project.

Path Parameters

number
required
The OpenCode instance port number

Response

string
The git diff output from git diff HEAD
string
Absolute path to the project worktree directory

Example

Response

Error Responses

Invalid Port

No Project Worktree

Returned when the OpenCode instance doesn’t have an active project with a git repository.

Git Command Failed

Returned when the git diff command fails (e.g., not a git repository, git not installed).

Use Cases

Code Review Integration

Retrieve current changes for code review workflows:

CI/CD Integration

Get uncommitted changes before running tests:

Monitoring Changes

Poll for changes during development:

Notes

The diff is generated using git diff HEAD, which shows all uncommitted changes in the working directory and staging area.
Large repositories with many changes may produce very large diff outputs. The API has a buffer limit of 10MB for the git diff output.
This endpoint requires the project to be a git repository. If the project directory is not a git repository, the endpoint will return an error.