Skip to content

Environment and context

tt-git gives a plugin everything it needs through environment variables. There is no SDK to import: read the variables, and run $TTGIT_BIN_PATH to talk back.

Every plugin process gets these:

Variable
TTGIT_ENV1, so a program can tell it’s running under tt-git.
TTGIT_BIN_PATHThe running tt-git executable. Use it rather than tt-git from PATH, so you talk to the same version.
TTGIT_SOCKET_PATHThis tt-git’s API socket. The CLI commands that need a running tt-git use it automatically.
TTGIT_PLUGIN_IDThe plugin’s id.
TTGIT_PLUGIN_ROOTThe plugin’s directory.
TTGIT_PLUGIN_CONFIG_DIRA directory for files the user edits, like a .env. tt-git creates it and never touches what’s in it.
TTGIT_PLUGIN_STATE_DIRA directory for the plugin’s own state. tt-git creates it and never touches what’s in it.
TTGIT_REPO_PATHThe repository’s working tree.
TTGIT_PLUGIN_CONTEXT_JSONWhat the user was looking at (below).

Some entry points add more:

Entry pointAdds
actionTTGIT_PLUGIN_ACTION_ID, the qualified action id.
event hookTTGIT_PLUGIN_EVENT, the event name, and TTGIT_PLUGIN_EVENT_JSON, set to {"event": …, "data": …}.
startup commandTTGIT_PLUGIN_EVENT=startup.
paneTTGIT_PLUGIN_ENTRYPOINT_ID, plus any --env KEY=VALUE the opener passed.
link handlerTTGIT_PLUGIN_CLICKED_URL and TTGIT_PLUGIN_LINK_HANDLER_ID.

tt-git sets its own variables last, so they win over any variable of the same name in the environment it was started from.

TTGIT_PLUGIN_CONTEXT_JSON is a JSON object describing the moment the plugin ran: which repository, which branch, and what was selected.

Field
repo_pathThe repository’s working tree.
repo_nameIts folder name.
headThe commit HEAD points at.
branchThe checked-out branch, if any.
upstreamIts upstream, like origin/main, if it has one.
selected_commitThe full hash of the commit selected in the graph.
selected_branchThe branch selected in the branches pane.
selected_fileThe file selected in the status pane.
selected_textNot set yet; kept for compatibility with herdr.
focused_paneThe pane that had focus: graph, status, branches or details.
invocation_sourceHow the plugin was started: keybinding, palette, socket, event, startup, link_click or pane.
correlation_idAn id for this run.
clicked_urlFor a link handler, the link.
link_handler_idFor a link handler, its id.

The three selected_* fields hold each pane’s selection whichever pane has focus, so an action can use the selected commit even when it was run from the branches pane. Fields that don’t apply are null, so check before you use one. For example, the open-on-github example reads it like this:

const ctx = JSON.parse(process.env.TTGIT_PLUGIN_CONTEXT_JSON ?? "{}");
if (what === "commit" && ctx.selected_commit) {
url = `${repoUrl()}/commit/${ctx.selected_commit}`;
}

For live state rather than a snapshot, ask the socket: repo.info, status.get, branch.list and graph.selection. See CLI and socket API.

  • Each action, hook and startup command is a fresh process.
  • Up to 32 can run at once. Past that, a run fails with plugin_command_limit_reached.
  • tt-git keeps up to 64 KiB of each command’s stdout and of its stderr, then adds a note that the rest was cut.
  • The last 200 runs are kept in the plugin log. A command that fails shows a ✗ notice in the help bar.