Skip to main content
Version: Next · development

Read-only CLI

The read-only golf CLI lets people, scripts and agents inspect the same repositories, native commit diffs, pull requests, native reviews, organization memberships, provider-visible teams, own-account activity and recorded repository-creation outcomes as the browser. This page covers building it, supplying credentials, every command and its JSON output.

The CLI does not execute coding agents, modify Git, create issues or deploy projects. Its Go client is generated from the same Protobuf/Connect contract as the browser. Authentication accepts a source-session-bound Golf API credential or scoped Forgejo token; managed OAuth/device login remains planned.

Provider and source authority

This portable contract describes its linked source snapshot. For current deployment instructions, use current installation, authentication and native Cloudflare guides. Historical receipts do not verify later builds.

This guide describes the current alpha, including owner-issued read-only API credentials. The authoritative product implementation ledger records exact qualified revisions and remaining scope. This is a development contract, not a stable release.

Build​

From the product checkout, with the Go version specified by go.mod:

make cli
./bin/golf --help

The CLI is bin/golf; the server produced by make build is bin/golf-server. The Compose image continues to run the server normally.

Command overview​

Command groupCommandsSection
repolist, view, branches, commits, contents, creationRepository and issue commands, Inspect repository creation
commitdiffCommit diff
issuelist, view, comments, operationRepository and issue commands, Issue discussion reads
prlist, view, reviewsPull-request commands
orglist, view, teamsOrganization and team commands
teamview, members, reposOrganization and team commands
auditlistAccount activity commands
mcp(none)Local MCP mode

Global flags precede repo, commit, issue, pr, org, team or audit; command flags follow all positional arguments.

Global flagPurpose
--urlSelect the Golf origin
--token-stdinRead one Forgejo token from stdin
--api-token-stdinRead one Golf API credential from stdin

Supply credentials​

The CLI accepts one of two credential sources. API and Forgejo token sources cannot be mixed.

SourceHow to supply itSession behavior
Golf API credentialGOLF_API_TOKEN, or pipe the secret to ./bin/golf --api-token-stdin repo listDelegates its existing source session, makes no login/logout calls and saves no cookies. Ending the source session invalidates it.
Forgejo tokenGOLF_FORGE_TOKEN from your secret manager, or pipe one token with the global --token-stdin flagEach invocation signs into Golf, performs its read, and deletes its temporary session.
# A secret-manager command supplies stdin; do not put a token literal in history.
./bin/golf --token-stdin repo list

Without a pipe, that command reads stdin until EOF. The CLI never saves the token or cookies and has no command-line token flag.

In Forgejo PAT mode, cleanup also runs after an operation error or normal cancellation. A forcibly terminated process can leave the session until server expiry. A cleanup failure returns an error rather than a successful command result.

Choose the Golf origin​

The default origin is http://localhost:8080. Override it with GOLF_URL or --url https://golf.example.com before the command. HTTP is permitted only for loopback origins. Remote installations require HTTPS, and redirects are rejected.

Token scopes​

ReadsRequired Forgejo token scopes
Code, commit diffs, pull requests and native reviewsread:user, read:repository
IssuesAdd read:issue
Organizations and teamsread:user, read:organization; opening repository source separately requires read:repository
Account activity and creation-record inspectionread:user only; returning current repository metadata additionally requires repository scope and native access

User access remains the upper bound regardless of token scopes.

Repository and issue commands​

These examples assume GOLF_FORGE_TOKEN is already available:

./bin/golf repo list --limit 20
./bin/golf repo view owner/repository
./bin/golf repo branches owner/repository --page 1
./bin/golf repo commits owner/repository --ref feature/example
./bin/golf repo contents owner/repository --ref COMMIT_ID --path README.md
./bin/golf issue list owner/repository --state closed
./bin/golf issue view owner/repository 1

Inspect repository creation​

Read one durable creation intent owned by your account:

./bin/golf --token-stdin repo creation 12345678-1234-4234-8234-123456789abc

Replace the example with the returned canonical lowercase UUID v4. This command accepts no repository name or pagination flags and calls only GetRepositoryCreation. It cannot create, retry a native write or resolve an unknown outcome. Its normal ephemeral login/read/logout lifecycle requires read:user; repository metadata remains subject to repository scope and current native access.

The response contains data.creation and optional data.repository. Preserve operation/native IDs as strings. data.creation.state is one of:

  • REPOSITORY_CREATION_STATE_OUTCOME_UNKNOWN
  • REPOSITORY_CREATION_STATE_SUCCEEDED
  • REPOSITORY_CREATION_STATE_REJECTED
