---
title: "Code search"
description: "File matches by query, global or scoped to an owner or a repository, on the platforms that have an endpoint for it."
canonical_url: "https://forges.agntn.dev/guide/code-search"
---
# Code search

> File matches by query, global or scoped to an owner or a repository, on the platforms that have an endpoint for it.

## Call

```ts
const result = await forge.code.search("defineNuxtConfig", {
  owner: "nitrojs",
  repo: "nitro",
  perPage: 20,
});

for (const item of result.items) {
  console.log(item.repository, item.path, item.url);
}
console.log(result.incomplete);
```

`CodeSearchOptions` is `cursor`, `perPage` and an optional `owner` and `repo` scope. A `repo` without an `owner` is a 400 before any request. The result is a `SearchPageResult<CodeSearchItem>` with `repository`, `path` and `url` per row.

## Per platform

<table>
<thead>
  <tr>
    <th>
      Platform
    </th>
    
    <th>
      Scope
    </th>
    
    <th>
      Fine print
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      GitHub
    </td>
    
    <td>
      global, owner, repository
    </td>
    
    <td>
      a token raises the rate limit; <code>
        incomplete
      </code>
      
       is true on a timeout, a dropped row or past the cap of 1 000 results
    </td>
  </tr>
  
  <tr>
    <td>
      GitLab
    </td>
    
    <td>
      global, group (owner), project (repository)
    </td>
    
    <td>
      every search call needs a token; global and group code search also need Premium or Ultimate with advanced or exact code search on
    </td>
  </tr>
  
  <tr>
    <td>
      Gitea, Forgejo
    </td>
    
    <td>
      none
    </td>
    
    <td>
      explicit <code>
        ForgesError
      </code>
      
       with status 501
    </td>
  </tr>
  
  <tr>
    <td>
      GitHub API hosts without the endpoint
    </td>
    
    <td>
      none
    </td>
    
    <td>
      explicit <code>
        ForgesError
      </code>
      
       with status 501
    </td>
  </tr>
</tbody>
</table>

On GitHub the scope is checked on the rows too, not just in the query. A row from outside the requested owner or repository is dropped and `incomplete` goes true, instead of a stray match from somewhere else quietly landing in your list.

## In an agent

`forges_code_search` takes the same arguments. Like every read tool it falls back to anonymous access when there is no credential, which on GitLab means a clear message about the token rather than a bare 401.


## Sitemap

See the full [sitemap](https://forges.agntn.dev/sitemap.md) for all pages.
