CLI Replace
The code-search replace command enables bulk search and replace operations across multiple repositories with automatic merge/pull request creation.
How It Works
Section titled “How It Works”The replace command uses a two-phase flow:
- Preview Phase: Searches for matches and displays what will be changed
- 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
Basic Usage
Section titled “Basic Usage”# Preview changes (default mode)code-search replace "oldFunction" "newFunction"
# Execute changes (creates MR)code-search replace "oldFunction" "newFunction" --execute
# With custom branch and MR titlecode-search replace "oldFunction" "newFunction" --execute \ --branch "refactor/rename-function" \ --mr-title "Rename oldFunction to newFunction"Command Syntax
Section titled “Command Syntax”code-search replace <old> <new> [flags]Command Options
Section titled “Command Options”Execution Control
Section titled “Execution Control”| Option | Short | Description |
|---|---|---|
--preview | -p | Preview changes without applying (default: true) |
--execute | Execute the replacements (creates MR) |
Filters
Section titled “Filters”| Option | Short | Description |
|---|---|---|
--repos | -R | Filter to specific repositories (comma-separated) |
--files | -f | Filter by file patterns (comma-separated) |
--case-sensitive | Enable case-sensitive matching |
Pattern Options
Section titled “Pattern Options”| Option | Short | Description |
|---|---|---|
--regex | -r | Treat search pattern as regex |
MR/PR Options
Section titled “MR/PR Options”| Option | Short | Description |
|---|---|---|
--branch | -b | Branch name for changes |
--mr-title | MR/PR title | |
--mr-description | MR/PR description |
Authentication
Section titled “Authentication”| Option | Short | Description |
|---|---|---|
--tokens | Per-connection tokens for push access (see below) |
Examples
Section titled “Examples”Simple Replace
Section titled “Simple Replace”# Preview renaming a functioncode-search replace "getUserById" "findUserById" --repos myorg/api
# Execute the rename (creates MR)code-search replace "getUserById" "findUserById" --repos myorg/api --executeRegex Replace
Section titled “Regex Replace”# Update version numberscode-search replace 'v(\d+)\.(\d+)\.(\d+)' 'v$1.$2.999' --regex
# Rename function with patterncode-search replace 'get(\w+)ById' 'find$1ById' --regexWith Custom MR Options
Section titled “With Custom MR Options”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"Common Use Cases
Section titled “Common Use Cases”Version Bumps
Section titled “Version Bumps”code-search replace "1.2.3" "1.3.0" \ --files "package.json" \ --repos "myorg/api" \ --executeDependency Updates
Section titled “Dependency Updates”code-search replace '"lodash": "4.17.20"' '"lodash": "4.17.21"' \ --files "package.json" \ --repos "myorg/frontend" \ --executeAPI Migration
Section titled “API Migration”code-search replace "api/v1" "api/v2" \ --repos "myorg/backend" \ --execute \ --branch "api-v2-migration"Replace Jobs
Section titled “Replace Jobs”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.
Job Flow
Section titled “Job Flow”┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐│ CLI Preview │────▶│ Show Matches│────▶│ Confirm (y) │────▶│ Queue Job │└─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘ │ ▼ ┌─────────────┐ │ Worker runs │ │ creates MR │ └─────────────┘# The execute command returns a job IDcode-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: pendingNext Steps
Section titled “Next Steps”- Find Commands - Find files and symbols
- Repository Management - Manage repos via CLI