Exit 0 does not mean the repository was created

A valid lookup returns exit 0 for any recorded state. A historical success can omit data.repository after deletion, rename, access loss or replacement with another native ID.

Missing/foreign keys produce the same not_found error and no record. Invalid UUID syntax exits 2 before the request. Authentication, lookup and session-cleanup failures exit 1; the CLI logs out before emitting a successful result. Different keys or accounts must not be treated as interchangeable retry authority.

Commit diff​

Select one exact commit with the same repository-read token:

./bin/golf commit diff owner/repository FULL_LOWERCASE_COMMIT_SHA

Replace the placeholder with a full lowercase 40- or 64-character hexadecimal ID from history. Branch names, abbreviated IDs, uppercase IDs and revision expressions are not accepted. This command has no page/base/path flags and does not resolve the current branch for you.

The golf.cli.v1 result contains data.commit, data.parentCommitIds, data.baseCommitId, data.base, data.rawDiff and numeric data.byteSize. The raw text is JSON-escaped, not a patch-file stdout mode; CLI serialization includes default empty strings, zero sizes and empty parent arrays. Root commits have no base, and merge commits compare only with their first parent. Full parent identities are preserved.

The 512 KiB UTF-8 bound rejects oversize and unsafe-control content visibly rather than returning a local truncation. Native binary notices and root commit metadata, including author email, remain as supplied. An empty result can be valid. The diff read contract explains why this is provider output, not independently validated patch completeness or merge eligibility.

PAT mode uses the normal ephemeral login/read/logout lifecycle; API mode delegates its issuing session. --url and --token-stdin precede commit; credentials are not stored. No issue scope or new browser OAuth grant is required.

Pull-request commands​

These read-only commands require read:user and read:repository; no additional read:issue scope is needed:

./bin/golf pr list owner/repository --state open --page 1 --limit 20
./bin/golf pr view owner/repository 12
./bin/golf pr reviews owner/repository 12 --page 1 --limit 20
CommandReturnsNotes
pr listdata.pullRequestsAccepts open (default), closed or all states; one explicit page
pr viewdata.pullRequestNo pagination flags
pr reviewsdata.reviewsOne explicit page

Numbers must be canonical positive decimal integers through 2147483647.

Continue using data.page.nextPage even after an empty review page: native pending-review visibility can be filtered after pagination. Returned base/head refs, retained snapshots and native review flags do not establish source freshness, eligible approval or merge readiness. These commands neither submit reviews nor merge. Each uses the selected credential mode described above.

Organization and team commands​

The six commands use the same membership checks as the browser. Replace acme with an organization name returned by org list, and 123 with a team ID returned by org teams:

./bin/golf org list --page 1 --limit 20
./bin/golf org view acme
./bin/golf org teams acme --page 1 --limit 20
./bin/golf team view acme 123
./bin/golf team members acme 123 --page 1 --limit 20
./bin/golf team repos acme 123 --page 1 --limit 20
CommandReturnsPagination
org listdata.organizationsOne page
org viewdata.organizationNone
org teamsdata.teamsOne page
team viewdata.teamNone
team membersdata.membersOne page
team reposdata.repositoriesOne page

Team IDs remain exact decimal strings, including IDs beyond JavaScript's safe integer range. Pass the returned ID unchanged; signs, leading zeroes, zero and values beyond 9223372036854775807 are rejected. An ID from a different organization does not authorize access through the selected one.

The returned visibility, permission, unitPermissions and includesAllRepositories fields describe native Forgejo settings. They do not calculate an effective Golf role or enable membership changes. A listed repository still needs its own code authorization before repo contents can read source.

Continue an explicit page​

Repository, issue, PR, organization and team collection commands return one page, not an automatic crawl. Pass a nonzero data.page.nextPage as --page to continue, keeping the same --limit; zero or omission means the end.

FlagRangeDefault
--page1–10,0001
--limit1–10020

For example, if the first team-repository response reports data.page.nextPage: 2, continue with:

./bin/golf team repos acme 123 --page 2 --limit 20
Follow nextPage, not array length

An empty data.repositories array can still have a nonzero next page because the provider filters inaccessible assignments after pagination. Provider denials return an error rather than a successful empty collection.

PAT page invocations start and close their own temporary sessions; API mode delegates its source session. Neither reuses a saved CLI cookie.

Account activity commands​

Read your recorded Golf session events with a token scoped to read:user:

./bin/golf audit list --limit 20
./bin/golf audit list --limit 20 --before-id BEFORE_ID --snapshot-id SNAPSHOT_ID

