abt-git-tools
abt-git-tools provides granular local git @tool functions — clone, search, history, and workspace writes. For GitHub CLI operations (PRs, issues, Actions, releases), install abt-gh-tools separately.
| GitHub MCP | abt-git-tools + abt-gh-tools | |
|---|---|---|
| Network calls per operation | 1 (API) | 0 (local CLI) |
| Works with GitLab / Bitbucket | No | Yes (any https:// git URL via git_clone) |
Package id: abt-git-tools · Shorthand: git
abt docs package git --project-root . # full component → tool catalog
Tool catalog
| Component | Tool | Access |
|---|---|---|
| clone | git_clone |
read |
| workspace | git_repo_search |
read |
| workspace | git_file_read |
read |
| workspace | git_log |
read |
| workspace | git_diff |
read |
| workspace | git_show |
read |
| workspace | git_dir_list |
read |
| workspace | git_deepen |
read |
| write | git_push |
write |
| write | git_commit |
write |
| write | git_create_branch |
write |
| write | git_file_write |
write |
| write | git_file_content_write |
write |
| write | git_file_edit |
write |
| write | git_lfs_pull |
write |
The model sees the function name (git_log), not the git__git_log spec, so every tool carries the service prefix.
Tool spec syntax
Agent frontmatter uses shorthand__tool (double underscore) — individual tools or a package wildcard (git__<tool> or git__*):
tools:
- git__git_clone
- git__git_log
- git__* # all enabled read tools (+ writes when allow_writes permits)
- git__git_file_write # write — needs allow_writes
Unknown specs (e.g. git__read, git__investigation) are invalid because no tool has that name. Specs with more than one __ segment (e.g. git__git_clone__write) and bare tool names without the git__ prefix (e.g. git_clone) are invalid too. abt compile fails on such specs once the package is installed (run abt deps first), and abt config show --agent NAME lists what actually resolves.
For GitHub tools use the gh shorthand — see gh-tools.
Installation
packages:
- git: https://github.com/getyourguide/abt-core.git
revision: main
subdirectory: packages/abt-git-tools
- git: https://github.com/getyourguide/abt-core.git
revision: main
subdirectory: packages/abt-gh-tools # usually needed for PR/CI workflows
abt deps
Prerequisites
| Tool | Required | Notes |
|---|---|---|
git |
Yes | Clone and history |
rg / ripgrep |
Recommended | git_repo_search falls back to grep -REn without it |
gh |
For wildcards only | owner/* expansion in git_clone |
Tools
Every tool is described with parse_docstring, so each parameter's description reaches the model. Out-of-range numbers return an [ERROR] instead of being clamped. Results are capped at 75,000 bytes (about 25k tokens); the full output is saved inside the clone and the cut result ends with the git_file_read call that pages through it. ABT_TOOL_MAX_OUTPUT_BYTES overrides the cap. An empty result is never returned bare: it says what was searched and found nothing.
git_clone
git_clone(
repo: str,
branch: str = "main",
depth: int | None = None,
since: str | None = None,
sparse_paths: list[str] | None = None,
max_repos: int = 10,
) -> str
Clones a repository so agents can browse it under /workspace/repos/<repo_name>/. repo is "owner/name" (GitHub), "owner/*" (wildcard, requires gh), or a public https:// git URL. Local paths, file://, http://, ssh addresses and URLs with a user or password, a query string or a fragment, and localhost or private, loopback and link-local addresses return [ERROR] without running git, so a model cannot make another repository on the host browsable or reach the host's own network services. IPv6 addresses that embed an IPv4 one (NAT64, 6to4, IPv4-mapped) are judged by the embedded address. A hostname that resolves to a private address (10.0.0.1.nip.io style) is not checked: restrict that in the network policy of the machine abt runs on. Git calls ignore GIT_DIR, GIT_WORK_TREE and the other variables that point git at a repository in abt's own environment. Network git calls also run with GIT_ALLOW_PROTOCOL=https (a value you set yourself is kept), so an insteadOf rewrite cannot reach file:// or ssh, and with http.followRedirects=false, so a public URL cannot redirect the clone to an internal address; a repository that moved must be cloned from its new URL. depth defaults to ABT_GIT_CLONE_DEPTH (1 = shallow) when omitted; pass 0 for full history. max_repos is 1–50.
since bounds the clone by date instead of commit count (e.g. "7 weeks ago", "2026-01-01") — cheaper than depth=0 for bounded look-backs. Wins over depth when both are set (git can't combine --depth and --shallow-since). An empty window auto-retries at depth=1. Merge-heavy history can drop more than the date implies; verify with git_log/git_deepen if completeness matters.
sparse_paths limits the checkout to the given directories (relative paths, no glob patterns). If git rejects them, git_clone returns [ERROR] instead of a full checkout.
Internally, git_clone keeps a shared bare-clone cache per repo and creates a fresh, isolated worktree from it on every call — cheap and safe to call again mid-run. Calling it twice for the same repo/branch does not re-download unless the cache is older than ABT_GIT_CACHE_TTL seconds.
git_clone("acme/data-pipelines")
git_clone("acme/data-pipelines", since="7 weeks ago")
git_clone("acme/*", max_repos=5) # requires gh CLI
Returns repo_name='owner___name' for downstream tools (host@owner___name outside github.com, so the same owner and name on two hosts never share a clone; a very long or unusual URL, or one with a part that starts or ends with _, becomes a slug ending in @@ and a hash). A repo or branch that starts with - returns [INVALID] without running git. A branch that does not exist says so and suggests omitting branch.
Workspace
| Tool | Purpose |
|---|---|
git_repo_search(pattern, path, glob, ignore_case, literal) |
Search with rg (falls back to grep); matching lines with line numbers and two lines of context. literal=True searches plain text, and an invalid regex says so. No match returns (no matches for …) |
git_file_read(path, lines, start_line) |
Raw file text, whole or a range. Negative values are an error; a start_line past the end names the file's length |
git_log(max_entries, path, author, since, grep, ref) |
Commits as short hash, date, author, subject; max_entries 1–200. Deepens a shallow clone when fewer commits exist than requested, and says when history is still shallow |
git_diff(ref, path, stat) |
Diff of ref (default HEAD~1) against the working tree; stat=True lists changed files first. A ref missing from a shallow clone is fetched automatically |
git_show(ref, stat) |
One commit (stat=True recommended); same automatic deepening |
git_dir_list(path, recursive, pattern) |
Entries with directories marked /, .git hidden; recursive=True lists files below path |
git_deepen(extra_commits) |
Fetch more history for a shallow clone, 1–1000. Only changes the local clone, so it is a read tool |
Write
Requires config.packages.abt-git-tools with effective allow_writes: true for the write component.
| Tool | Purpose |
|---|---|
git_push |
Push HEAD to a branch on the remote |
git_commit |
Stage paths and commit. paths takes one or more repo-relative paths, space separated (quote a path containing a space); it defaults to . when omitted, but an explicitly empty paths is refused rather than widened to . |
git_create_branch |
Create and check out a new branch |
git_file_write |
mkdir/cp/mv/touch/rm (operation is a closed set) |
git_file_content_write |
Write a whole file (create or overwrite) — the model restates every byte, so use it for new or small files |
git_file_edit |
Replace an exact snippet in an existing file. Prefer this for any edit to a file that already exists: the call carries only the changed snippet, so its cost is independent of file size. A whole-file git_file_content_write of a large file can exceed the response's output-token cap, in which case content is truncated away entirely and the write silently fails. expected_count (≥ 1) must equal the real match count or nothing is written; line endings and encoding are preserved byte for byte |
git_lfs_pull |
Pull LFS content |
Usage in an agent
tools:
- git__git_clone
- git__git_repo_search
- git__git_log
- gh__gh_run_view # abt-gh-tools
- gh__gh_pr_list
Minimal workflow:
git_clone("owner/repo")once per repogit_file_read/git_dir_listunder/workspace/repos/<repo_name>/git_repo_search,git_log,gh_run_view, etc.
Write tool gating
| Level | Config key | Effect |
|---|---|---|
| Package | config.packages.abt-git-tools.allow_writes |
Default for the write-gated component |
write component |
config.packages.abt-git-tools.components.write.allow_writes |
Gates git_push, git_commit, git_create_branch, git_file_write, git_file_content_write, git_file_edit, git_lfs_pull; false always blocks |
workspace component |
config.packages.abt-git-tools.components.workspace.allow_writes |
Not needed: every workspace tool is read-only and stays available under the default allow_writes: false |
Auth
git_clone (private repos), git_push, history deepening, git_lfs_pull and any gh fallback (owner/* wildcard expansion) share the same
token, which is credentials.github.token from profiles.yaml, else GITHUB_TOKEN, else GH_TOKEN. One resolver serves git, gh and context.github(), so they always use the same token. See abt-gh-tools.
credentials:
github:
token: "{{ env_var('GITHUB_TOKEN') }}"
git: {} # must exist: a selected `git__*` tool fails with E_PROFILE_MISSING_NAMESPACE without it; its contents are not read
The token reaches only the process that needs it, and never appears in a clone URL, a command line, .git/config, a log or a tool result (git var and git config are refused, so the agent cannot ask git to print it):
| Process | Receives |
|---|---|
git network calls (clone, fetch, pull, push, ls-remote, lfs, submodule update, remote update) |
An Authorization header for https://github.com/ only, passed through that process's GIT_CONFIG_* environment. Other hosts (GitLab, look-alike domains, plain http://, a redirect target) get nothing |
every other git call (log, diff, status, rev-parse, worktree, grep, …) |
Nothing, so a hook, textconv or filter program a local call spawns never sees a credential |
gh |
GH_TOKEN and GITHUB_TOKEN, both set to the token above (gh scopes them to GitHub hosts) |
rg, cat, grep, … |
No token variables, even when your shell exports them |
Commands run with an allow-listed environment and no stdin. Output is read through a bounded buffer: a command that prints more than 10 MB (or ABT_TOOL_MAX_OUTPUT_BYTES, if larger) is stopped, and the tool returns the usual truncated result whose saved file ends at that point.
GH_TOKEN and GITHUB_TOKEN in your shell never reach git, so gh auth setup-git credential-helper use does not pick them up for GitHub Enterprise hosts (*.ghe.com, GHES) or any host other than github.com. Such a host authenticates through your machine's git setup: a credential helper with stored gh auth login credentials, or an SSH key through a url.<base>.insteadOf rewrite of its https URL. abt starts network git with GIT_ALLOW_PROTOCOL=https, so the rewrite is refused (git refused the ssh transport ...) until you start abt with GIT_ALLOW_PROTOCOL=https:ssh. The model still cannot ask for an ssh source: git_clone accepts only owner/name and https URLs.
Environment variables
| Variable | Default | Description |
|---|---|---|
ABT_GIT_CLONE_DEPTH |
1 |
Default clone depth (shallow); 0 = full history |
ABT_GIT_CLONE_TIMEOUT |
120 |
Clone timeout (seconds) |
ABT_GIT_CLONE_LOCK_TIMEOUT |
60 |
Per-repo clone lock wait (seconds) |
ABT_GIT_LOCK_STALE_SECONDS |
300 |
Age after which a stuck clone lock is treated as stale and cleared |
ABT_GIT_CACHE_TTL |
30 |
Seconds a bare-clone cache is trusted without re-fetching |
ABT_GIT_EXEC_TIMEOUT |
30 |
Subprocess timeout for git/gh commands (seconds) |
ABT_GIT_EXEC_ALLOWLIST |
git,gh,rg,cat,find,head,tail,wc,ls,sed,echo,mkdir,cp,mv,touch,grep,diff,rm |
Comma-separated first-token allowlist for shelled-out commands. Beyond the first token, flags that execute programs or write files are rejected per binary (e.g. git --upload-pack, --output, --git-dir, -c, abbreviated or grouped forms included; rg --pre), path arguments — including --flag=PATH values — must stay inside the repo once symlinks are resolved, and writes into .git are refused (see Cloned repos are untrusted) |
ABT_TOOL_MAX_OUTPUT_BYTES |
75 KB for git/gh tools (500 KB for other tools) | Per-tool output cap in bytes |
Cloned repos are untrusted
A repository an agent clones can contain anything, including symlinks to ~/.ssh or to its own .git/hooks. The tools therefore enforce, independently of the allowlist above:
- Paths stay inside the clone. Every path argument (including a value glued onto a short option, such as
-fkey) and everygit_file_edit/git_file_content_writetarget is resolved, following symlinks, and must land inside the repo.git_file_writecp/mvinto a directory also checks the file it would create there. Absolute paths,..,~, and a symlink pointing outside the repo are refused with[INVALID COMMAND]or[ERROR]. A symlink that stays inside the repo works normally. .gitis never written. Writes to.git, in any letter case or through a symlink, are refused, whether they come from the git tools or from the filesystem tools (write_file,edit_file,delete) under/workspace/repos/: a file in.git/hooks, or a.gitfile repointed at a config that setscore.fsmonitor, would run a program on the next git call. The filesystem-tool protection matches the exact name.gitand its case variants (.GIT) at any depth, including under hidden directories to a bounded depth, which covers case-insensitive filesystems but not other aliases a filesystem may give it. These path rules are one layer; the one that holds at any depth is that every git call runs with command-line-level settings that outrank any repository's own config (core.fsmonitor=false,core.hooksPathpointing at nothing,protocol.extandprotocol.fileoff, submodules not entered by status, diff or fetch), so a repo planted under the clone, or an embedded repo thatgit add .turned into a gitlink, cannot make git run its programs. The repo locks (/workspace/repos/.lock-*) are protected the same way. A git command is also refused when it would run, through-C, in a directory under the clone that has its own.git. Reads (git_file_read,read_file) of.gitare allowed.repo_nameis never a path. Every tool takes therepo_namevaluegit_clonereturned, a single directory name directly under the repos directory. An absolute path,../, or a symlink leading elsewhere is refused (the error lists the available repos), so the write tools cannot reach the project or any other repository on disk.- Walks do not follow symlinks.
rg -L/--follow,grep -R/-S,find -L/-H/-follow,cp -L/-H,ls -L/-Handdiff -rare rejected, abbreviated long options (--deref) included; thegrepfallback ofgit_repo_searchuses-r. sedscripts cannot write to other files. Thewflag ofs///is rejected along with thew,eandrcommands.sed -istill edits files inside the repo.
A committed symlink that points outside the repo is refused as a path argument for every command, including git log -- <link>.
repo_name format
owner/name → owner___name (triple underscore); other hosts add the host: gitlab.example.com@owner___name. Use the exact value from git_clone output.