Skip to content

CLI Configuration

Configure the CLI to connect to your Code Search server.

Terminal window
# Initialize configuration file
code-search config init
# Set the API URL
code-search config set api_url http://localhost:8080
# Verify configuration
code-search config show

The CLI reads configuration from ~/.code-search.yaml:

~/.code-search.yaml
api_url: http://localhost:8080
output: text
search:
limit: 100
context_lines: 2
replace:
dry_run: true
parallel: 5
Terminal window
# Create config in home directory
code-search config init
# Create config in current directory
code-search config init --local
# Overwrite existing config
code-search config init --force
Terminal window
# Show all configuration values
code-search config show

Example output:

Current configuration:
Config file: /Users/user/.code-search.yaml
api_url: http://localhost:8080
output: text
search.limit: 100
search.context_lines: 2
replace.dry_run: true
replace.parallel: 5
Terminal window
# Set API URL
code-search config set api_url https://code-search.example.com
# Set default output format
code-search config set output json
# Set search defaults
code-search config set search.limit 50
code-search config set search.context_lines 5

The CLI respects these environment variables (with CODE_SEARCH_ prefix):

VariableDescriptionConfig Key
CODE_SEARCH_API_URLAPI server URLapi_url
CODE_SEARCH_TOKENAuthentication tokentoken
CODE_SEARCH_OUTPUTDefault output formatoutput
CODE_SEARCH_CONFIGPath to config file-

Environment variables take precedence over config file values.

These flags can be used with any command to override configuration:

FlagDescription
--configPath to config file
--api-urlAPI server URL (default: localhost:8080)
--outputOutput format: text, json, table

URL of the Code Search API server.

api_url: https://code-search.example.com

Default: http://localhost:8080

Authentication token for API requests.

token: ${CODE_SEARCH_TOKEN}

Default output format for commands.

ValueDescription
textPlain text output (default)
jsonJSON output
tableFormatted table output
output: text
search:
limit: 100 # Default result limit
context_lines: 2 # Lines of context around matches
replace:
dry_run: true # Preview by default
parallel: 5 # Number of parallel workers

The CLI searches for configuration in this order:

  1. --config flag (highest priority)
  2. $CODE_SEARCH_CONFIG environment variable
  3. .code-search.yaml (current directory)
  4. ~/.code-search.yaml (home directory)
  1. Use environment variables for tokens

    Terminal window
    export CODE_SEARCH_TOKEN="your-token"
  2. Protect the config file

    Terminal window
    chmod 600 ~/.code-search.yaml
  3. Don’t commit config files Add to .gitignore:

    .code-search.yaml

For CI/CD environments, use environment variables:

# GitHub Actions
- name: Search code
env:
CODE_SEARCH_API_URL: ${{ secrets.CODE_SEARCH_URL }}
CODE_SEARCH_TOKEN: ${{ secrets.CODE_SEARCH_TOKEN }}
run: |
code-search search "TODO"