Skip to content
flow

CLI & automationghx and gitx

ghx and gitx

ghx, the local GitHub read cache Flow uses by default, and gitx, the git passthrough that updates cached pull requests after a push.

View as Markdown
On this page

Flow reads pull requests, issues and checks from GitHub constantly. ghx is a local, caching front for the GitHub CLI (gh) that serves those reads from disk and refreshes them in the background, so Flow and your shells stay fast and within GitHub's rate limits. gitx is a thin wrapper around git that tells ghx when a git push moved a branch, so cached pull requests update at once instead of at the next poll. Both ship with Flow.

Install

ghx and gitx are bundled with Flow. Settings › Advanced › Command-line tools (or Install command-line tools… in the command palette) links flow-cli, drop, ghx, gitx and sink into /usr/local/bin. ghx needs the GitHub CLI, gh, installed and logged in: everything ghx does not cache, it hands to gh.

How Flow uses ghx

Flow reads PR data through the program in Settings › General › Pull requests:

SettingDefaultMeaning
git.cli"ghx"The program that reads PR data: the bundled ghx cache, gh, or any client with the same commands. Empty means ghx.
git.events"ghx events"A long-running command whose cache-updated lines refresh PR data in Flow. Unset follows the read CLI; empty turns the stream off. There is none with gh.
git.asynctrueServe cached data instantly and refresh in the background (ghx's -A). Not available with gh.

Flow always runs the ghx bundled beside the app, never another copy on your PATH.

Route your shells through ghx and gitx

Flow's own GitHub writes go through ghx, so the cache stays current. A gh or git push typed in a shell, or run by a coding agent, would not, unless gh is ghx and git is gitx there. Two buttons in Settings › General › Pull requests set that up:

ButtonPalette actionAdds to ~/.zshrc
Route gh through ghxtoggle_gh_aliasalias gh=ghx
Route git through gitxtoggle_git_aliasalias git=gitx (plus a compdef so git still completes as git)

Each button adds one marked block at the end of ~/.zshrc, or removes it if it is there:

sh
# >>> flow: route gh through ghx (managed by Flow Settings) >>>
if command -v ghx >/dev/null 2>&1; then alias gh=ghx; fi
# <<< flow: route gh through ghx <<<
  • Only new shells pick the alias up. Shells already open keep their old gh / git until they re-read the file.
  • The alias only applies where the tool is on PATH (install the command-line tools first); Flow warns when it can't find it.
  • An agent gets it only where it runs commands in an interactive zsh or replays that shell's aliases (Claude Code's shell snapshot does). zsh -c scripts, bash and programs that run git directly do not.
  • A symlinked ~/.zshrc is followed and its target edited. Removing the block restores the file exactly.

ghx commands

