Documentation
¶
Overview ¶
Package gitremote answers "where does this repository live on the web, and which pull requests did a session open", from the machine alone.
Owner request (2026-10-04): from a session, one click to the repository it works in and to the pull requests it opened. Rule 4 holds: nothing here makes a network call. The repository comes from `git remote get-url` in the session's directory, turned into a web address by string rules; the pull requests come from what Claude Code already recorded in its own tool output. A remote this package cannot read as a web host yields no link rather than a guessed one.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BranchURL ¶
BranchURL is the web page of a branch, or "" when the branch is the default (the repository page already shows it), unknown, or the host's scheme for branch pages is not one this package knows. Hosts are recognised by name, so GitHub Enterprise and self-hosted GitLab are covered when their host says so.
func PushFromToolPost ¶ added in v0.179.1
PushFromToolPost reads the branch a Bash tool's PostToolUse payload pushed: Claude Code records `tool_response.gitOperation.push.branch` when a `git push` succeeds. It is how a session's pull request is found when the session never ran `gh pr` itself (a script opened it). A failed command, or a push without a branch, records nothing.
func WebURL ¶
WebURL turns a git remote into the repository's https address.
Accepted: `git@host:owner/repo.git` (scp-like), `ssh://[user@]host[:port]/owner/repo.git`, `git+ssh://`, `git://`, `http(s)://[user[:pass]@]host[:port]/owner/repo(.git)`. Credentials and an ssh port are dropped (the web is on https's own port); an http(s) port is kept. A local path, `file://`, or anything else that names no host returns false.
Types ¶
type PR ¶
type PR struct {
URL string `json:"url"`
Number int `json:"number"`
// Title is the `--title` the command passed, when it passed one plainly.
Title string `json:"title,omitempty"`
// Action is what this one command did: created, merged, closed, edited,
// commented. Only a recorded "merged" ever makes a PR read as merged.
Action string `json:"action"`
}
PR is one pull request a session opened, or merged, as its own tool output recorded it.
func FromToolPost ¶
FromToolPost reads a pull request out of a Bash tool's PostToolUse payload.
Claude Code records `tool_response.gitOperation.pr` — {number, url, action} — when a `gh pr` command succeeds; that is the primary source and the only one trusted for anything but "created". Without it, a `gh pr create` whose output carries a pull-request URL counts as created. A failed command records nothing.
type Repo ¶
type Repo struct {
// Root is the repository's top level on this machine, or the directory
// itself when git could not say. Shown, with a copy button, when there is
// no web address to link to.
Root string `json:"root"`
// URL is the repository's web address, https, no credentials. Empty when
// there is no remote or it is not a web host (a path, a file:// URL).
URL string `json:"url,omitempty"`
// Branch is the checked-out branch; empty on a detached HEAD.
Branch string `json:"branch,omitempty"`
// DefaultBranch is the remote's default branch when git knows it locally
// (refs/remotes/<remote>/HEAD).
DefaultBranch string `json:"default_branch,omitempty"`
// BranchURL is the branch's page, set only when the branch is not the
// default and the host's URL scheme for branches is known.
BranchURL string `json:"branch_url,omitempty"`
}
Repo is where a working directory's repository lives.