Brave Search CLI with batch support and locale-aware headers
npm install @kennyfrc/websearchwebsearch is a Bun-powered CLI that calls the Brave Search API, automatically enabling operators and extra snippets while supporting single or batched queries.
Follow these steps to run your first search.
1. Install dependencies:
``bash`
bun install
2. Create ~/.config/webserch/config.toml with your Brave token:
`toml`
apiKey = "YOUR_BRAVE_API_TOKEN"
3. Execute a query:
`bash`
bun run src/main.ts query --q "hello world"
The CLI prints the top results with their extra snippets. Repeat the command with different queries as needed.
- Override defaults for a single query
- Supply flags like --country=us --lang=en-US --count=5 --offset=10 alongside --q.--batch
- Run multiple queries in one invocation
- Use to provide a list: bun run src/main.ts query --batch "bun runtime" "brave search api limits".bun run build
- Compile a standalone binary
- Run , then execute node dist/main.js query --q "typescript" without Bun.
- Command
- websearch query --q --lang --count --q
- is optional when --batch is provided; extra snippets and operators are always enabled.--country
- Flags
- : two-letter ISO code; uppercased automatically.--lang
- : language tag; normalized to en-US style.--count
- / --offset: positive integers validated by Commander.--freshness
- : Brave freshness window such as d1, w1, or m6.--batch
- : runs each query sequentially, reusing other options.~/.config/webserch/config.toml
- Configuration
- File: apiKey
- Keys: , endpoint, defaultCountry, defaultLanguage, defaultFreshness.WEBSEARCH_API_KEY
- Environment overrides: , BRAVE_API_KEY, BRAVE_SEARCH_API_KEY.Accept-Language
- Headers
- and Accept-Location derive from CLI flags or system locale hints.User-Agent
- identifies the CLI and Bun runtime.
- Bun ships direct TypeScript execution, removing separate build steps during development.
- Brave requires extra_snippets=true and operators=true for richer responses; the CLI enforces both, along with Accept-*` headers taken from host locales.
- Configuration falls back from environment variables to TOML to avoid leaking API keys into command histories.
- Batch execution reuses network headers but handles errors per query, so one failure does not abort the remaining searches.