Query a code workspace
Runs one query in a workspace that POST /code-workspaces opened. Paths are relative to the repository root. You need the member role or above.
tool picks what runs:
tool |
What it does |
|---|---|
run_command |
Runs the bash command line in command from the repository root, such as rg, sed, git log, git diff, or git blame, with no credentials and no network access. It has 120 seconds, and its output is cut at 500 lines. |
search |
Searches for pattern, an extended regular expression, with git grep -E. context_lines adds lines around each match. |
read |
Returns a file’s numbered lines, from start_line to end_line, up to 400 at a time. |
list |
Lists a directory, or with recursive every file under it. name_pattern keeps the paths that match it. |
diff |
Diffs a pull request against its base, in a workspace opened from a pull request. |
log |
Lists the commits that touched a path. |
blame |
Shows who last changed each line, from start_line to end_line, up to 400 at a time. |
dependencies |
Lists the dependency manifests and lock files, or with pattern the lines in them that name that package. |
truncated is true when the output was cut at its limit. Narrow the command, path, or pattern and run it again.
A closed workspace returns 404 Not Found, and one that failed or is closing returns 409 Conflict. In both cases, open the workspace again.
Request
POST /code-workspaces/{workspace_id}/query
Send an API key with the read scope in the X-Api-Key header.
Path parameters
| Parameter | Description |
|---|---|
workspace_idstring, required | workspace_id from opening a code workspace. |
Body
A required application/json body.
| Field | Description |
|---|---|
toolstring, required | run_command (a bash command line in the repository root: rg, sed, git log, git diff, git blame and the like, with no credential and no network), or one of the fixed commands: search (git grep -E), read (a file’s lines), list (a directory, or files by name), diff (a pull request against its base), log (commits touching a path), blame (who last changed a file’s lines), dependencies (the dependency manifests and lock files, or the lines in them naming a package). One of run_command, search, read, list, diff, log, blame, or dependencies. |
commandstring | For run_command: the bash command line, run from the repository root with a 120s limit; output is cut at 500 lines. |
pathstring | A path relative to the repository root. |
patternstring | Extended regular expression for search; for dependencies, the package name as text. |
ignore_caseboolean | Default false. |
context_linesnumber | Lines of context around each search match. Default 0. At least 0. At most 5. |
name_patternstring | For list: only paths under path matching this extended regular expression, case-insensitive. |
start_linenumber | Default 1. At least 1. |
end_linenumber | Up to 400 lines are read or blamed. At least 1. |
recursiveboolean | list every file under the path instead of one level. Default false. |
Responses
200 OK
| Field | Description |
|---|---|
outputstring, required | The command’s output: for run_command, stdout and stderr together, ending with the exit code when it isn’t 0; file:line:text for search, numbered lines for read, paths (directories end in /) for list, commit, author, date and text per line for blame. |
truncatedboolean, required | Whether the output was cut at its limit; narrow the command, path or pattern. |
400 Bad Request
The query is invalid, such as a path outside the repository or a diff outside a pull request.
404 Not Found
The workspace has closed; open it again.
409 Conflict
The workspace failed or is closing; open it again.
429 Too Many Requests
The workspace is busy with other queries; try again in a few seconds.