Skip to content

CLI Replace

The code-search replace command enables bulk search and replace operations across multiple repositories with automatic merge/pull request creation.

The replace command uses a two-phase flow:

  1. Preview Phase: Searches for matches and displays what will be changed
  2. Execute Phase: Uses the matches from preview to perform replacements and create MRs

This design ensures:

  • You always see what will change before committing
  • The execute phase is fast since it doesn’t need to re-search
  • Exact consistency between preview and execution
  • All changes go through merge request review
Terminal window
# Preview changes (default mode)
code-search replace "oldFunction" "newFunction"
# Execute changes (creates MR)
code-search replace "oldFunction" "newFunction" --execute
# With custom branch and MR title
code-search replace "oldFunction" "newFunction" --execute \
--branch "refactor/rename-function" \
--mr-title "Rename oldFunction to newFunction"
Terminal window
code-search replace <old> <new> [flags]
OptionShortDescription
--preview-pPreview changes without applying (default: true)
--executeExecute the replacements (creates MR)
OptionShortDescription
--repos-RFilter to specific repositories (comma-separated)
--files-fFilter by file patterns (comma-separated)
--case-sensitiveEnable case-sensitive matching
OptionShortDescription
--regex-rTreat search pattern as regex
OptionShortDescription
--branch-bBranch name for changes
--mr-titleMR/PR title
--mr-descriptionMR/PR description
OptionShortDescription
--tokensPer-connection tokens for push access (see below)
Terminal window
# Preview renaming a function
code-search replace "getUserById" "findUserById" --repos myorg/api
# Execute the rename (creates MR)
code-search replace "getUserById" "findUserById" --repos myorg/api --execute
Terminal window
# Update version numbers
code-search replace 'v(\d+)\.(\d+)\.(\d+)' 'v$1.$2.999' --regex
# Rename function with pattern
code-search replace 'get(\w+)ById' 'find$1ById' --regex
Terminal window
code-search replace "v1.0.0" "v2.0.0" \
--repos "myorg/api" \
--files "version.go" \
--execute \
--branch "release/v2.0.0" \
--mr-title "Bump version to v2.0.0"
Terminal window
code-search replace "1.2.3" "1.3.0" \
--files "package.json" \
--repos "myorg/api" \
--execute
Terminal window
code-search replace '"lodash": "4.17.20"' '"lodash": "4.17.21"' \
--files "package.json" \
--repos "myorg/frontend" \
--execute
Terminal window
code-search replace "api/v1" "api/v2" \
--repos "myorg/backend" \
--execute \
--branch "api-v2-migration"

When you execute a replace with --execute, the operation is queued as a background job. The CLI sends the matches from the preview to the server, so the job doesn’t need to re-search.

┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ CLI Preview │────▶│ Show Matches│────▶│ Confirm (y) │────▶│ Queue Job │
└─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘
┌─────────────┐
│ Worker runs │
│ creates MR │
└─────────────┘
Terminal window
# The execute command returns a job ID
code-search replace "old" "new" --execute
# Preview:
# myorg/repo/file.go:10: oldValue
# myorg/repo/file.go:25: oldValue
#
# Found 2 matches. Execute replacement (MR will be created)? [y/N]: y
# ✅ Replace job queued
# Job ID: abc123
# Status: pending