OpenAI is partnering with Hacktron to find vulnerabilities in its systems. Read the announcement.

Skip to content Hacktron Sign in [S]
Hacktron Sign in [S] Customers Docs Contact Sign in

Query a code workspace

1 min
, View, ChatGPT, Claude, Perplexity, OpenAPI

Copy page

Query a code workspace

View MarkdownOpen in ChatGPTOpen in ClaudeOpen in PerplexityDownload OpenAPI

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

ParameterDescription
workspace_id
string, required
workspace_id from opening a code workspace.

Body

A required application/json body.

FieldDescription
tool
string, 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.
command
string
For run_command: the bash command line, run from the repository root with a 120s limit; output is cut at 500 lines.
path
string
A path relative to the repository root.
pattern
string
Extended regular expression for search; for dependencies, the package name as text.
ignore_case
boolean
Default false.
context_lines
number
Lines of context around each search match. Default 0. At least 0. At most 5.
name_pattern
string
For list: only paths under path matching this extended regular expression, case-insensitive.
start_line
number
Default 1. At least 1.
end_line
number
Up to 400 lines are read or blamed. At least 1.
recursive
boolean
list every file under the path instead of one level. Default false.

Responses

200 OK

FieldDescription
output
string, 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.
truncated
boolean, 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.

[↓] [↑] [enter] to visit
Menu
[M]
Next in menu
[J]
Previous in menu
[K]
Find
[F]
Ask
[A]
Sign in
[S]
Copy page
[C]
Listen
[L]
Justification
[R]
Language
[G]
Dark mode
[D]
High contrast
[H]
Shortcuts
[I]
Close
[Esc]