Skip to content

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>.


Search code in a workspace.

Terminal window
bb search code <query...> [options]
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:
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.

Terminal window
bb search code parseConfig
bb search code parseConfig -r my-repo
bb search code TODO lang:typescript -w my-workspace --limit 50
# Paths of every matching file
bb search code parseConfig --json --jq '.results[].file.path'
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>.

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 PATH and MATCH values are shortened to fit the terminal width. Pass the global --no-truncate for the full line; --json always carries everything.
  • A malformed query fails with Bitbucket’s 400 error message.