---
title: "Workspace: Grep"
method: POST
path: "/v1/agents/{agent_id}/workspace/grep"
tags: ["API v1", "Agents", "Agents Workspace"]
---

# Workspace: Grep

`POST /v1/agents/{agent_id}/workspace/grep`

## Request

- Base URL: `https://api.xpander.ai` (the document declares no server; this is the origin it was published from)
- URL: `https://api.xpander.ai/v1/agents/{agent_id}/workspace/grep`
- Auth: API key in header `x-api-key`

Search for a regex pattern across files in the agent's workspace.

## Path parameters

- `agent_id` string, required

## Request body

- GrepRequest
  - `pattern` string, required: Regex pattern to search for (Extended Regular Expressions).
  - `path` string: Directory or file path to search in, relative to workspace root. Directories are searched recursively.
  - `include` string, nullable: Glob pattern to filter which files to search (e.g. '*.py' to only search Python files).
  - `context_lines` integer: Number of lines of context to show before and after each match.

## Response `200`

Successful Response

- GrepResponse
  - `matches` GrepMatch[]: List of matched results with context
    - `file` string, required: Path of the file containing the match
    - `line` integer, required: 1-indexed line number of the match
    - `content` string, required: The matched line content
    - `context` string: Surrounding lines of context
  - `total_matches` integer: Total number of matching lines found
  - `files_with_matches` integer: Number of distinct files that contained at least one match
  - `summary` string: Human-readable one-line summary of the search result

## Other responses

- `422`: Validation Error

---

[API](https://skmtc.dev/xpander/apis/xpander-ai-api-service.md) - [All operations](https://skmtc.dev/xpander/apis/xpander-ai-api-service/llms.txt) - [OpenAPI document](https://skmtc.dev/xpander/apis/xpander-ai-api-service/revisions/725c0066d5df?raw)
