Skip to main content

Cotool + Sourcegraph

Connect Sourcegraph to Cotool so agents search code, commits, and diffs across every indexed repository and read files at any revision during investigations.

Code & CI
Updated

The short answer

Sourcegraph searches code, commit messages, and diffs across many repositories with one query language and reads any branch, tag, or commit. Cotool's Sourcegraph integration, added in release 0.74.0, gives agents repository discovery, code search, file and commit retrieval, and read-only GraphQL queries.[1][4]

How it connects: Cotool runs read-only queries against the Sourcegraph GraphQL API with an access token sent in the Authorization header. Use a service account's token: service accounts are meant for API integrations, have no email or password, and can't open the Sourcegraph UI.[1][5][6]

What Cotool uses from Sourcegraph

Code search
Queries match file contents and narrow results with filters such as repo:, file:, lang:, and content:, each of which can be negated.[4]
Commit and diff search
type:commit searches commit messages and type:diff searches changes. Both accept author:, committer:, message:, before:, and after: filters, so a query can scope history to a person, a phrase, or a time window.[4]
Files at any revision
A revision appended to repo: or given with rev: can be a branch, a commit hash, or a tag, and several can be searched at once.[1][4]
Repositories
Repository filters select forks and archived repositories, repositories with given metadata or topics, and those with commits after a date.[1][4]
Audit log actors
Sourcegraph audit entries follow an actor, action, entity pattern. The actor block carries actorUID, the client IP, the user agent, and fromAccessTokenID when a token was used.[8]

Detections, hunts, and triage

Find every copy of a leaked valueTriage
When an alert names a leaked key prefix, a suspicious package, or a vulnerable function, an agent searches for it across every repository the token can read and opens the file at the commit that introduced it.[1][2][4]
Review recent changes to sensitive pathsHunt
A hunt runs type:diff searches scoped by file: and after: over CI workflows, Dockerfiles, or authentication code, and flags changes from unexpected authors.[3][4]
Attribute code in an alert to its authorEnrichment
For code named in a finding, an agent lists the commit history of the path and records who changed it and when, so the alert reaches the owning team.[1][4]

Example query

Dockerfile changes from outside authorstext
type:diff file:Dockerfile after:"6 weeks ago" -author:example.com>$

Finds Dockerfile diffs from the last six weeks whose author string doesn't end in your domain. Replace example.com with your email domain, and swap file: for the paths you care about.[4]

Setup and permissions

An admin opens Administration > Users & auth > Users, clicks Create User, checks Service account, and creates it. In that account's Access tokens settings, generate a token, keep the default user:all scope, set how long it stays valid, and copy it from the screen.[6][7]

PermissionAccess
Service Account system roleAssigned automatically to every service account and provides basic API access.[6]Read
Repository permissionsService accounts see only public and unrestricted repositories by default, so grant the private repositories to search.[6]Read
user:allThe default token scope, enough for most uses of the GraphQL API.[7]Read
site-admin:sudoLeave unselected. Sourcegraph reserves it for impersonating other users.[7]Write
  • Sourcegraph shows an access token once. After the page closes, you can only revoke it and issue a new one.[7]
  • Service accounts can also use M2M OAuth credentials, which issue tokens through the client credentials flow that expire after one hour.[6]

How Cotool works with Sourcegraph

  • Cotool added Sourcegraph in release 0.74.0 for repository discovery, code search, file and commit retrieval, and read-only GraphQL queries, and fixed Sourcegraph commit lookups in release 0.79.0.[1]
  • Cotool response agents investigate and triage alerts across the whole tool stack, so a code search sits in the same investigation as identity, endpoint, and log evidence.[2]

FAQ

Which repositories can Cotool search through Sourcegraph?
Cotool searches what the connected token's owner can read. A Sourcegraph service account sees only public and unrestricted repositories until private ones are granted to it.[1][6]
Can the Sourcegraph integration change code or settings?
No. Cotool's Sourcegraph integration runs read-only GraphQL queries for search, files, commits, and repositories.[1]

Sources

  1. Changelog (Cotool docs) · accessed November 22, 2026
  2. Respond to every signal (Cotool Respond) · accessed November 22, 2026
  3. Threat hunting (Cotool Hunt) · accessed November 22, 2026
  4. Search query syntax (Sourcegraph docs) · accessed November 22, 2026
  5. Sourcegraph GraphQL API (Sourcegraph docs) · accessed November 22, 2026
  6. Service accounts (Sourcegraph docs) · accessed November 22, 2026
  7. Creating an access token (Sourcegraph docs) · accessed November 22, 2026
  8. Audit log (Sourcegraph docs) · accessed November 22, 2026

Related integrations

All integrations

Use cases with Sourcegraph

Related reading

Attackers are scaling with tokens

Cotool helps defenders operate at machine speed. See how security teams are scaling Detection & Response.

Book a demo