Skip to content

Snippet Commands - Manage Bitbucket Snippets

Manage Bitbucket Cloud snippets, workspace-scoped code/text pastes.

Snippet commands operate at workspace scope (no repository context required). Use -w, --workspace <workspace> or set a default with bb config set defaultWorkspace <workspace>.

See Global flags for JSON output, workspace/repository selection, and display options.


List snippets in a workspace.

Terminal window
bb snippet list [options]
Option Description
--role <role> Filter by authenticated user’s role: owner, contributor, or member
--limit <number> Maximum number of snippets (default: 25)
--all List all snippets (overrides --limit)
Terminal window
bb snippet list
bb snippet list --role owner
bb snippet list --limit 50 --json
bb snippet list --all
# Project to specific fields (returns a flat array)
bb snippet list --json id,title,is_private
# Filter with built-in --jq — public snippets only
bb snippet list --json --jq '.snippets[] | select(.is_private == false) | .title'
  • Table columns: ID, TITLE, VISIBILITY, CREATOR, UPDATED.
  • JSON envelope: { workspace, count, snippets }.
  • --limit is enforced across paginated responses.
  • When the result is capped by --limit, a hint shows how many were listed; use a higher --limit or --all to see the rest (suppressed with --json).

View snippet details. Optionally print file contents.

Terminal window
bb snippet view <id> [options]
Argument Description
id Snippet encoded ID (e.g. kypj)
Option Description
-f, --file <name> Print contents of a specific file in the snippet
--files Print contents of all files in the snippet
Terminal window
bb snippet view kypj
bb snippet view kypj --json
bb snippet view kypj --file config.yml
bb snippet view kypj --files
  • --file takes precedence over --files. Pass both and only the single file is printed.
  • An unknown file name fails with File not found in snippet: <name> (5003 FILE_NOT_FOUND, see Error codes). The error context carries available with the snippet’s actual file names.
  • --files prints the snippet header first, then each file under a bold ── <name> ── heading. With the global --no-unicode the separator renders as --.
  • JSON shapes differ per flag:
    • no flag → the bare Bitbucket snippet object, no envelope
    • --file <name> → { file, content }
    • --files → { snippet, files: { "<name>": "<content>" } }

Create a snippet. The files you pass are uploaded as multipart/form-data to Bitbucket, their contents are the snippet body.

Terminal window
bb snippet create [options]
Option Description
-t, --title <title> Snippet title (required)
-f, --file <path...> File path(s) to include (required; variadic, pass several paths or repeat the flag)
--private Create a private snippet (default)
--public Create a public snippet
--dry-run Print the write request instead of sending it (details)
Terminal window
bb snippet create -t "My snippet" -f file.txt
bb snippet create -t "Config files" -f config.yml -f setup.sh --public
# Capture the new snippet id
bb snippet create -t "My snippet" -f file.txt --json --jq '.id'
  • Snippets are private by default.
  • --private and --public cannot both be set.
  • Each --file must exist on disk; missing files fail the command before any upload.
  • --json emits the bare Bitbucket snippet object, with no envelope.

Update a snippet’s title, visibility, or files.

Terminal window
bb snippet edit <id> [options]
Argument Description
id Snippet encoded ID (e.g. kypj)
Option Description
-t, --title <title> New title
--private Make snippet private
--public Make snippet public
-f, --file <path...> Replace or add file(s); sends a multipart update (variadic)
--dry-run Print the write request instead of sending it (details)
Terminal window
bb snippet edit kypj -t "New title"
bb snippet edit kypj --public
bb snippet edit kypj -f updated.txt
  • Metadata-only edits (title, visibility) send a JSON PUT.
  • Passing --file switches to a multipart PUT and uploads the given files.
  • At least one of --title, --private, --public, or --file is required.
  • --json emits the bare Bitbucket snippet object, with no envelope.

Delete a snippet.

Terminal window
bb snippet delete <id> [options]
Argument Description
id Snippet encoded ID (e.g. kypj)
Option Description
-y, --yes Skip the confirmation prompt (required when not in an interactive terminal)
--dry-run Print the write request instead of sending it (details)
Terminal window
bb snippet delete kypj --yes
  • JSON envelope: { success, snippetId, workspace }.

Subscribe or unsubscribe the authenticated user to/from a snippet.

Terminal window
bb snippet watch <id> [options]
bb snippet unwatch <id> [options]
Argument Description
id Snippet encoded ID (e.g. kypj)
Option Description
--dry-run Print the write request instead of sending it (details)
Terminal window
bb snippet watch kypj
bb snippet unwatch kypj
  • JSON envelope: { success, snippetId, watching }, watching is true for watch and false for unwatch.

See snippet comments for options and examples.

bb snippet comments add.

bb snippet comments edit.

bb snippet comments delete.

Notes.