Directory Compare FCRS-1.0 /llms.txt
← Back to Directory

Sourcegraph CLI

$ src Official Med Risk
Sourcegraph · Files & Search · Apache-2.0 · macos / linux / windows

Official Sourcegraph CLI (src) enables cross-repository code search with -json output, raw GraphQL queries via src api, and large-scale Batch Changes automation. Headless agents authenticate cleanly via SRC_ENDPOINT and SRC_ACCESS_TOKEN.

FCRS-1.0 Score
85 /100
Good
Medium Confidence
Zero-Friction Install
brew install sourcegraph/src-cli-v2/src-cli
CLI vs MCP Decision CLI Preferred vs MCP

src search -json and src api cover global code search and GraphQL queries without standing up an MCP server, while src batch preview validates multi-repo changesets.

Agent-Readiness Checklist

✓ JSON Output
— Field Filtering
✓ Non-Interactive
✓ Dry-Run
— Read-Only Mode
— NO_COLOR Clean
✓ Self-Describing
— Official SKILL.md

Static evaluation (not yet probed on this host). Run npm run data:probe locally to capture live verification.

FCRS-1.0 6-Dimension Breakdown

Agent-Readiness 22 / 25

Supports src search -json, src api JSON output, SRC_ACCESS_TOKEN headless auth, and src batch preview.

  • src search -json and src api emit machine-parseable JSON
  • SRC_ENDPOINT + SRC_ACCESS_TOKEN env vars avoid interactive login
Trust & Safety 20 / 25

Token-based auth and src batch preview dry-run checks are strong, though src batch apply opens remote PRs and --get-curl leaks tokens to stdout.

  • src batch preview validates changesets before remote PR creation
  • --get-curl prints raw Authorization headers
Setup & Portability 13 / 15

Single static Go binary available via custom Homebrew tap sourcegraph/src-cli-v2/src-cli, go install, and GitHub releases.

  • Cross-platform Go binary for macOS, Linux, and Windows
Utility & Efficiency 13 / 15

Searches across hundreds of remote repositories in one call and automates cross-repo Batch Changes.

  • Combines search, GraphQL src api, and Batch Changes
Maintenance & Lineage 9 / 10

Official first-party CLI maintained by Sourcegraph (sourcegraph/src-cli) under Apache-2.0.

  • Official Sourcegraph repository under Apache-2.0
Docs & Verifiability 8 / 10

Official CLI reference docs at sourcegraph.com/docs/cli and per-subcommand -h help.

  • Structured reference documentation online and via -h

Security, Auth & Guardrails

Auth Modes
Env API Key OAuth Browser Config File
Credential Storage

Reads SRC_ENDPOINT and SRC_ACCESS_TOKEN env vars, or stores credentials from src login in ~/.config/sourcegraph (or OS keychain).

Side Effects
Read-Only Remote Write
Cost & Quotas

CLI is Apache-2.0 open-source; connecting to private Sourcegraph instances requires an account/license.

Copyable Guardrail for CLAUDE.md / AGENTS.md
# Sourcegraph CLI (src) Agent Rules
- Authenticate via `SRC_ENDPOINT` + `SRC_ACCESS_TOKEN` and always pass `-json` on `src search`.
- Run `src batch preview -f <spec>` before `src batch apply`; never pass `--get-curl` in shared logs (it prints raw tokens).

Agent-Ready Command Recipes

Safe Read-Only Queries

Run cross-repo code search as JSON
src search -json 'repo:^github.com/my-org/ lang:go context.Background'

Queries a Sourcegraph instance and outputs structured JSON match payloads.

Query Sourcegraph GraphQL API
src api -query='query { currentUser { username } }'

Executes a read-only GraphQL query returning JSON for scripting or auth verification.

Controlled Writes & Previews

Preview a Batch Changes spec without applying
src batch preview -f batch.yaml

Validates and previews multi-repo changesets on Sourcegraph without opening pull requests.

Strengths for Agents

  • + src search -json and src api provide clean JSON across all indexed remote repositories.
  • + src batch preview enables safe validation before executing multi-repo changesets.

Caveats & Pitfalls

  • ! src search uses single-dash -json rather than --json.
  • ! Debug flag --get-curl prints the raw SRC_ACCESS_TOKEN to stdout.

Tested Agent Hosts

Claude Code Codex CLI Gemini CLI