Skip to content

Commit 9653462

Browse files
committed
feat(config): support .sentryclirc config file for per-directory defaults
Add backward-compatible support for .sentryclirc INI config files. The CLI walks up from CWD to find config files, merging them (closest wins per-field) with ~/.sentryclirc as a global fallback. Supported fields: - [defaults] org, project, url - [auth] token Token and URL are applied via env shim (SENTRY_AUTH_TOKEN, SENTRY_URL). Org and project are inserted into the resolution chain between env vars and SQLite defaults with source tracking. This enables per-directory project defaults in monorepos and seamless migration from legacy sentry-cli.
1 parent 8c49fb2 commit 9653462

File tree

20 files changed

+1594
-91
lines changed

20 files changed

+1594
-91
lines changed

docs/src/content/docs/agent-guidance.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Best practices and operational guidance for AI coding agents using the Sentry CL
1212
- **Use `sentry schema` to explore the API** — if you need to discover API endpoints, run `sentry schema` to browse interactively or `sentry schema <resource>` to search. This is faster than fetching OpenAPI specs externally.
1313
- **Use `sentry issue view <id>` to investigate issues** — when asked about a specific issue (e.g., `CLI-G5`, `PROJECT-123`), use `sentry issue view` directly.
1414
- **Use `--json` for machine-readable output** — pipe through `jq` for filtering. Human-readable output includes formatting that is hard to parse.
15-
- **The CLI auto-detects org/project** — most commands work without explicit targets by scanning for DSNs in `.env` files, source code, config defaults, and directory names. Only specify `<org>/<project>` when the CLI reports it can't detect the target or detects the wrong one.
15+
- **The CLI auto-detects org/project** — most commands work without explicit targets by checking `.sentryclirc` config files, scanning for DSNs in `.env` files and source code, and matching directory names. Only specify `<org>/<project>` when the CLI reports it can't detect the target or detects the wrong one.
1616

1717
## Design Principles
1818

@@ -213,7 +213,7 @@ When querying the Events API (directly or via `sentry api`), valid dataset value
213213
- **Wrong issue ID format**: Use `PROJECT-123` (short ID), not the numeric ID `123456789`. The short ID includes the project prefix.
214214
- **Pre-authenticating unnecessarily**: Don't run `sentry auth login` before every command. The CLI detects missing/expired auth and prompts automatically. Only run `sentry auth login` if you need to switch accounts.
215215
- **Missing `--json` for piping**: Human-readable output includes formatting. Use `--json` when parsing output programmatically.
216-
- **Specifying org/project when not needed**: Auto-detection resolves org/project from DSNs, env vars, config defaults, and directory names. Let it work first — only add `<org>/<project>` if the CLI says it can't detect the target or detects the wrong one.
216+
- **Specifying org/project when not needed**: Auto-detection resolves org/project from `.sentryclirc` config files, DSNs, env vars, and directory names. Let it work first — only add `<org>/<project>` if the CLI says it can't detect the target or detects the wrong one.
217217
- **Confusing `--query` syntax**: The `--query` flag uses Sentry search syntax (e.g., `is:unresolved`, `assigned:me`), not free text search.
218218
- **Not using `--web`**: View commands support `-w`/`--web` to open the resource in the browser — useful for sharing links.
219219
- **Fetching API schemas instead of using the CLI**: Prefer `sentry schema` to browse the API and `sentry api` to make requests — the CLI handles authentication and endpoint resolution, so there's rarely a need to download OpenAPI specs separately.

docs/src/content/docs/configuration.md

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,67 @@
11
---
22
title: Configuration
3-
description: Environment variables and configuration options for the Sentry CLI
3+
description: Environment variables, config files, and configuration options for the Sentry CLI
44
---
55