audit list returns data.events, data.nextBeforeId and data.snapshotId. It accepts no --page; omitted limit defaults to 20 and explicit limits are 1–100.

To page through activity:

  1. Run audit list without cursors and keep the returned data.snapshotId.
  2. Pass each data.nextBeforeId as --before-id, with that same first snapshot as --snapshot-id. Replace the cursor placeholders with exact returned strings.
  3. Stop when the next cursor is empty.

To refresh, start again without either cursor.

Cursors are canonical positive signed-int64 strings. A before cursor requires a snapshot, cannot exceed it and must reference an event in the caller's account. Future, missing and foreign cursor IDs are rejected. Do not round IDs through JavaScript numbers or derive a cursor from a timestamp.

Every PAT invocation creates and logs out its own ephemeral session, adding sign-in/sign-out records. Reusing the captured snapshot keeps those later CLI events outside continuation; repeatedly taking a new snapshot does not enumerate one stable history. Normal cleanup leaves no saved session/credential, but abrupt termination remains subject to server expiry. Browser OAuth is separate.

Events include enum action names such as AUDIT_ACTION_SIGN_IN, exact non-credential session handles, times, operation ID and decimal-string revokedCount. Sign-in alone includes optional expiresAt. The activity guide explains coverage: automatic expiry/refresh, failed attempts and provider writes are not recorded; no old login history is invented. This command is a bounded read, not a dedicated retention/export or organization-audit workflow.

Issue discussion reads​

./bin/golf issue comments OWNER/REPO 1 --page 1 --limit 20
./bin/golf issue operation UUID

Comments resolve current repository/issue IDs in the same authenticated call, then return one filtered native repository-wide page. Empty pages can advance; follow data.page.nextPage. Own-operation inspection never posts or adopts an object. Provisional receipt IDs remain evidence of an unknown outcome, not success. See issues and discussions. There are no CLI write commands for these operations.

Local MCP mode​

The same binary can serve 21 authorized read tools over local stdio:

# The owner supplies GOLF_FORGE_TOKEN through the process environment.
./bin/golf mcp

Your MCP client owns stdin/stdout; both token-stdin flags are rejected in this mode. The process captures one configured token and Golf origin at startup, and tool arguments cannot override them. PAT calls use fresh login/read/logout and add session activity; Golf API credentials delegate their source session without login/logout. Both modes emit golf.mcp.v1 tool output. Ordinary commands retain golf.cli.v1 and their existing secret-input behavior.

This local server is separate from remote MCP. On a Cloudflare-native installation, coding agents connect to the remote /mcp endpoint with a scoped API token; Claude Code was verified against it on the hosted demo. See Connect a coding agent. ACP remains unqualified.

Output and exit status​

Success writes a JSON envelope to stdout:

{"schema_version":"golf.cli.v1","data":{"repositories":[],"page":{"nextPage":0}}}

The data value is the corresponding Connect API response serialized as Protobuf JSON. The CLI emits default scalar values and empty arrays for predictable scripting; absent optional fields and absent nested messages remain absent. API JSON received directly may omit more defaults.

Use camelCase fields such as fullName, defaultBranch, commitId, createdAt, updatedAt and htmlUrl. IDs and uint64 byte sizes remain decimal strings, without rounding through JavaScript numbers. States/kinds are schema enum names, such as ISSUE_STATE_OPEN and SOURCE_ENTRY_TYPE_FILE.

Source results include data.commitId; reuse it as --ref when inspecting related files so moving branches cannot mix snapshots. File metadata is nested under data.file.entry, text under data.file.content, and exclusions under data.file.previewReason. Empty text has a present content: ""; a metadata-only preview has no content field. File content stays JSON-escaped. Errors go to stderr without upstream response bodies or credentials.

Exit codeMeaning
0Successful read or help; a creation-record read may describe rejection or uncertainty
1Authentication, operation, connection or session-cleanup failure
2Invalid command, arguments, origin or credential input

golf.cli.v1 identifies the generated-contract envelope in this development build; it does not announce a stable product release. Scripts written for the earlier bootstrap response format must update their fields and pagination.

Roadmap​

CLI write commands, ACP and managed credentials remain roadmap work; local stdio MCP reads are available. Remote MCP with scoped API tokens is available on Cloudflare-native installations, outside the CLI; see Connect a coding agent. Browser OAuth is available for the web UI when configured, but the CLI accepts a delegated Golf API credential or personal-token bootstrap. It does not save provider credentials or reuse browser cookies; managed CLI/device login remains future work.