百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

src-cli

> 后端框架
开源

Sourcegraph CLI

346 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

Sourcegraph CLI

Sourcegraph CLI

src is a command line interface to Sourcegraph:

  • Search & get results in your terminal
  • Search & get JSON for programmatic consumption
  • Make GraphQL API requests with auth easily & get JSON back fast
  • Execute batch changes
  • Manage & administrate repositories, users, and more
  • Easily convert src-CLI commands to equivalent curl commands, just add --get-curl!

Note: Using Sourcegraph 3.12 or earlier? See the older README.

Installation

Binary downloads are available on the releases tab, and through Sourcegraph.com. If the latest version does not work for you, consider using the version compatible with your Sourcegraph instance instead.

Installation: Mac OS

Latest version

bash
curl -L https://sourcegraph.com/.api/src-cli/src_darwin_amd64 -o /usr/local/bin/src
chmod +x /usr/local/bin/src

or with Homebrew:

bash
brew install sourcegraph/src-cli/src-cli

or with npm:

bash
npm install -g @sourcegraph/src

Version compatible with your Sourcegraph instance

Replace sourcegraph.example.com with your Sourcegraph instance URL:

bash
curl -L https://sourcegraph.example.com/.api/src-cli/src_darwin_amd64 -o /usr/local/bin/src
chmod +x /usr/local/bin/src

or, if you know the specific version to target, for example 3.43.2:

bash
brew install sourcegraph/src-cli/[email protected]

or with npm/npx:

bash
npx @sourcegraph/[email protected] version

Note: Versioned formulas are available on Homebrew for Sourcegraph versions 3.43.2 and later.

Installation: Linux

Latest version

bash
curl -L https://sourcegraph.com/.api/src-cli/src_linux_amd64 -o /usr/local/bin/src
chmod +x /usr/local/bin/src

or with npm:

bash
npm install -g @sourcegraph/src

Version compatible with your Sourcegraph instance

Replace sourcegraph.example.com with your Sourcegraph instance URL:

bash
curl -L https://sourcegraph.example.com/.api/src-cli/src_linux_amd64 -o /usr/local/bin/src
chmod +x /usr/local/bin/src

or, with npm/npx, if you know the specific version to target, for example 3.43.2:

bash
npx @sourcegraph/[email protected] version

Installation: Windows

See Sourcegraph CLI for Windows.

Installation: Docker

sourcegraph/src-cli is published to Docker Hub. You can use the latest tag or a specific version such as 3.43. To see all versions view sourcegraph/src-cli tags.

bash
docker run --rm=true sourcegraph/src-cli:latest search 'hello world'

Connect to your Sourcegraph instance

src needs the URL of your Sourcegraph instance. Set SRC_ENDPOINT in your shell environment, replacing https://sourcegraph.example.com with your instance URL:

bash
export SRC_ENDPOINT=https://sourcegraph.example.com

For PowerShell on Windows:

powershell
$env:SRC_ENDPOINT = 'https://sourcegraph.example.com'

For convenience, add this environment variable to your terminal profile or system environment variables. On Mac OS and Linux, the terminal profile is typically ~/.bash_profile for Bash or ~/.zprofile for Zsh. On Windows, you can add it through the System Properties window. See these instructions for details.

If SRC_ENDPOINT is not set, src defaults to https://sourcegraph.com.

OAuth login

Run src login to authenticate interactively with OAuth:

bash
src login

OAuth does not require you to create or export SRC_ACCESS_TOKEN. The OAuth credential is stored in your operating system's native keyring. Keep SRC_ENDPOINT set when running subsequent commands because src uses the endpoint to load the matching OAuth credential.

You can also pass the instance URL directly to src login, but this only selects the endpoint for that login command. You must still set SRC_ENDPOINT when running subsequent commands:

bash
src login https://sourcegraph.example.com

To use the active credential in another command, src auth token prints the raw token and src auth token --header prints a complete Authorization header for the active authentication mode.

Personal access token login

For non-interactive authentication, such as in CI or scripts, create an access token on your Sourcegraph instance under Settings > Access tokens, then set both SRC_ENDPOINT and SRC_ACCESS_TOKEN:

bash
export SRC_ENDPOINT=https://sourcegraph.example.com
export SRC_ACCESS_TOKEN=my-token

For PowerShell on Windows:

powershell
$env:SRC_ENDPOINT = 'https://sourcegraph.example.com'
$env:SRC_ACCESS_TOKEN = 'my-token'

When SRC_ACCESS_TOKEN is set, src uses it instead of an OAuth credential and running src login is not necessary. You can also set both variables for a single command:

bash
SRC_ENDPOINT=https://sourcegraph.example.com SRC_ACCESS_TOKEN=my-token src search 'foo'

Is your Sourcegraph instance behind a custom auth proxy? See auth proxy configuration docs.

Usage

src provides different subcommands to interact with different parts of Sourcegraph:

  • src login - authenticate to a Sourcegraph instance with your user credentials
  • src auth - print the active authentication token or authorization header
  • src search - perform searches and get results in your terminal or as JSON
  • src api - run Sourcegraph GraphQL API requests
  • src batch - execute and manage batch changes
  • src repos - manage repositories
  • src users - manage users
  • src orgs - manages organization
  • src config - manage global, org, and user settings
  • src extsvc - manage external services (repository configuration)
  • src extensions - manage extensions
  • src code-intel - manages Code Intelligence data
  • src serve-git - serves your local git repositories over HTTP for Sourcegraph to pull
  • src version - check version and guaranteed-compatible version for your Sourcegraph instance

Run src -h and src -h for more detailed usage information. You can also read the usage docs for the latest version of src-cli online.

Optional: Renaming src

If you have a naming conflict with the src command, such as a Bash alias, you can rename the static binary. For example, on Linux / Mac OS:

bash
mv /usr/local/bin/src /usr/local/bin/src-cli

You can then invoke it via src-cli.

Timeouts

src waits up to 1 minute for the server to start responding to a request. To change this, set the SRC_RESPONSE_HEADER_TIMEOUT environment variable to a duration such as 30s or 10m, or to 0 to disable the timeout. This timeout only applies until the server sends its response headers — responses that stream data for a long time, such as large search job results, are not interrupted.

Telemetry

src includes the operating system and architecture in the User-Agent header sent to Sourcegraph. For example, running src version 3.21.10 on an x86-64 Linux host will result in this header:

src-cli/3.21.10 linux amd64

To disable this and only send the version, you can set -user-agent-telemetry=false for a single command, or set the SRC_DISABLE_USER_AGENT_TELEMETRY environment variable to any non-blank string.

As with other Sourcegraph telemetry, any collected data is only sent to Sourcegraph.com in aggregate form.

Development

Some useful notes on developing src can be found in DEVELOPMENT.md.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Goapicligraphqlrepo-type-cli

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架