CLI Configuration
Configure the CLI to connect to your Code Search server.
Quick Setup
Section titled “Quick Setup”# Initialize configuration filecode-search config init
# Set the API URLcode-search config set api_url http://localhost:8080
# Verify configurationcode-search config showConfiguration File
Section titled “Configuration File”The CLI reads configuration from ~/.code-search.yaml:
api_url: http://localhost:8080output: text
search: limit: 100 context_lines: 2
replace: dry_run: true parallel: 5Configuration Commands
Section titled “Configuration Commands”Initialize Configuration
Section titled “Initialize Configuration”# Create config in home directorycode-search config init
# Create config in current directorycode-search config init --local
# Overwrite existing configcode-search config init --forceView Configuration
Section titled “View Configuration”# Show all configuration valuescode-search config showExample output:
Current configuration:Config file: /Users/user/.code-search.yamlapi_url: http://localhost:8080output: textsearch.limit: 100search.context_lines: 2replace.dry_run: truereplace.parallel: 5Set Configuration
Section titled “Set Configuration”# Set API URLcode-search config set api_url https://code-search.example.com
# Set default output formatcode-search config set output json
# Set search defaultscode-search config set search.limit 50code-search config set search.context_lines 5Environment Variables
Section titled “Environment Variables”The CLI respects these environment variables (with CODE_SEARCH_ prefix):
| Variable | Description | Config Key |
|---|---|---|
CODE_SEARCH_API_URL | API server URL | api_url |
CODE_SEARCH_TOKEN | Authentication token | token |
CODE_SEARCH_OUTPUT | Default output format | output |
CODE_SEARCH_CONFIG | Path to config file | - |
Environment variables take precedence over config file values.
Global Command Flags
Section titled “Global Command Flags”These flags can be used with any command to override configuration:
| Flag | Description |
|---|---|
--config | Path to config file |
--api-url | API server URL (default: localhost:8080) |
--output | Output format: text, json, table |
Configuration Reference
Section titled “Configuration Reference”api_url
Section titled “api_url”URL of the Code Search API server.
api_url: https://code-search.example.comDefault: http://localhost:8080
Authentication token for API requests.
token: ${CODE_SEARCH_TOKEN}output
Section titled “output”Default output format for commands.
| Value | Description |
|---|---|
text | Plain text output (default) |
json | JSON output |
table | Formatted table output |
output: textsearch Settings
Section titled “search Settings”search: limit: 100 # Default result limit context_lines: 2 # Lines of context around matchesreplace Settings
Section titled “replace Settings”replace: dry_run: true # Preview by default parallel: 5 # Number of parallel workersConfiguration Locations
Section titled “Configuration Locations”The CLI searches for configuration in this order:
--configflag (highest priority)$CODE_SEARCH_CONFIGenvironment variable.code-search.yaml(current directory)~/.code-search.yaml(home directory)
Security Best Practices
Section titled “Security Best Practices”-
Use environment variables for tokens
Terminal window export CODE_SEARCH_TOKEN="your-token" -
Protect the config file
Terminal window chmod 600 ~/.code-search.yaml -
Don’t commit config files Add to
.gitignore:.code-search.yaml
CI/CD Configuration
Section titled “CI/CD Configuration”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"Next Steps
Section titled “Next Steps”- Search Commands - Learn to search
- Replace Commands - Bulk operations