Search Commands - Search Code in Bitbucket
Search the code in a workspace with Bitbucket’s code search, using the same query syntax as the web UI.
bb search code is non-interactive and accepts the
global flags, including --json [fields] and
--jq <expression>.
bb search code
Section titled “bb search code”Search code in a workspace.
bb search code <query...> [options]Arguments
Section titled “Arguments”| Argument | Description |
|---|---|
query |
Search query. Multiple words are joined with spaces and searched as separate terms; for an exact phrase, keep the double quotes in the query ('"def main"'). Supports Bitbucket’s search modifiers such as lang:, ext:, path: and repo: |
Options
Section titled “Options”| Option | Description |
|---|---|
-r, --repo <repo> |
Only search this repository by adding repo:<repo> to the query |
--limit <number> |
Maximum number of results (default: 25) |
--all |
List all results (overrides --limit) |
The workspace comes from -w/--workspace, then the current repository’s
Bitbucket remote, then BB_WORKSPACE, then defaultWorkspace. The search
covers the whole workspace unless you pass --repo, even inside a checkout.
Examples
Section titled “Examples”bb search code parseConfigbb search code parseConfig -r my-repobb search code TODO lang:typescript -w my-workspace --limit 50
# Paths of every matching filebb search code parseConfig --json --jq '.results[].file.path'Output
Section titled “Output”REPOSITORY PATH LINE MATCH---------- ------------------- ---- --------------------------------------------------acme/api src/config/parse.ts 12 export function parseConfig(raw: string): Config {acme/web src/lib/settings.ts 4 import { parseConfig } from '@acme/api';LINE and MATCH show the first matching line of each file. They are empty
when only the file path matched. A search with no hits prints
No code matches for "<query>" in workspace <workspace>.
JSON output
Section titled “JSON output”The envelope is { workspace, query, count, results }. query is the query
as sent, including the repo: scope --repo adds. Each item in results is
Bitbucket’s code search result: content_matches (lines split into
segments, where matched text has match: true), path_matches, and file,
with the repository under file.commit.repository.
- Long
PATHandMATCHvalues are shortened to fit the terminal width. Pass the global--no-truncatefor the full line;--jsonalways carries everything. - A malformed query fails with Bitbucket’s
400error message.
Related
Section titled “Related”- Bitbucket search syntax
- Repository Context: how the CLI resolves the workspace.