Skip to content

Commit d81e813

Browse files
authored
Merge pull request #126 from nshepperd/xdg-config-path
Xdg config path
2 parents 356330f + 6815608 commit d81e813

18 files changed

Lines changed: 198 additions & 80 deletions

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ Before `1.0.0`, breaking changes may still ship in minor releases.
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- The configuration file now lives at a fixed XDG location instead of a working-directory-relative `./.kagi.toml`. It is resolved in this order: `$KAGI_CONFIG` (an explicit full file path), then `$XDG_CONFIG_HOME/kagi-cli/config.toml`, then `~/.config/kagi-cli/config.toml`. The file is still created with `0600` permissions, and the `KAGI_API_KEY`/`KAGI_API_TOKEN`/`KAGI_SESSION_TOKEN` environment variables continue to take precedence over it.
13+
14+
**Breaking:** credentials previously saved in a working-directory-relative `./.kagi.toml` are no longer read. Run `kagi auth set` (or `kagi auth`) once to re-save them at the new location, or point `KAGI_CONFIG` at your existing file.
15+
1016
## [0.10.0]
1117

1218
### Added

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Pull requests will not be rejected solely because AI was used. They may be rejec
7878

7979
## Auth and Test Safety
8080

81-
- Do not commit `.env`, `.kagi.toml`, session tokens, or API tokens
81+
- Do not commit `.env`, credential files, session tokens, or API tokens
8282
- Prefer unit tests and parser fixtures over live authenticated tests
8383
- If a change requires live verification, document the exact manual steps in the pull request
8484

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
`kagi` is a terminal CLI for Kagi that gives you command-line access to search, quick answers, ask-page, assistant, translate, summarization, public feeds through `news` and `smallweb`, paid API commands like `fastgpt` and `enrich`, and account-level settings like lenses, custom assistants, custom bangs, and redirect rules. it is built for people who want one command surface for interactive use, shell workflows, and structured JSON output.
2020

21-
the main setup path is `kagi auth`. on a real terminal it opens a guided setup flow where you choose `Session Link`, `API Key`, or `Legacy API Token`, get the official instructions inline, paste the credential, save it to `./.kagi.toml`, and validate it immediately. if you also use Kagi's paid API, the same wizard can add that too.
21+
the main setup path is `kagi auth`. on a real terminal it opens a guided setup flow where you choose `Session Link`, `API Key`, or `Legacy API Token`, get the official instructions inline, paste the credential, save it to `~/.config/kagi-cli/config.toml`, and validate it immediately. if you also use Kagi's paid API, the same wizard can add that too.
2222