sh
ghx pr list                         # a cached gh read: same arguments, same output as gh
ghx -A pr view 94                   # serve what is cached now, refresh in the background if stale
ghx -F pr view 94                   # block on a fresh fetch
ghx -W pr view 94                   # print, then a new line each time the cached answer changes
ghx pr merge 94 --squash            # a write: runs gh as typed, then updates the cache
ghx cache status
ghx events --repo owner/repo        # tail cache-updated events
CommandWhat it does
ghx [-F|-A] [-W] GH_ARGS…A gh command through the cache. pr list, pr view, pr diff, issue list and issue view are served from cached rows; search prs, search issues and read-only api calls from a cache of their output. Anything else is passed to gh unchanged.
ghx cache status | clear [--type …] | invalidate pr|issue|repo …Inspect, clear or invalidate the cache. (ghx cache list and ghx cache delete are gh's own Actions-cache commands and pass through.)
ghx audit summary | tail | clearghx's audit log of its reads: hits and misses per command and repository, and the most common miss reasons.
ghx daemon, ghx daemon info | stopRun, inspect or stop the background daemon. It normally starts on its own.
ghx events [--repo o/r[,…]] [--kind pr,issue,repo] [--since N]Print one line per cache-updated event, reconnecting as needed. This is what Flow's git.events runs.
ghx ingest pr|issue O/R N [--bust] [--data FILE|-]Tell the cache that an item changed, or hand it the new data. Also ingest repo, ingest --webhook EVENT and ingest push (what gitx sends).
ghx media URL [--repo o/r] [--pr N] [--refresh]Download a GitHub attachment (image, video, file) once and print its local path.
ghx webhooks …The GitHub webhook receiver and follower. See GitHub webhooks.

Read flags

FlagMeaning
-F, --forceFetch fresh from GitHub and wait for it.
-A, --force-asyncAnswer with what is cached right now (an empty [], {} or "" on a cold miss) and, only if that is stale or missing, ask the daemon to refresh it.
-W, --watchPrint {"seq":N,"stdout":"…"}, then a new line each time the output changes. Exits when stdout closes.

Without a flag, ghx answers from the cache when it holds the data and refreshes stale data in the background (stale-while-revalidate); concurrent refreshes of one item share a single gh call. gh errors are never cached. pr diff is always the whole diff.

Writes

A write through ghx (ghx pr merge 94, ghx api -X PATCH …, a GraphQL mutation, or the same typed as gh … under the alias) runs gh exactly as you typed it: same arguments, input, output and exit code. ghx never writes to GitHub itself. Around it, ghx keeps the cache in step:

  • Before gh runs, when the outcome is predictable (a merge with an explicit method, close, reopen, ready, an edit of title, body or base), ghx updates the cached item at once so Flow shows it.
  • After gh succeeds, ghx refetches the item and announces the change.
  • After gh fails, ghx puts the predicted fields back and refetches.

A pr create refreshes the head branch so the new pull request appears right away.

gitx

gitx runs git exactly as typed: the same arguments, terminal, signals, output and exit code. It never prints anything on stdout. The only difference is git push (including an alias that expands to one): gitx snapshots your remote-tracking refs before and after the push, and for every branch that moved it runs ghx ingest push. ghx then updates any cached open pull request on that branch with the new head commit and refetches it, retrying for a few seconds while GitHub catches up.

Every other git command is a direct exec of the real git, so gitx costs nothing there.

VariableMeaning
GITX_GITThe real git, as an absolute path. Default: the first git on PATH that isn't gitx, else /usr/bin/git.
GITX_GHXThe ghx to tell (empty: none). Default: the ghx beside gitx, else the first on PATH, used only if it is Flow's.
GITX_DEBUGNon-empty: show ghx's output and print each call to stderr.

gitx caveats

  • Only pushes recorded in remote-tracking refs are seen: a push to a bare URL (git push git@host:o/r main), or to a remote with no fetch refspec for the branch, reports nothing. So does --dry-run.
  • A shell alias is judged by its text: !git push -u origin HEAD is observed, but !f() { git push; }; f is not.
  • The alias is zsh's. Scripts, git hooks, editors and other programs run git directly, unless a git symlink to gitx sits early on your PATH.
  • gitx waits at most 5 seconds for ghx after a push, then exits with git's status.

Configuration

ghx keeps its state in ~/.ghx: the cache database (cache.db), the daemon's socket (ghx.sock), its info and log files, and attachments under media/. Everything else is set with environment variables:

VariableDefaultMeaning
GHX_DB_PATH~/.ghx/cache.dbThe cache database.
GHX_SOCKET~/.ghx/ghx.sockThe daemon's socket.
GHX_POLL_INTERVAL_S300How often the daemon polls watched repositories, in seconds. 0 turns polling off.
GHX_TTL_PR_LIST_S300How long a PR list stays fresh.
GHX_TTL_PR_DETAIL_S600How long a PR's details stay fresh.
GHX_TTL_PR_DIFF_S600How long a PR's diff stays fresh.
GHX_TTL_ISSUE_LIST_S, GHX_TTL_ISSUE_DETAIL_S300, 600The same for issues.
GHX_TTL_API_REST_S, GHX_TTL_API_GRAPHQL_S300Read-only api calls.
GHX_TTL_SEARCH_S120search results.
GHX_TTL_NEGATIVE_S3600How long a "not found" is remembered.
GHX_GH_TIMEOUT_S, GHX_GH_LIST_TIMEOUT_S30, 60Timeouts for a gh call and a gh list call.
GHX_GRAPHQL_FLOOR500Remaining GraphQL budget below which background refreshes wait. Your own reads and writes are never delayed.
GHX_MEDIA_MAX_MB, GHX_MEDIA_MAX_FILE_MB1024, 100The attachment cache's size and the largest single file.
GHX_DISABLE_SWR=1Never serve stale data while refreshing.
GHX_AUDIT_DISABLED=1Turn the audit log off.
GHX_DEBUGAny value: debug output.

Limits

  • ghx needs gh; with git.cli set to gh, Flow has no async reads and no event stream.
  • Shell aliases only reach interactive zsh.
  • A push gitx can't see (above) updates Flow at the next poll instead.
Sources

Written from these files in the Flow app repo

  • src/bin/ghx.rs
  • src/ghx/mod.rs
  • src/ghx/cli.rs
  • src/ghx/config.rs
  • src/bin/gitx.rs
  • src/gitx/mod.rs
  • src/shell_alias.rs
  • src/cli_install.rs
  • agent-skills/settings/MANIFEST.md