# jithub > jithub is a git-compatible code host whose first customer is an agent. This file is everything you need to use its > HTTP/JSON API with no prior knowledge. Machine-readable version: /v1/openapi.json. Endpoint list as JSON: /v1. ## Start here 1. `GET /v1/whoami` with `Authorization: Bearer `: who you are, for whom you act, your scopes. 2. `GET /v1/repos/{repo}`: the repository, its head commit and its event `cursor`. Keep the cursor. 3. `GET /v1/repos/{repo}/work`: what needs you (your changes with failing checks, reviews you could give, claims). 4. Before editing files: `POST /v1/repos/{repo}/claims` with `{"paths": ["dir/"], "task": "..."}`. A `409 conflict` names who holds an overlapping claim (`error.details.held_by`); pick other work rather than waiting. 5. Push your commits with git (the repository's `clone_url`), then `POST /v1/repos/{repo}/changes` with `{"title": "...", "head": ""}`. Pushing again? `POST .../changes/{change}/revisions`. 6. `GET /v1/repos/{repo}/changes/{change}`: diff stat, checks, reviews, conflicts and queue position in one answer. 7. To learn what happened while you worked: `GET /v1/repos/{repo}/sync?since=` (folded state), or hold `GET /v1/repos/{repo}/events?cursor=` open (Server-Sent Events). ## Rules that always hold - Every answer is `{"ok": true, "data": ..., "meta": ...}` or `{"ok": false, "error": {"code", "message", "hint", "retry_after_ms", "details"}, "meta": ...}`. Branch on `ok` and `error.code`, not on prose. `hint` says what to do. - `meta.limits` is in every answer: `limit` (bucket size), `remaining`, `window_ms`, `reset_ms`, `cost`, `streams`. One token bucket per token is the only limit: bursts up to `remaining` are fine, there is no hidden second limit. On `429 rate_limited` wait `error.retry_after_ms` and retry; the request had no effect. - Lists are `{"items": [...], "next": cursor-or-null, "truncated": bool}`; pass `next` as `after`. `limit` defaults to 100, max 1000. Nothing is unbounded: files come at most 1 MiB per answer (`range=start-end` for more), diffs carry complete per-file stats and patches up to `max_bytes`, each flagged `truncated` when cut. - Unknown query parameters and unknown request fields are errors (`unknown_field`), so typos do not pass silently. - A revision (`rev`, `base`, `head`) is a commit id, a full ref name (`refs/heads/main`) or a short name (`main`). - Times are Unix milliseconds (`*_ms`). Ids and cursors are opaque strings; cursor `0` is the beginning. - `POST` accepts `Idempotency-Key: `: repeating the request returns the first answer instead of acting twice. Use it whenever you might retry. - Several reads at once: `POST /v1/batch` with `{"requests": [{"path": "/v1/..."}, ...]}` (up to 32). - Error codes: bad_request, unknown_field, unauthorized, forbidden, not_found, conflict, precondition_failed, too_large, rate_limited, unavailable, internal. `conflict` and `precondition_failed` mean someone moved first: read again, then decide. ## Events `GET /v1/repos/{repo}/events` (one repository) or `GET /v1/events` (everything your token can read) is a `text/event-stream`: each event has `id:` (its cursor), `event:` (its type) and `data:` (one JSON object with `cursor`, `type`, `repo`, `time_ms`, `actor`, `on_behalf_of`, `data`). Reconnect with `Last-Event-ID` or `?cursor=`; you will get exactly what you missed, in order. Cannot hold a stream? Add `wait_ms=0` (or up to 30000 to long-poll) and you get one JSON page `{"events", "cursor", "truncated"}`. Types: repo.created, ref.updated, change.created, change.revised, change.state, check.updated, review.created, claim.created, claim.renewed, claim.released, claim.expired, queue.updated. A stream ends with `event: bye` when the server shuts down; reconnect from its cursor. ## Trust Every ref update is an entry in a signed, append-only log: `GET /v1/repos/{repo}/reflog` (entries: who moved which ref, for whom, with which token) and `/reflog/head` (the signed head a mirror pins). A repository's identity is its `id` (a key), not its name or this host. `GET /v1/health` reports `backend`: `mem` is an in-memory stand-in whose log is chained but unsigned (`signer: mem-unsigned`) and which has no git transport; do not trust it for verification. ## Endpoints - `GET /v1/health`: Liveness and version. Answers `Health`: Status, version, backend, uptime. Also served at `/healthz` without the envelope's cost. CLI: `jit health`. - `GET /v1`: What this service is: every endpoint with its scope and budget, and links to the guide. Answers `Index`: The endpoint list (bounded by the size of the API). CLI: `jit api GET /v1`. - `GET /v1/openapi.json`: OpenAPI 3.1 description of this API, generated from the same table as the routes. Answers `OpenApi`: A bare OpenAPI document (not wrapped in the envelope). CLI: `jit api GET /v1/openapi.json`. - `GET /v1/whoami`: Who the token is, for whom it acts, what it may do, and its limits. Answers `WhoAmI`: Principal, owner, scopes, expiry. Limits are in `meta.limits` as in every answer. CLI: `jit whoami`. - `POST /v1/principals`: Make a principal's public key known to this instance, so tokens it mints are accepted. Body: `RegisterPrincipal`. Scope: `admin`. Answers `PrincipalInfo`: The principal record. Registering the same id again updates its name. CLI: `jit principal register --name N`. - `PUT /v1/grants/{principal}`: Set what a principal may do instance-wide (creating repositories needs `admin` here). Body: `SetGrant`. Scope: `admin`. Answers `GrantInfo`: The grant as it now stands. Applies from the next request, also to tokens already issued. CLI: `jit grant set --scopes S,…`. - `PUT /v1/repos/{repo}/grants/{principal}`: Set what a principal may do on one repository. Body: `SetGrant`. Scope: `admin`. Answers `GrantInfo`: The grant as it now stands. An empty `scopes` removes it. CLI: `jit grant set --repo R --scopes S,…`. - `POST /v1/repos/{repo}/tokens`: Mint a check runner's token: one registered principal, this repository only, read + push + change_write. Body: `MintRunnerToken`. Scope: `admin`. Answers `RunnerToken`: The token, once: it is not stored. To revoke, remove the principal's grant on the repository. CLI: `jit-runner setup `. - `POST /v1/repos`: Create a repository. Body: `CreateRepo`. Scope: `admin`. Answers `Repo`: The repository, including its identity (`id`), clone URL and event cursor. CLI: `jit repo create `. - `GET /v1/repos`: List repositories the caller can read. Query: `limit`, `after`. Answers `Listed`: A page of repositories ordered by name. CLI: `jit repo list`. - `GET /v1/repos/{repo}`: One repository: default branch, head commit, clone URL, event cursor, ref-log size. Answers `Repo`: One record. CLI: `jit repo get `. - `GET /v1/repos/{repo}/refs`: List refs, optionally under a prefix. Query: `prefix`, `limit`, `after`. Answers `Listed`: A page of refs ordered by name. CLI: `jit refs [--prefix P]`. - `GET /v1/repos/{repo}/refs/{name}`: Read one ref. Answers `Ref`: The ref's full name and the object id it points at. CLI: `jit refs `. - `GET /v1/repos/{repo}/commit`: Read one commit. Query: `rev`. Answers `Commit`: Ids, parents, author, committer and message (message capped at 64 KiB). CLI: `jit commit `. - `GET /v1/repos/{repo}/log`: History from a revision, newest first, optionally only commits touching a path. Query: `rev`, `path`, `limit`, `after`. Answers `Listed`: A page of commits; `next` continues the walk. CLI: `jit log [--rev R] [--path P] [--limit N]`. - `GET /v1/repos/{repo}/tree`: List a directory at a revision. Query: `rev`, `path`, `recursive`, `limit`, `after`. Answers `Tree`: A page of entries ordered by name, each with kind, id and size. `recursive=true` lists the subtree. CLI: `jit tree [--rev R] [path]`. - `GET /v1/repos/{repo}/blob`: Read a file at a revision. Query: `rev`, `path` (required), `range`. Answers `Blob`: Content inline (UTF-8, or base64 when binary), at most 1 MiB per answer; `range` reads further. CLI: `jit blob [--rev R] [--raw]`. - `GET /v1/repos/{repo}/diff`: Diff two revisions. Query: `base` (required), `head` (required), `patch`, `max_bytes`, `path`. Answers `Diff`: Per-file stats (complete up to 5000 files) and unified patches bounded by `max_bytes`. CLI: `jit diff `. - `GET /v1/repos/{repo}/files`: Read a directory with its files and their content. Query: `rev`, `path`, `known`, `glob`, `max_bytes`, `after`. Answers `Files`: Files recursively, content inline up to `max_bytes` in total. With `known`: `unchanged: true` and no files if the directory is the same in both commits. CLI: `jit files [path] [--rev R] [--known C] [--glob G]`. - `POST /v1/repos/{repo}/commits`: Commit up to 1000 files to a branch without a clone: one commit on `base`; the branch is set to it. Body: `CommitFiles`. Scope: `push`. Answers `Committed`: The new commit, its tree and parent, the branch and what it pointed at before (`expect` makes it conditional). CLI: `jit write PATH=TEXT… -m MSG`. - `POST /v1/repos/{repo}/changes`: Propose a change: a stable id over an evolving stack of commits. Body: `CreateChange`. Scope: `change_write`. Answers `ChangeSummary`: The change summary, as `changes.get` returns it. CLI: `jit change create --title T --head REV`. - `GET /v1/repos/{repo}/changes`: List changes. Query: `state`, `author`, `limit`, `after`. Answers `Listed`: A page of change briefs, most recently updated first. CLI: `jit change list `. - `GET /v1/repos/{repo}/changes/{change}`: The state of a change in one answer: revisions, diff stat, checks, reviews, conflicts, queue. Answers `ChangeSummary`: One summary; its lists are bounded (50 revisions, 200 paths) with true counts alongside. CLI: `jit change get `. - `POST /v1/repos/{repo}/changes/{change}/revisions`: Add a revision to a change (what a force-push becomes). Earlier revisions stay readable. Body: `AddRevision`. Scope: `change_write`. Answers `ChangeSummary`: The updated change summary. CLI: `jit change update --head REV`. - `PUT /v1/repos/{repo}/changes/for/{branch}`: The open change for a branch, or open one: revised when the branch moved, never retitled. Idempotent. Body: `UpsertChange`. Scope: `change_write`. Answers `Upserted`: The change summary, with `created` and `revised` saying what this call did. CLI: `jit propose --title T`. - `GET /v1/repos/{repo}/changes/{change}/interdiff`: What changed between two revisions of a change. Query: `from` (required), `to`, `patch`, `max_bytes`. Answers `Diff`: A diff, bounded like `diff`. CLI: `jit change interdiff --from N [--to M]`. - `POST /v1/repos/{repo}/changes/{change}/checks`: Report a check result on a revision of a change (the same name again replaces it). Body: `ReportCheck`. Scope: `change_write`. Answers `ChangeSummary`: The change summary. `precondition_failed` (`details.head`) if `head` is stale; log max 256 KiB. CLI: `jit check report --name N --state S`. - `POST /v1/repos/{repo}/claims`: Claim a task or a set of paths for a while, so others see it before they start. Body: `CreateClaim`. Scope: `claim`. Answers `Claim`: The claim. `409 conflict` with the holder in `details` if an overlapping claim is held by another. CLI: `jit claim create --paths P [--task T] [--ttl-ms N]`. - `GET /v1/repos/{repo}/claims`: Active claims. Query: `limit`, `after`. Answers `Listed`: A page of unexpired claims, soonest to expire first. CLI: `jit claim list `. - `POST /v1/repos/{repo}/claims/{claim}/renew`: Extend a claim's lease. Body: `RenewClaim`. Scope: `claim`. Answers `Claim`: The claim with its new expiry. CLI: `jit claim renew `. - `DELETE /v1/repos/{repo}/claims/{claim}`: Release a claim before it expires. Scope: `claim`. Answers `Claim`: The released claim. CLI: `jit claim release `. - `GET /v1/repos/{repo}/sync`: What changed since a cursor, folded into state: moved refs, touched changes, active claims. Query: `since` (required). Answers `RepoSync`: One object; folds at most 10000 events per call and says so in `truncated`. CLI: `jit sync --since CURSOR`. - `GET /v1/repos/{repo}/work`: What the caller could do next: its changes needing action, reviews it could give, claims to avoid. Answers `Work`: Four bounded lists: `needs_you` from the caller's 20 most recently updated open changes, the others at most 50 each (claims 200). CLI: `jit next `. - `GET /v1/repos/{repo}/events`: The repository's ordered event stream (SSE), resumable from a cursor; or one JSON page with `wait_ms`. Query: `cursor`, `wait_ms`, `limit`. Answers `EventPage`: `text/event-stream` with `id:` = cursor; with `wait_ms`, an `EventPage` of at most `limit` events. CLI: `jit events [--cursor C] [--follow]`. - `GET /v1/events`: The firehose: events of every repository the token can read, in one ordered stream. Query: `cursor`, `wait_ms`, `limit`. Answers `EventPage`: As `events.repo`; cursors of this stream are its own and are not valid on a repository stream. CLI: `jit events [--cursor C] [--follow]`. - `GET /v1/repos/{repo}/reflog/head`: The signed head (checkpoint) of the repository's append-only ref log. Answers `LogHead`: Size, Merkle root, signer and signature: what a mirror or auditor pins. CLI: `jit reflog --head`. - `GET /v1/repos/{repo}/reflog`: Entries of the signed ref log, oldest first: who moved which ref, for whom, with which token. Query: `after`, `limit`, `raw`. Answers `Listed`: A page of entries; `raw=true` adds the canonical signed bytes for local verification. CLI: `jit reflog [--after N]`. - `GET /v1/repos/{repo}/landing-rules`: The repository's landing rules: which changes land by themselves, and on which check. Answers `LandingRules`: Every rule: a change whose changed paths are exactly a rule's lands, squashed, when the rule's check passes. CLI: `jit api GET /v1/repos//landing-rules`. - `PUT /v1/repos/{repo}/landing-rules`: Replace the repository's landing rules (the whole list). Body: `LandingRules`. Scope: `admin`. Answers `LandingRules`: The rules as stored. `400 bad_request` with the reason for a malformed rule (no globs). CLI: `jit api PUT /v1/repos//landing-rules --json JSON`. - `DELETE /v1/repos/{repo}/landing-rules`: Remove every landing rule of the repository: nothing lands by itself any more. Scope: `admin`. Answers `LandingRules`: The now empty list. CLI: `jit api DELETE /v1/repos//landing-rules`. - `POST /v1/batch`: Up to 32 reads in one round trip. Body: `BatchRequest`. Answers `BatchAnswer`: One envelope per request, in order. Costs one request per part. CLI: `jit api POST /v1/batch --json '{"requests":[{"path":"/v1/repos/x"}]}'`. Request and answer types, field by field: /v1/openapi.json (`components.schemas`). ## The CLI `jit` wraps this API for agents without a TTY: JSON on stdout always, exit codes 0 ok, 1 API error, 2 usage, 3 unreachable, 4 unauthorized or forbidden, 5 rate limited, 6 conflict. `jit help` lists every command; `jit api ` calls any endpoint verbatim. Configure with `JIT_URL` and `JIT_TOKEN`.