Codetree
GET/repositories/{repo_id}/grep
Search file content in a repository at a ref
grep_repo
tree:read
A token needs thetree:readscope: Browse repository trees and blobsGranted bymcp_agent,mcp_agent_write,read_api,read_repository,write_api,write_repository.Every operation this scope unlocksMetered egress · in band body
x-gitmoap-egress: {"kind":"metered","arg":"in_band_body"}
Finds lines matching q — literal text, or an extended regular expression with regex=true
— across the repository at one commit, or within up to 20 paths. Returns at most 200 matches
with two lines of context each, and says when the search stopped short. Anyone who can read the
repository's code may call it.
Parameters
Path
- repo_idRepositoryId (string · uuid)Repository ID
Query
- qstringThe text to find (required). Matched literally unless
regex=true - refstringoptionalGit ref (branch, tag, or commit SHA). Default: HEAD
- patharray of stringoptionalLimit the search to this file or directory; repeat for several. Default: the whole repository
- regexbooleanoptionalRead
qas an extended regular expression. Default: false - ignore_casebooleanoptionalMatch regardless of case. Default: false
Responses
200Matching lines with two lines of context each, at the commit the ref resolved to. At most 200 matches; `truncated` says when more may existapplication/json
matchesarray of GrepMatchMatching lines, grouped by file in path order and by line within a file.
- The GrepMatch schema
- afterarray of stringThe lines just after the match, in file order.
- beforearray of stringThe lines just before the match, in file order.
- lineinteger0–∞The line number of the match, counting from 1.
- pathstringThe file the match is in, relative to the repository root.
- textstringThe matching line. A very long line is shortened and ends with
….
- shaCommitHash (string)The commit that was searched. Repeating the search at this commit returns the same lines.
- truncatedbooleanThe search stopped before it finished — it reached its match limit, its size limit or its time limit. More matches may exist; narrow the search with a path or a more specific pattern to see them.
200 exampleSynthesized example
{
"matches": [
{
"after": [],
"before": [],
"line": 55,
"path": "path-e730",
"text": "text-5b3d"
}
],
"sha": "af50868fd2a002f634c1537de7d6e62ae96d0a76",
"truncated": false
}
400Missing or overlong pattern, an invalid regular expression, or an invalid pathapplication/json
Error codes
- BAD_REQUESTThe request is malformed: a parameter or a body field is not a well-formed value of its type
errorErrorBody
- The ErrorBody schema
- codestringThe coarse category, tied to the status:
NOT_FOUND,CONFLICT,INSUFFICIENT_SCOPE. Every error has one; the API reference's error catalogue lists them all. - messagestringWhat went wrong, for a person. Written to be read, not parsed: match on
reasonorcode. - fieldstring or nulloptionalOn a
400that refused one field's value, the field, as its JSON path:email,items[0].name. Put the message under that input. Absent on every other error. - reasonstring or nulloptionalThe specific code, when the error has one:
LAST_ORGANIZATION_OWNER,BRANCH_PROTECTED. The message starts with it too. Match on this when it is present, and oncodeotherwise. - required_scopestring or nulloptionalThe scope the access token was missing, on
INSUFFICIENT_SCOPE. - violationsanyoptionalPresent on the structured-validation errors (
PROVIDER_VALIDATION_FAILEDper-node,PIPELINE_VALIDATION_FAILEDDAG): a JSON array of the offending elements, so a caller can fix every one in a single round-trip. Absent (omitted) on every other error.
400 exampleSynthesized example
{
"error": {
"code": "code-8de9",
"message": "Label every synthesized example"
}
}
401Unauthenticated — no credential, or an invalid oneapplication/json
Error codes
- UNAUTHORIZEDNo credential was sent, or the one sent is invalid, expired or revoked
errorErrorBody
- The ErrorBody schema
- codestringThe coarse category, tied to the status:
NOT_FOUND,CONFLICT,INSUFFICIENT_SCOPE. Every error has one; the API reference's error catalogue lists them all. - messagestringWhat went wrong, for a person. Written to be read, not parsed: match on
reasonorcode. - fieldstring or nulloptionalOn a
400that refused one field's value, the field, as its JSON path:email,items[0].name. Put the message under that input. Absent on every other error. - reasonstring or nulloptionalThe specific code, when the error has one:
LAST_ORGANIZATION_OWNER,BRANCH_PROTECTED. The message starts with it too. Match on this when it is present, and oncodeotherwise. - required_scopestring or nulloptionalThe scope the access token was missing, on
INSUFFICIENT_SCOPE. - violationsanyoptionalPresent on the structured-validation errors (
PROVIDER_VALIDATION_FAILEDper-node,PIPELINE_VALIDATION_FAILEDDAG): a JSON array of the offending elements, so a caller can fix every one in a single round-trip. Absent (omitted) on every other error.
401 exampleSynthesized example
{
"error": {
"code": "code-30ad",
"message": "Draw the region map from operation density"
}
}
403Forbidden — the caller's access level or token scope is insufficientapplication/json
Error codes
- FORBIDDENYou are signed in but may not do this here;
reasonnames the permission or the rule that refused it - INSUFFICIENT_SCOPEThe access token lacks the scope this operation needs;
required_scopenames it - PERMISSION_REQUIREDYou need a permission you do not hold here; the message names it
errorErrorBody
- The ErrorBody schema
- codestringThe coarse category, tied to the status:
NOT_FOUND,CONFLICT,INSUFFICIENT_SCOPE. Every error has one; the API reference's error catalogue lists them all. - messagestringWhat went wrong, for a person. Written to be read, not parsed: match on
reasonorcode. - fieldstring or nulloptionalOn a
400that refused one field's value, the field, as its JSON path:email,items[0].name. Put the message under that input. Absent on every other error. - reasonstring or nulloptionalThe specific code, when the error has one:
LAST_ORGANIZATION_OWNER,BRANCH_PROTECTED. The message starts with it too. Match on this when it is present, and oncodeotherwise. - required_scopestring or nulloptionalThe scope the access token was missing, on
INSUFFICIENT_SCOPE. - violationsanyoptionalPresent on the structured-validation errors (
PROVIDER_VALIDATION_FAILEDper-node,PIPELINE_VALIDATION_FAILEDDAG): a JSON array of the offending elements, so a caller can fix every one in a single round-trip. Absent (omitted) on every other error.
403 exampleSynthesized example
{
"error": {
"code": "code-d9a9",
"message": "Pin a page's payload to the build that rendered it"
}
}
404Repository or ref not foundapplication/json
Error codes
- NOT_FOUNDThe resource does not exist — or exists and you cannot see it: a private resource you have no access to answers exactly as an absent one does
errorErrorBody
- The ErrorBody schema
- codestringThe coarse category, tied to the status:
NOT_FOUND,CONFLICT,INSUFFICIENT_SCOPE. Every error has one; the API reference's error catalogue lists them all. - messagestringWhat went wrong, for a person. Written to be read, not parsed: match on
reasonorcode. - fieldstring or nulloptionalOn a
400that refused one field's value, the field, as its JSON path:email,items[0].name. Put the message under that input. Absent on every other error. - reasonstring or nulloptionalThe specific code, when the error has one:
LAST_ORGANIZATION_OWNER,BRANCH_PROTECTED. The message starts with it too. Match on this when it is present, and oncodeotherwise. - required_scopestring or nulloptionalThe scope the access token was missing, on
INSUFFICIENT_SCOPE. - violationsanyoptionalPresent on the structured-validation errors (
PROVIDER_VALIDATION_FAILEDper-node,PIPELINE_VALIDATION_FAILEDDAG): a JSON array of the offending elements, so a caller can fix every one in a single round-trip. Absent (omitted) on every other error.
404 exampleSynthesized example
{
"error": {
"code": "code-cf75",
"message": "Label every synthesized example"
}
}
409The repository is empty: nothing has been pushed to it, so there is nothing to searchapplication/json
Error codes
- CONFLICTThe request conflicts with the resource's current state;
reasonsays how - REPOSITORY_EMPTYThe repository has no branches or tags yet; there is nothing to read until something is pushed to it
errorErrorBody
- The ErrorBody schema
- codestringThe coarse category, tied to the status:
NOT_FOUND,CONFLICT,INSUFFICIENT_SCOPE. Every error has one; the API reference's error catalogue lists them all. - messagestringWhat went wrong, for a person. Written to be read, not parsed: match on
reasonorcode. - fieldstring or nulloptionalOn a
400that refused one field's value, the field, as its JSON path:email,items[0].name. Put the message under that input. Absent on every other error. - reasonstring or nulloptionalThe specific code, when the error has one:
LAST_ORGANIZATION_OWNER,BRANCH_PROTECTED. The message starts with it too. Match on this when it is present, and oncodeotherwise. - required_scopestring or nulloptionalThe scope the access token was missing, on
INSUFFICIENT_SCOPE. - violationsanyoptionalPresent on the structured-validation errors (
PROVIDER_VALIDATION_FAILEDper-node,PIPELINE_VALIDATION_FAILEDDAG): a JSON array of the offending elements, so a caller can fix every one in a single round-trip. Absent (omitted) on every other error.
409 exampleSynthesized example
{
"error": {
"code": "code-e26e",
"message": "Pin a page's payload to the build that rendered it"
}
}
CLI
gitmoap tree grep-repo
- --repo-ididRepository ID (id or owner/repo path)
- --ignore-caseflagoptionalMatch regardless of case. Default: false
- --pathrepeatableoptionalLimit the search to this file or directory; repeat for several. Default: the whole repository
- --qstringThe text to find (required). Matched literally unless `regex=true`
- --refstringoptionalGit ref (branch, tag, or commit SHA). Default: HEAD
- --regexflagoptionalRead `q` as an extended regular expression. Default: false