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.
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:, andcontent:, each of which can be negated.[4] - Commit and diff search
type:commitsearches commit messages andtype:diffsearches changes. Both acceptauthor:,committer:,message:,before:, andafter: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 withrev: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, andfromAccessTokenIDwhen a token was used.[8]
Detections, hunts, and triage
Example query
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]
| Permission | Access | Why |
|---|---|---|
| Service Account system roleAssigned automatically to every service account and provides basic API access.[6] | Read | Assigned automatically to every service account and provides basic API access.[6] |
| Repository permissionsService accounts see only public and unrestricted repositories by default, so grant the private repositories to search.[6] | Read | Service accounts see only public and unrestricted repositories by default, so grant the private repositories to search.[6] |
user:allThe default token scope, enough for most uses of the GraphQL API.[7] | Read | The default token scope, enough for most uses of the GraphQL API.[7] |
site-admin:sudoLeave unselected. Sourcegraph reserves it for impersonating other users.[7] | Write | Leave unselected. Sourcegraph reserves it for impersonating other users.[7] |
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
- Changelog (Cotool docs) · accessed November 22, 2026
- Respond to every signal (Cotool Respond) · accessed November 22, 2026
- Threat hunting (Cotool Hunt) · accessed November 22, 2026
- Search query syntax (Sourcegraph docs) · accessed November 22, 2026
- Sourcegraph GraphQL API (Sourcegraph docs) · accessed November 22, 2026
- Service accounts (Sourcegraph docs) · accessed November 22, 2026
- Creating an access token (Sourcegraph docs) · accessed November 22, 2026
- Audit log (Sourcegraph docs) · accessed November 22, 2026