6-
The Sentry CLI can be configured through environment variables and a local database. Most users don't need to set any of these — the CLI auto-detects your project from your codebase and stores credentials locally after `sentry auth login`.
6+
The Sentry CLI can be configured through config files, environment variables, and a local database. Most users don't need to set any of these — the CLI auto-detects your project from your codebase and stores credentials locally after `sentry auth login`.
7+
8+
## Configuration File (`.sentryclirc`)
9+
10+
The CLI supports a `.sentryclirc` config file using standard INI syntax. This is the same format used by the legacy `sentry-cli` tool, so existing config files are automatically picked up.
11+
12+
### How It Works
13+
14+
The CLI looks for `.sentryclirc` files by walking up from your current directory toward the filesystem root. If multiple files are found, values from the closest file take priority, with `~/.sentryclirc` serving as a global fallback.
15+
16+
```ini
17+
[defaults]
18+
org = my-org
19+
project = my-project
20+
21+
[auth]
22+
token = sntrys_...
23+
```
24+
25+
### Supported Fields
26+
27+
| Section | Key | Description |
28+
|---------|-----|-------------|
29+
| `[defaults]` | `org` | Default organization slug |
30+
| `[defaults]` | `project` | Default project slug |
31+
| `[defaults]` | `url` | Sentry base URL (for self-hosted) |
32+
| `[auth]` | `token` | Auth token (mapped to `SENTRY_AUTH_TOKEN`) |
33+
34+
### Monorepo Setup
35+
36+
In monorepos, place a `.sentryclirc` at the repo root with your org, then add per-package configs with just the project:
37+
38+
```
39+
my-monorepo/
40+
.sentryclirc # [defaults] org = my-company
41+
packages/
42+
frontend/
43+
.sentryclirc # [defaults] project = frontend-web
44+
backend/
45+
.sentryclirc # [defaults] project = backend-api
46+
```
47+
48+
When you run a command from `packages/frontend/`, the CLI resolves `org = my-company` from the root and `project = frontend-web` from the closest file.
49+
50+
### Resolution Priority
51+
52+
When the CLI needs to determine your org and project, it checks these sources in order:
53+
54+
1. **Explicit CLI arguments**`sentry issue list my-org/my-project`
55+
2. **Environment variables**`SENTRY_ORG` / `SENTRY_PROJECT`
56+
3. **`.sentryclirc` config file** — walked up from CWD, merged with `~/.sentryclirc`
57+
4. **DSN auto-detection** — scans source code and `.env` files
58+
5. **Directory name inference** — matches your directory name against project slugs
59+
60+
The first source that provides both org and project wins. For org-only commands, only the org is needed.
61+
62+
### Backward Compatibility
63+
64+
If you previously used the legacy `sentry-cli` and have a `~/.sentryclirc` file, the new CLI reads it automatically. The `[defaults]` and `[auth]` sections are fully compatible. The `[auth] token` value is mapped to the `SENTRY_AUTH_TOKEN` environment variable internally (only if the env var is not already set).
765

866
## Environment Variables
967

docs/src/content/docs/features.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The Sentry CLI includes several features designed to streamline your workflow, e
77

88
## DSN Auto-Detection
99