2323
[documentation](https://kagi.micr.dev) | [npm](https://www.npmjs.com/package/kagi-cli) | [mcp](https://github.com/Microck/kagi-mcp)
2424

@@ -81,7 +81,7 @@ the wizard is the default setup path. it guides you through:
8181
- `Session Link` from `https://kagi.com/settings/user_details`
8282
- `API Key` from `https://kagi.com/api/keys`
8383
- `Legacy API Token` from `https://kagi.com/settings/api`
84-
- saving into `./.kagi.toml`
84+
- saving into `~/.config/kagi-cli/config.toml`
8585
- immediate validation
8686

8787
non-interactive alternative:
@@ -153,8 +153,8 @@ notes:
153153

154154
- `kagi auth` is interactive on TTYs and becomes the default onboarding path
155155
- `kagi auth set --session-token` accepts either the raw token or the full session-link URL
156-
- `kagi --profile work ...` reads `[profiles.work.auth]` from `.kagi.toml`
157-
- environment variables override `.kagi.toml`
156+
- `kagi --profile work ...` reads `[profiles.work.auth]` from the config file (`~/.config/kagi-cli/config.toml`)
157+
- environment variables override `~/.config/kagi-cli/config.toml`
158158
- base `kagi search` defaults to the session-token path when both credentials are present
159159
- set `[auth] preferred_auth = "api"` if you want base search to prefer the API path instead
160160
- API-first base search falls back to the session-token path when the API key is rejected, including quota and rate-limit failures

docs/SKILL.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ kagi auth
4949
Opens a guided TTY wizard that walks through:
5050
- Choosing Session Link, API Key, or Legacy API Token
5151
- Pasting credentials
52-
- Saving to `./.kagi.toml`
52+
- Saving to `~/.config/kagi-cli/config.toml`
5353
- Immediate validation
5454

5555
### Non-Interactive Setup
@@ -77,7 +77,7 @@ export KAGI_API_TOKEN='...'
7777
| `KAGI_API_TOKEN` | summarize, fastgpt, enrich web, enrich news |
7878
| none | news, smallweb, auth status, --help |
7979

80-
Environment variables override `./.kagi.toml`. When a session token and API key are both present, base `kagi search` defaults to the session token; set `[auth] preferred_auth = "api"` in config to prefer the API key.
80+
Environment variables override `~/.config/kagi-cli/config.toml`. When a session token and API key are both present, base `kagi search` defaults to the session token; set `[auth] preferred_auth = "api"` in config to prefer the API key.
8181

8282
## Commands
8383

docs/commands/auth.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: "Reference for the kagi auth wizard and non-interactive credential
55

66
# `kagi auth`
77

8-
`kagi auth` is the main onboarding path for this CLI. On a real terminal, it launches an interactive setup wizard that lets you choose `Session Link`, `API Key`, or `Legacy API Token`, shows the official Kagi settings page for that credential, accepts a paste, saves into `./.kagi.toml`, and validates the selected credential immediately.
8+
`kagi auth` is the main onboarding path for this CLI. On a real terminal, it launches an interactive setup wizard that lets you choose `Session Link`, `API Key`, or `Legacy API Token`, shows the official Kagi settings page for that credential, accepts a paste, saves into `~/.config/kagi-cli/config.toml`, and validates the selected credential immediately.
99

1010
![Auth command demo](/images/demos/auth.gif)
1111

@@ -34,7 +34,7 @@ The wizard flow is:
3434
4. accepts the pasted value
3535
5. asks before overwriting an existing config value of the same type
3636
6. validates the selected credential
37-
7. saves to `./.kagi.toml`
37+
7. saves to `~/.config/kagi-cli/config.toml`
3838
8. warns if an environment variable will still override what you saved
3939

4040
### Session Link Path
@@ -109,7 +109,7 @@ preferred auth for base search: session
109109
api key: not configured
110110
legacy api token: not configured
111111
session token: configured via config
112-
config path: .kagi.toml
112+
config path: ~/.config/kagi-cli/config.toml
113113
precedence: env > selected profile config > default config; base search defaults to session unless preferred_auth = "api"; lens search requires session token
114114
```
115115

@@ -155,7 +155,7 @@ Options:
155155

156156
Behavior:
157157

158-
- creates `./.kagi.toml` when needed
158+
- creates `~/.config/kagi-cli/config.toml` when needed
159159
- preserves the other credential if you only set one
160160
- normalizes full Session Link URLs into the raw token value
161161
- writes the config file with restrictive permissions on Unix
@@ -166,9 +166,9 @@ The CLI resolves credentials in this order:
166166

167167
1. `KAGI_API_KEY` / `KAGI_API_TOKEN` / `KAGI_SESSION_TOKEN`
168168
2. selected profile config, such as `[profiles.work.auth]`
169-
3. default `./.kagi.toml` `[auth]`
169+
3. default `~/.config/kagi-cli/config.toml` `[auth]`
170170

171-
Environment variables override the config file. Use `--profile <NAME>` to select a named profile from `.kagi.toml`:
171+
The config file is resolved from `$KAGI_CONFIG` (an explicit full path), then `$XDG_CONFIG_HOME/kagi-cli/config.toml`, then `~/.config/kagi-cli/config.toml`. Environment variables override the config file. Use `--profile <NAME>` to select a named profile from the config file (`~/.config/kagi-cli/config.toml`):
172172

173173
```toml
174174
[profiles.work.auth]
@@ -220,7 +220,7 @@ kagi search --format pretty "what changed in rust 1.86?"
220220
## Security Notes
221221

222222
- `auth status` and `auth check` never print the secret values
223-
- `./.kagi.toml` is local plaintext config, so keep it out of version control
223+
- `~/.config/kagi-cli/config.toml` is local plaintext config, so keep it out of version control
224224
- on Unix, the CLI writes restrictive file permissions when saving the config
225225
- environment variables still override config and may be preferable in CI/CD
226226

docs/guides/advanced-usage.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,9 @@ chmod 600 "$TEMP_FILE"
691691
#!/bin/bash
692692
# Prevent accidental token commits
693693

694-
# Add to .gitignore
695-
echo ".kagi.toml" >> .gitignore
694+
# The config file now lives at ~/.config/kagi-cli/config.toml, outside your
695+
# repositories, so it no longer needs to be added to .gitignore.
696+
# Still guard against other accidental secret commits:
696697
echo ".env" >> .gitignore
697698
echo "*token*" >> .gitignore
698699

docs/guides/authentication.mdx

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ On a real terminal, the default setup path is:
1515
kagi auth
1616
```
1717

18-
The wizard lets you choose `Session Link`, `API Key`, or `Legacy API Token`, points you to the correct Kagi settings page, accepts a paste, saves into `./.kagi.toml`, and validates the selected credential immediately.
18+
The wizard lets you choose `Session Link`, `API Key`, or `Legacy API Token`, points you to the correct Kagi settings page, accepts a paste, saves into `~/.config/kagi-cli/config.toml`, and validates the selected credential immediately.
1919

2020
Use `kagi auth set ...` only when you want a non-interactive or scripted flow.
2121

@@ -219,10 +219,14 @@ env:
219219
220220
### Method 2: Configuration File
221221
222-
The `.kagi.toml` file provides persistent configuration:
222+
The config file provides persistent configuration:
223223
224224
**Location:**
225-
- `./.kagi.toml` in the current working directory
225+
- `~/.config/kagi-cli/config.toml`
226+
227+
The config file is resolved from `$KAGI_CONFIG` (an explicit full path), then `$XDG_CONFIG_HOME/kagi-cli/config.toml`, then `~/.config/kagi-cli/config.toml`.
228+
229+
> **Migration note:** A pre-existing `./.kagi.toml` in your working directory is no longer read. Re-run `kagi auth set` (or `kagi auth`) once to re-save your credentials at the new location, or set `KAGI_CONFIG` to the old file path.
226230

227231
**File format:**
228232

@@ -260,14 +264,15 @@ kagi auth set --session-token 'https://kagi.com/search?token=SESSION_TOKEN' --ap
260264

261265
```bash
262266
# macOS/Linux
263-
cat > ./.kagi.toml << 'EOF'
267+
mkdir -p ~/.config/kagi-cli
268+
cat > ~/.config/kagi-cli/config.toml << 'EOF'
264269
[auth]
265270
api_token = "your_api_token"
266271
session_token = "https://kagi.com/search?token=your_session_token"
267272
EOF
268273
269274
# Set secure permissions
270-
chmod 600 ./.kagi.toml
275+
chmod 600 ~/.config/kagi-cli/config.toml
271276
```
272277

273278
```powershell
@@ -277,7 +282,8 @@ $content = @"
277282
api_token = `"your_api_token`"
278283
session_token = `"https://kagi.com/search?token=your_session_token`"
279284
"@
280-
$content | Out-File -FilePath ".kagi.toml" -Encoding utf8
285+
New-Item -ItemType Directory -Force -Path "$HOME\.config\kagi-cli" | Out-Null
286+
$content | Out-File -FilePath "$HOME\.config\kagi-cli\config.toml" -Encoding utf8
281287
```
282288

283289
### Precedence Rules
@@ -286,10 +292,12 @@ Credentials are resolved in this order (first match wins):
286292

287293
```
288294
1. Environment Variables (KAGI_API_KEY, KAGI_API_TOKEN, KAGI_SESSION_TOKEN)
289-
2. Configuration File (`./.kagi.toml`)
295+
2. Configuration File (`~/.config/kagi-cli/config.toml`)
290296
3. Missing (error for commands requiring auth)
291297
```
292298

299+
The config file is resolved from `$KAGI_CONFIG` (an explicit full path), then `$XDG_CONFIG_HOME/kagi-cli/config.toml`, then `~/.config/kagi-cli/config.toml`.
300+
293301
This means:
294302
- Environment variables override config file values
295303
- You can temporarily test different tokens via env vars
@@ -300,7 +308,7 @@ This means:
300308

301309
```bash
302310
# Config file has default session token
303-
cat ./.kagi.toml
311+
cat ~/.config/kagi-cli/config.toml
304312
# [auth]
305313
# session_token = "https://kagi.com/search?token=DEFAULT_TOKEN"
306314

@@ -335,7 +343,7 @@ selected: none
335343
api key: not configured
336344
legacy api token: not configured
337345
session token: not configured
338-
config path: .kagi.toml
346+
config path: ~/.config/kagi-cli/config.toml
339347
```
340348

341349
Session token only:
@@ -344,7 +352,7 @@ selected: session-token (config)
344352
api key: not configured
345353
legacy api token: not configured
346354
session token: configured via config
347-
config path: .kagi.toml
355+
config path: ~/.config/kagi-cli/config.toml
348356
```
349357

350358
API key and session token:
@@ -353,7 +361,7 @@ selected: api-key (env)
353361
api key: configured via env
354362
legacy api token: not configured
355363
session token: configured via config
356-
config path: .kagi.toml
364+
config path: ~/.config/kagi-cli/config.toml
357365
```
358366

359367
### Validating Credentials
@@ -497,7 +505,7 @@ kagi search "test"
497505
**Scenario 2: API-first mode works**
498506
```bash
499507
export KAGI_API_KEY='valid_key'
500-
# .kagi.toml contains: [auth] preferred_auth = "api"
508+
# ~/.config/kagi-cli/config.toml contains: [auth] preferred_auth = "api"
501509
kagi search "test"
502510
# Uses Search API, returns results
503511
```
@@ -506,7 +514,7 @@ kagi search "test"
506514
```bash
507515
export KAGI_API_KEY='valid_key'
508516
export KAGI_SESSION_TOKEN='also_valid'
509-
# .kagi.toml contains: [auth] preferred_auth = "api"
517+
# ~/.config/kagi-cli/config.toml contains: [auth] preferred_auth = "api"
510518
kagi search "test"
511519
# Tries Search API and gets auth error
512520
# Falls back to session token path
@@ -527,7 +535,7 @@ kagi search "test"
527535

528536
**DO:**
529537
- ✅ Use `kagi auth` for local setup so the CLI validates the credential as you save it
530-
- ✅ Store tokens in `./.kagi.toml` with 600 permissions
538+
- ✅ Store tokens in `~/.config/kagi-cli/config.toml` with 600 permissions
531539
- ✅ Use environment variables in CI/CD secrets
532540
- ✅ Use secret managers (1Password, Vault, etc.)
533541
- ✅ Rotate tokens periodically
@@ -742,7 +750,7 @@ $env:KAGI_SESSION_TOKEN = [System.Runtime.InteropServices.Marshal]::PtrToStringA
742750

743751
### Multiple Profiles
744752

745-
For users with multiple Kagi accounts, prefer named profiles in one `.kagi.toml`:
753+
For users with multiple Kagi accounts, prefer named profiles in one config file (`~/.config/kagi-cli/config.toml`):
746754

747755
```toml
748756
[auth]

docs/guides/installation.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ To completely remove *kagi*:
547547
rm ~/.local/bin/kagi
548548

549549
# Remove config
550-
rm ./.kagi.toml
550+
rm ~/.config/kagi-cli/config.toml
551551

552552
# Remove from PATH (edit ~/.bashrc, ~/.zshrc, etc.)
553553
```
@@ -559,7 +559,7 @@ rm ./.kagi.toml
559559
Remove-Item -Recurse -Force "$env:LOCALAPPDATA\kagi"
560560
561561
# Remove config
562-
Remove-Item ".kagi.toml"
562+
Remove-Item "$HOME\.config\kagi-cli\config.toml"
563563
564564
# Remove from PATH via System Properties
565565
```

docs/guides/quickstart.mdx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ selected: none
9090
api key: not configured
9191
legacy api token: not configured
9292
session token: not configured
93-
config path: .kagi.toml
93+
config path: ~/.config/kagi-cli/config.toml
9494
```
9595

9696
This is expected - we'll configure credentials next.
@@ -150,7 +150,7 @@ Save the token to a config file:
150150
kagi auth set --session-token 'https://kagi.com/search?token=YOUR_TOKEN_HERE'
151151
```
152152

153-
This creates `./.kagi.toml` with your token. The CLI accepts either:
153+
This creates `~/.config/kagi-cli/config.toml` with your token. The CLI accepts either:
154154
- The full Session Link URL (recommended)
155155
- Just the raw token value
156156

@@ -167,7 +167,7 @@ selected: session-token (config)
167167
api key: not configured
168168
legacy api token: not configured
169169
session token: configured via config
170-
config path: .kagi.toml
170+
config path: ~/.config/kagi-cli/config.toml
171171
```
172172

173173
### Testing Subscriber Features
@@ -306,9 +306,9 @@ See the [Auth Matrix](/reference/auth-matrix) for the complete command-to-token
306306

307307
Now that you've tested everything, let's create a robust configuration.
308308

309-
### The .kagi.toml File
309+
### The config file
310310

311-
Kagi uses a TOML configuration file located at `./.kagi.toml`.
311+
Kagi uses a TOML configuration file located at `~/.config/kagi-cli/config.toml`.
312312

313313
**Basic configuration:**
314314

@@ -322,24 +322,25 @@ session_token = "your_session_token_here"
322322

323323
```bash
324324
# Create the file
325-
cat > ./.kagi.toml << 'EOF'
325+
mkdir -p ~/.config/kagi-cli
326+
cat > ~/.config/kagi-cli/config.toml << 'EOF'
326327
[auth]
327328
api_token = "your_api_token_here"
328329
session_token = "your_session_token_here"
329330
EOF
330331

331332
# Set secure permissions
332-
chmod 600 ./.kagi.toml
333+
chmod 600 ~/.config/kagi-cli/config.toml
333334
```
334335

335336
### Configuration Precedence
336337

337338
Kagi resolves credentials in this order (first match wins):
338339

339340
1. **Environment variables** (`KAGI_API_KEY`, `KAGI_API_TOKEN`, `KAGI_SESSION_TOKEN`)
340-
2. **Config file** (`./.kagi.toml`)
341+
2. **Config file** (`~/.config/kagi-cli/config.toml`)
341342

342-
This means you can override file configuration with environment variables for specific workflows or CI/CD.
343+
The config file is resolved from `$KAGI_CONFIG` (an explicit full path), then `$XDG_CONFIG_HOME/kagi-cli/config.toml`, then `~/.config/kagi-cli/config.toml`. This means you can override file configuration with environment variables for specific workflows or CI/CD.
343344

344345
### Shell Profile Integration
345346

@@ -379,7 +380,7 @@ $env:KAGI_API_TOKEN = 'your_api_token'
379380

380381
### Security Best Practices
381382

382-
1. **File permissions**: Set `./.kagi.toml` to 600 (readable only by you)
383+
1. **File permissions**: Set `~/.config/kagi-cli/config.toml` to 600 (readable only by you)
383384
2. **Environment variables**: Don't commit these to version control
384385
3. **Token rotation**: Regenerate tokens periodically
385386
4. **Separate contexts**: Use different tokens for different environments (dev/staging/prod)

docs/guides/troubleshooting.mdx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ kagi auth check
179179
kagi auth set --session-token 'https://kagi.com/search?token=YOUR_TOKEN'
180180

181181
# Or manually
182-
cat > ./.kagi.toml << 'EOF'
182+
mkdir -p ~/.config/kagi-cli
183+
cat > ~/.config/kagi-cli/config.toml << 'EOF'
183184
[auth]
184185
session_token = "https://kagi.com/search?token=YOUR_TOKEN"
185186
EOF
@@ -789,7 +790,9 @@ kagi auth check
789790

790791
### Config File Location
791792

792-
- Repo checkout: `./.kagi.toml`
793+
- Default: `~/.config/kagi-cli/config.toml`
794+
795+
The config file is resolved from `$KAGI_CONFIG` (an explicit full path), then `$XDG_CONFIG_HOME/kagi-cli/config.toml`, then `~/.config/kagi-cli/config.toml`. A pre-existing `./.kagi.toml` is no longer read; re-run `kagi auth set` (or `kagi auth`) to re-save credentials at the new location, or set `KAGI_CONFIG` to the old file path.
793796

794797
### Shell Syntax
795798

0 commit comments

Comments
 (0)