Searching code with Sourcegraph

Search code across repositories using the Sourcegraph CLI with JSON output.

5|Updated Feb 9, 2018
One-click install
npx skills add https://github.com/markus1189/nixos-config --skill searching-code-with-sourcegraph
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Searching code with Sourcegraph
Source: https://github.com/markus1189/nixos-config/tree/main/nixos-shared/claude/skills/sourcegraph-search
Command: npx skills add https://github.com/markus1189/nixos-config --skill searching-code-with-sourcegraph

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires Sourcegraph CLI.

What problem does it solve?

This Skill eliminates the manual, time-consuming process of searching for code across vast, distributed repositories. It helps you quickly pinpoint specific implementations, understand cross-project dependencies, and identify code patterns without sifting through countless files.

Core Features & Use Cases

  • Cross-Repository Search: Search code across all your configured repositories, not just local files.
  • Pattern & API Usage Analysis: Find examples of API usage, specific functions, or complex code patterns.
  • Security Auditing: Quickly locate potential security issues like hardcoded credentials or vulnerable patterns.
  • Use Case: You need to refactor a deprecated function. Use this Skill to instantly find every instance of that function across your entire organization's codebase, saving days of manual searching.

Quick Start

Simple text search across all repos

src search 'PATTERN'

Search for a Go function in a specific repository

src search 'repo:github.com/org/repo$ lang:go func handleRequest'

Find all TODOs, excluding test files

src search 'TODO -file:test'

Frequently Asked Questions about Searching code with Sourcegraph

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I search for code across multiple repositories at once?

Cross-repository code search queries all your configured repositories using the Sourcegraph CLI. Run `src search 'PATTERN'` to find code across all repos, or use filters like `repo:`, `lang:`, and `file:` to narrow results by repository, language, or filename. The Sourcegraph CLI returns matches instantly without manual file-by-file inspection.

Can I find all uses of a deprecated function across my organization's codebase?

Yes. Use Sourcegraph CLI pattern matching to locate every instance of a function across all repositories. For example, `src search 'func handleRequest'` with language and repository filters finds all occurrences, supporting refactoring efforts and dependency tracking at organizational scale.

What pattern types does Sourcegraph support for code searches?

Sourcegraph CLI supports literal text matching, regular expressions, and structural patterns. Each pattern type lets you search differently: literal for exact strings, regexp for flexible matching, and structural for code-aware patterns. You can combine patterns with filters for precise queries.

How do I find hardcoded credentials or security vulnerabilities in code?

Use Sourcegraph CLI searches with pattern matching and filters to locate potential security issues across repositories. Search for patterns like hardcoded API keys, credentials, or known vulnerable functions using queries like `src search 'password.*=' -file:test`. JSON output enables programmatic analysis of results.

Can I get search results in a machine-readable format?

Yes. The Sourcegraph CLI `-json` flag outputs search results as JSON, enabling programmatic parsing, integration with other tools, and batch processing of findings across multiple repositories.

Do I need the Sourcegraph CLI installed to use this Skill?

Yes. The Sourcegraph CLI (src) is a required dependency. It must be installed and configured with access to your repositories before running code searches through this Skill.