10-
The CLI automatically detects your Sentry project from your codebase, eliminating the need to specify the target for every command.
10+
The CLI automatically detects your Sentry project from your codebase, eliminating the need to specify the target for every command. DSN detection is one part of the [resolution priority chain](./configuration/#resolution-priority) — it runs after checking for explicit arguments, environment variables, and `.sentryclirc` config files.
1111

1212
### How It Works
1313

@@ -19,6 +19,10 @@ DSN detection follows this priority order (highest first):
1919

2020
When a DSN is found, the CLI resolves it to your organization and project, then caches the result for fast subsequent lookups.
2121

22+
:::tip
23+
For monorepos or when DSN detection picks up the wrong project, use a [`.sentryclirc` config file](./configuration/#configuration-file-sentryclirc) to pin your org/project explicitly.
24+
:::
25+
2226
### Supported Languages
2327

2428
The CLI can detect DSNs from source code in these languages:

plugins/sentry-cli/skills/sentry-cli/SKILL.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Best practices and operational guidance for AI coding agents using the Sentry CL
2222
- **Use `sentry schema` to explore the API** — if you need to discover API endpoints, run `sentry schema` to browse interactively or `sentry schema <resource>` to search. This is faster than fetching OpenAPI specs externally.
2323
- **Use `sentry issue view <id>` to investigate issues** — when asked about a specific issue (e.g., `CLI-G5`, `PROJECT-123`), use `sentry issue view` directly.
2424
- **Use `--json` for machine-readable output** — pipe through `jq` for filtering. Human-readable output includes formatting that is hard to parse.
25-
- **The CLI auto-detects org/project** — most commands work without explicit targets by scanning for DSNs in `.env` files, source code, config defaults, and directory names. Only specify `<org>/<project>` when the CLI reports it can't detect the target or detects the wrong one.
25+
- **The CLI auto-detects org/project** — most commands work without explicit targets by checking `.sentryclirc` config files, scanning for DSNs in `.env` files and source code, and matching directory names. Only specify `<org>/<project>` when the CLI reports it can't detect the target or detects the wrong one.
2626

2727
### Design Principles
2828

@@ -223,7 +223,7 @@ When querying the Events API (directly or via `sentry api`), valid dataset value
223223
- **Wrong issue ID format**: Use `PROJECT-123` (short ID), not the numeric ID `123456789`. The short ID includes the project prefix.
224224
- **Pre-authenticating unnecessarily**: Don't run `sentry auth login` before every command. The CLI detects missing/expired auth and prompts automatically. Only run `sentry auth login` if you need to switch accounts.
225225
- **Missing `--json` for piping**: Human-readable output includes formatting. Use `--json` when parsing output programmatically.
226-
- **Specifying org/project when not needed**: Auto-detection resolves org/project from DSNs, env vars, config defaults, and directory names. Let it work first — only add `<org>/<project>` if the CLI says it can't detect the target or detects the wrong one.
226+
- **Specifying org/project when not needed**: Auto-detection resolves org/project from `.sentryclirc` config files, DSNs, env vars, and directory names. Let it work first — only add `<org>/<project>` if the CLI says it can't detect the target or detects the wrong one.
227227
- **Confusing `--query` syntax**: The `--query` flag uses Sentry search syntax (e.g., `is:unresolved`, `assigned:me`), not free text search.
228228
- **Not using `--web`**: View commands support `-w`/`--web` to open the resource in the browser — useful for sharing links.
229229
- **Fetching API schemas instead of using the CLI**: Prefer `sentry schema` to browse the API and `sentry api` to make requests — the CLI handles authentication and endpoint resolution, so there's rarely a need to download OpenAPI specs separately.

plugins/sentry-cli/skills/sentry-cli/references/dashboard.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ View a dashboard
4242
- `-w, --web - Open in browser`
4343
- `-f, --fresh - Bypass cache, re-detect projects, and fetch fresh data`
4444
- `-r, --refresh <value> - Auto-refresh interval in seconds (default: 60, min: 10)`
45-
- `-t, --period <value> - Time range: "7d", "2026-03-08..2026-04-08", ">=2026-03-08"`
45+
- `-t, --period <value> - Time range: "7d", "2026-03-09..2026-04-09", ">=2026-03-09"`
4646

4747
**Examples:**
4848

plugins/sentry-cli/skills/sentry-cli/references/event.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ List events for an issue
2828
- `-n, --limit <value> - Number of events (1-1000) - (default: "25")`
2929
- `-q, --query <value> - Search query (Sentry search syntax)`
3030
- `--full - Include full event body (stacktraces)`
31-
- `-t, --period <value> - Time range: "7d", "2026-03-08..2026-04-08", ">=2026-03-08" - (default: "7d")`
31+
- `-t, --period <value> - Time range: "7d", "2026-03-09..2026-04-09", ">=2026-03-09" - (default: "7d")`
3232
- `-f, --fresh - Bypass cache, re-detect projects, and fetch fresh data`
3333
- `-c, --cursor <value> - Navigate pages: "next", "prev", "first" (or raw cursor string)`
3434

plugins/sentry-cli/skills/sentry-cli/references/issue.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ List issues in a project
1919
- `-q, --query <value> - Search query (Sentry search syntax)`
2020
- `-n, --limit <value> - Maximum number of issues to list - (default: "25")`
2121
- `-s, --sort <value> - Sort by: date, new, freq, user - (default: "date")`
22-
- `-t, --period <value> - Time range: "7d", "2026-03-08..2026-04-08", ">=2026-03-08" - (default: "90d")`
22+
- `-t, --period <value> - Time range: "7d", "2026-03-09..2026-04-09", ">=2026-03-09" - (default: "90d")`
2323
- `-c, --cursor <value> - Pagination cursor (use "next" for next page, "prev" for previous)`
2424
- `--compact - Single-line rows for compact output (auto-detects if omitted)`
2525
- `-f, --fresh - Bypass cache, re-detect projects, and fetch fresh data`
@@ -78,7 +78,7 @@ List events for a specific issue
7878
- `-n, --limit <value> - Number of events (1-1000) - (default: "25")`
7979
- `-q, --query <value> - Search query (Sentry search syntax)`
8080
- `--full - Include full event body (stacktraces)`
81-
- `-t, --period <value> - Time range: "7d", "2026-03-08..2026-04-08", ">=2026-03-08" - (default: "7d")`
81+
- `-t, --period <value> - Time range: "7d", "2026-03-09..2026-04-09", ">=2026-03-09" - (default: "7d")`
8282
- `-f, --fresh - Bypass cache, re-detect projects, and fetch fresh data`
8383
- `-c, --cursor <value> - Navigate pages: "next", "prev", "first" (or raw cursor string)`
8484

plugins/sentry-cli/skills/sentry-cli/references/log.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ List logs from a project
1919
- `-n, --limit <value> - Number of log entries (1-1000) - (default: "100")`
2020
- `-q, --query <value> - Filter query (Sentry search syntax)`
2121
- `-f, --follow <value> - Stream logs (optionally specify poll interval in seconds)`
22-
- `-t, --period <value> - Time range: "7d", "2026-03-08..2026-04-08", ">=2026-03-08"`
22+
- `-t, --period <value> - Time range: "7d", "2026-03-09..2026-04-09", ">=2026-03-09"`
2323
- `-s, --sort <value> - Sort order: "newest" (default) or "oldest" - (default: "newest")`
2424
- `--fresh - Bypass cache, re-detect projects, and fetch fresh data`
2525

plugins/sentry-cli/skills/sentry-cli/references/span.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ List spans in a project or trace
1919
- `-n, --limit <value> - Number of spans (<=1000) - (default: "25")`
2020
- `-q, --query <value> - Filter spans (e.g., "op:db", "duration:>100ms", "project:backend")`
2121
- `-s, --sort <value> - Sort order: date, duration - (default: "date")`
22-
- `-t, --period <value> - Time range: "7d", "2026-03-08..2026-04-08", ">=2026-03-08" - (default: "7d")`
22+
- `-t, --period <value> - Time range: "7d", "2026-03-09..2026-04-09", ">=2026-03-09" - (default: "7d")`
2323
- `-f, --fresh - Bypass cache, re-detect projects, and fetch fresh data`
2424
- `-c, --cursor <value> - Navigate pages: "next", "prev", "first" (or raw cursor string)`
2525

plugins/sentry-cli/skills/sentry-cli/references/trace.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ List recent traces in a project
1919
- `-n, --limit <value> - Number of traces (1-1000) - (default: "25")`
2020
- `-q, --query <value> - Search query (Sentry search syntax)`
2121
- `-s, --sort <value> - Sort by: date, duration - (default: "date")`
22-
- `-t, --period <value> - Time range: "7d", "2026-03-08..2026-04-08", ">=2026-03-08" - (default: "7d")`
22+
- `-t, --period <value> - Time range: "7d", "2026-03-09..2026-04-09", ">=2026-03-09" - (default: "7d")`
2323
- `-f, --fresh - Bypass cache, re-detect projects, and fetch fresh data`
2424
- `-c, --cursor <value> - Navigate pages: "next", "prev", "first" (or raw cursor string)`
2525

@@ -78,7 +78,7 @@ View logs associated with a trace
7878

7979
**Flags:**
8080
- `-w, --web - Open trace in browser`
81-
- `-t, --period <value> - Time range: "7d", "2026-03-08..2026-04-08", ">=2026-03-08" - (default: "14d")`
81+
- `-t, --period <value> - Time range: "7d", "2026-03-09..2026-04-09", ">=2026-03-09" - (default: "14d")`
8282
- `-n, --limit <value> - Number of log entries (<=1000) - (default: "100")`
8383
- `-q, --query <value> - Additional filter query (Sentry search syntax)`
8484
- `-s, --sort <value> - Sort order: "newest" (default) or "oldest" - (default: "newest")`

0 commit comments

Comments
 (0)