csd is a fast, safe, interactive regex search-and-replace CLI tool for codebases. It has zero external dependencies beyond Go's standard library.
go install github.com/chmouel/csd@latestOr build from source:
make buildcsd [OPTIONS] [FILE_PATTERN] SEARCH_PATTERN REPLACEMENT
With three arguments, the first is a regular expression matched against file paths (FILE_PATTERN). With two arguments, all files in the directory tree are searched.
When standard input is piped with two arguments, csd processes the file list provided via stdin (one file path per line).
# Replace "foo" with "bar" in all files
csd 'foo' 'bar'
# Replace only in .txt files
csd '\.txt$' 'foo' 'bar'
# Replace in a piped list of files
find . -name '*.go' | csd 'old_func' 'new_func'
# Preview changes without modifying files
csd --dry-run 'foo' 'bar'
# Interactively prompt for each change with a colored diff
csd -i 'foo' 'bar'
# Use capture groups ($1 or \1 syntax)
csd '(\w+) (\w+)' '$2 $1'
csd '(\w+) (\w+)' '\2 \1'| Flag | Short | Description |
|---|---|---|
--interactive |
-i |
Prompt for confirmation before applying each change |
--quiet |
-q |
Suppress normal output messages |
--no-ignore |
-I |
Do not respect .gitignore or .ignore files |
--include-git-dir |
Include files inside .git directory |
|
--dry-run |
Show modified files without writing changes | |
--version |
Display version information |
Generate and source a completion script for the current shell:
# Bash
source <(csd --completion bash)
# Zsh
source <(csd --completion zsh)Use -c as a short alias for --completion. Add the applicable command to
your shell startup file to enable completion in new sessions.
- Atomic Writes: Preserves original permissions and guarantees safe file modifications via temporary file swap.
- Ignore Aware: Respects
.gitignoreand.ignorefiles by default. - Binary File Detection: Automatically skips binary files containing NUL bytes.
- Zero Dependencies: Built purely with Go standard library (
regexp,path/filepath,os, etc.).
make check # gofmt, golangci-lint, and go test
make build # build bin/csdgolangci-lint (see .golangci.yml) is required for make check/make lint; install it from https://golangci-lint.run/welcome/install/. pre-commit install wires the same checks into your local git hooks.