Skip to main content
Beta Search for patterns within repository content with advanced filtering and pagination.
POST /api/v1/repos/grep
Authorization: Bearer YOUR_JWT_TOKEN
Content-Type: application/json

{
  "rev": "main",
  "query": {
    "pattern": "function.*Error",
    "case_sensitive": false
  },
  "file_filters": {
    "include_globs": ["*.js", "*.ts"],
    "exclude_globs": ["node_modules/**", "*.test.js"],
    "extension_filters": [".js", ".ts", ".tsx"]
  },
  "context": {
    "before": 2,
    "after": 2
  },
  "limits": {
    "max_lines": 1000,
    "max_matches_per_file": 50
  },
  "pagination": {
    "limit": 100
  }
}

Request Body

ParameterTypeDescription
revOptionalBranch name, tag, or commit SHA to grep in (defaults to repository’s default branch)
query.patternRequiredRegex pattern to search for
query.case_sensitiveOptionalWhether grep should be case sensitive (default: true)
pathsOptionalArray of specific paths to grep within
file_filters.include_globsOptionalGlob patterns for files to include in grep
file_filters.exclude_globsOptionalGlob patterns for files to exclude from grep
file_filters.extension_filtersOptionalFile extensions to filter by (e.g., [“.js”, “.py”])
context.beforeOptionalNumber of lines to include before each match
context.afterOptionalNumber of lines to include after each match
limits.max_linesOptionalMaximum total lines to return (default: 2000, max: 2000)
limits.max_matches_per_fileOptionalMaximum matches per file (default: 200)
pagination.cursorOptionalPagination cursor from previous response
pagination.limitOptionalMaximum number of matches to return (default: 200)

JWT Requirements

  • The JWT must include the repository in the repo claim
  • Requires git:read scope

Response

{
  "query": {
    "pattern": "function.*Error",
    "case_sensitive": false
  },
  "repo": {
    "ref": "main",
    "commit": "a1b2c3d4e5f6789..."
  },
  "matches": [
    {
      "path": "src/utils/error-handler.js",
      "lines": [
        {
          "line_number": 15,
          "text": "function handleError(message) {",
          "type": "match"
        },
        {
          "line_number": 16,
          "text": "  console.error(message);",
          "type": "context"
        }
      ]
    },
    {
      "path": "src/api/auth.js",
      "lines": [
        {
          "line_number": 42,
          "text": "function validateError() {",
          "type": "match"
        }
      ]
    }
  ],
  "next_cursor": "eyJmaWxlX2luZGV4IjoxMCwibGluZV9udW1iZXIiOjE1fQ==",
  "has_more": true
}

Response Headers

  • X-Cache: Indicates cache status (HIT or MISS)

Notes

  • Supports full regex patterns in the grep query
  • File filtering supports glob patterns (e.g., **/*.js, src/**/*.ts)
  • Pagination uses cursor-based navigation for consistent results
  • Large files or binary files may be automatically excluded from grep results

Error Responses

StatusDescription
400 Bad RequestInvalid regex pattern, missing required fields, or invalid pagination cursor
401 UnauthorizedMissing authorization header
403 ForbiddenInvalid JWT or missing git:read scope
404 Not FoundRepository or reference doesn’t exist
500 Internal Server ErrorGit command failures or database errors
503 Service UnavailableRepository sync in progress or storage unavailable
504 Gateway TimeoutRequest timeout