Skip to main content
Code Insights turns your codebase into a time-series data source. Any pattern you can express as a Sourcegraph search query can become a chart that shows how that pattern has changed over days, weeks, months, or years. Sourcegraph backfills historical data from your version control history, so you get trend lines immediately on creation — no waiting for data to accumulate.
Code Insights is available on Enterprise plans.

What you can track

Anything searchable in Sourcegraph is trackable in Code Insights:
  • The number of files still using a deprecated API
  • How many repositories have migrated to a new framework version
  • The count of open TODO comments across your codebase
  • Which language makes up what percentage of your repositories
  • Whether a known vulnerable dependency version still exists anywhere
Code Insights operates at the repository level, running across thousands of repositories. Results are precise because they are built on the same engine as Code Search.

Insight types

Track the count of any pattern expressed as a Sourcegraph search query. Each data series corresponds to one search query, and multiple series can be overlaid on a single chart.Example uses:
  • Count of TODO comments over time
  • Adoption rate of a new logging library (number of files importing it)
  • Number of repositories still calling a deprecated function
Search-based insights backfill up to a configurable number of historical data points from your Git history.

Creating your first insight

This walkthrough creates a search-based insight that tracks the number of TODO comments in your codebase over the past year.
1

Navigate to Insights

Open your Sourcegraph instance and click Insights in the main navigation bar. If you do not see this item, ask your site administrator to enable Code Insights.
2

Create a new insight

Click + Create insight on the Insights page.
3

Select insight type

On the insight type selection page, choose Track changes. This creates a search-based insight where you define one or more search queries to track over time.Choose Detect and track instead if you want to automatically generate separate series for each distinct captured value (for example, each version of a dependency).
4

Select repositories

Choose which repositories to include:
  • Enter specific repository URLs (e.g., github.com/myorg/myrepo) separated by commas, or
  • Check Run over all repositories to track the pattern across your entire Sourcegraph instance
You can also define the scope using a Sourcegraph search query for more flexible filtering.
5

Define a data series

A data series becomes a line on the chart.
  • Name: Enter a descriptive label such as TODO count
  • Search query: Enter the search expression to count — for this example, TODO
  • Color: Choose a line color for the chart
Add additional data series to compare multiple trends on the same chart.
6

Configure the chart

  • Title: Enter a descriptive chart title, such as TODO comments in myrepo
  • Data point interval: Choose the time between data points (e.g., 1 month). Sourcegraph provides 12 data points per series, so monthly intervals show one year of history.
7

Create and view the insight

Click Create code insight. You are taken to the Insights dashboard where your new chart appears immediately, with historical data already populated from your Git history.
8

Filter and explore

Click the filter icon on any insight card to open the filters panel. Use regular expressions to include or exclude specific repositories. This lets you drill down into a subset of your codebase without creating a separate insight.

Use cases

Migration tracking

Track the progress of a large-scale migration — for example, from one framework to another — by charting the number of files still using the old pattern alongside the number using the new one.

Vulnerability remediation

After a CVE disclosure, create an insight to track how many repositories still contain a vulnerable version. Watch the count drop as teams apply patches.

Dependency version adoption

Use detect-and-track to chart which versions of a key dependency are in use across your organization. Identify which teams are behind and by how much.

Code health over time

Track proxy metrics for code health: TODO count, FIXME count, or the number of files exceeding a line length threshold. Use these as a signal for technical debt accumulation.

Test coverage growth

Count the number of test files or test functions over time to verify that testing practices are improving alongside feature development.

API surface area

Track how many public API endpoints exist across your services to understand whether the surface area is growing or being consolidated.

Dashboards

Insights are organized into dashboards. You can create multiple dashboards to group related insights — for example, a dashboard for security metrics, a dashboard for a specific team’s migration work, or a dashboard for platform health. Each dashboard has configurable visibility: private to you, shared with your organization, or visible to your entire Sourcegraph instance. From the Insights home page, click + Create dashboard to create a new dashboard and then add insights to it. Insights can appear on multiple dashboards simultaneously.

Frequently asked questions

Sourcegraph backfills 12 data points at the configured interval. At a monthly interval, this gives you one year of history. At a weekly interval, about three months. The backfill reads from your Git history, so data is available immediately without waiting for new commits.
Yes. When you enable Run over all repositories, the insight runs against every repository indexed in your Sourcegraph instance. For very large instances (thousands of repositories), there may be a short delay for initial backfill.
Track changes requires you to define each data series manually with a specific search query. Detect and track uses a capture group in a single query to automatically generate one series per distinct captured value — useful for tracking all versions of a dependency without manually creating a series for each version.
Yes. Insight data is accessible via the Sourcegraph API, and you can download chart data in CSV format from the insight card menu. This lets you import metrics into external dashboards or spreadsheets.
Yes. Each user sees only data from repositories they have access to. If you share a dashboard with another user, they see the insight filtered to their accessible repositories, which may differ from what you see.

Code Search

Write and test the search queries that power your insights before creating the chart.

Batch Changes

Use Batch Changes to act on the patterns surfaced by Code Insights — for example, automatically opening PRs to fix the issues you are tracking.

Deep Search

Ask questions about the patterns Code Insights reveals — for example, “Why are there so many TODOs in this module?”

Admin overview

Configure Code Insights for your Sourcegraph instance and manage access controls.

Build docs developers (and LLMs) love