Skip to content

Commit 6148c3f

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 dd4f76e commit 6148c3f

32 files changed

+1588
-708
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: 4 additions & 25 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.
@@ -436,29 +436,8 @@ Browse the Sentry API schema
436436

437437
→ Full flags and examples: `references/schema.md`
438438

439-
## Global Options
440-
441-
All commands support the following global options:
442-
443-
- `--help` - Show help for the command
444-
- `--version` - Show CLI version
445-
- `--log-level <level>` - Set log verbosity (`error`, `warn`, `log`, `info`, `debug`, `trace`). Overrides `SENTRY_LOG_LEVEL`
446-
- `--verbose` - Shorthand for `--log-level debug`
447-
448439
## Output Formats
449440

450-
### JSON Output
441+
Most commands support `--json` flag for JSON output, making it easy to integrate with other tools.
451442

452-
Most list and view commands support `--json` flag for JSON output, making it easy to integrate with other tools:
453-
454-
```bash
455-
sentry org list --json | jq '.[] | .slug'
456-
```
457-
458-
### Opening in Browser
459-
460-
View commands support `-w` or `--web` flag to open the resource in your browser:
461-
462-
```bash
463-
sentry issue view PROJ-123 -w
464-
```
443+
View commands support `-w` or `--web` flag to open the resource in your browser.

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

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -26,44 +26,4 @@ Make an authenticated API request
2626
- `--verbose - Include full HTTP request and response in the output`
2727
- `-n, --dry-run - Show the resolved request without sending it`
2828

29-
**Examples:**
30-
31-
```bash
32-
# List organizations
33-
sentry api organizations/
34-
35-
# Get a specific issue
36-
sentry api issues/123456789/
37-
38-
# Create a release
39-
sentry api organizations/my-org/releases/ \
40-
-X POST -F version=1.0.0
41-
42-
# With inline JSON body
43-
sentry api issues/123456789/ \
44-
-X POST -d '{"status": "resolved"}'
45-
46-
# Update an issue status
47-
sentry api issues/123456789/ \
48-
-X PUT -F status=resolved
49-
50-
# Assign an issue
51-
sentry api issues/123456789/ \
52-
-X PUT --field assignedTo="user@example.com"
53-
54-
sentry api projects/my-org/my-project/ -X DELETE
55-
56-
# Add custom headers
57-
sentry api organizations/ -H "X-Custom: value"
58-
59-
# Read body from a file
60-
sentry api projects/my-org/my-project/releases/ -X POST --input release.json
61-
62-
# Verbose mode (shows full HTTP request/response)
63-
sentry api organizations/ --verbose
64-
65-
# Preview the request without sending
66-
sentry api organizations/ --dry-run
67-
```
68-
6929
All commands also support `--json`, `--fields`, `--help`, `--log-level`, and `--verbose` flags.

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

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -20,41 +20,17 @@ Authenticate with Sentry
2020
- `--timeout <value> - Timeout for OAuth flow in seconds (default: 900) - (default: "900")`
2121
- `--force - Re-authenticate without prompting`
2222

23-
**Examples:**
24-
25-
```bash
26-
sentry auth login
27-
28-
sentry auth login --token YOUR_SENTRY_API_TOKEN
29-
30-
SENTRY_URL=https://sentry.example.com sentry auth login
31-
32-
SENTRY_URL=https://sentry.example.com sentry auth login --token YOUR_TOKEN
33-
```
34-
3523
### `sentry auth logout`
3624

3725
Log out of Sentry
3826

39-
**Examples:**
40-
41-
```bash
42-
sentry auth logout
43-
```
44-
4527
### `sentry auth refresh`
4628

4729
Refresh your authentication token
4830

4931
**Flags:**
5032
- `--force - Force refresh even if token is still valid`
5133

52-
**Examples:**
53-
54-
```bash
55-
sentry auth refresh
56-
```
57-
5834
### `sentry auth status`
5935

6036
View authentication status
@@ -63,28 +39,10 @@ View authentication status
6339
- `--show-token - Show the stored token (masked by default)`
6440
- `-f, --fresh - Bypass cache, re-detect projects, and fetch fresh data`
6541

66-
**Examples:**
67-
68-
```bash
69-
sentry auth status
70-
71-
# Show the raw token
72-
sentry auth status --show-token
73-
74-
# View current user
75-
sentry auth whoami
76-
```
77-
7842
### `sentry auth token`
7943

8044
Print the stored authentication token
8145

82-
**Examples:**
83-
84-
```bash
85-
sentry auth token
86-
```
87-
8846
### `sentry auth whoami`
8947

9048
Show the currently authenticated user

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

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,13 @@ CLI-related commands
1515

1616
Send feedback about the CLI
1717

18-
**Examples:**
19-
20-
```bash
21-
# Send positive feedback
22-
sentry cli feedback i love this tool
23-
24-
# Report an issue
25-
sentry cli feedback the issue view is confusing
26-
```
27-
2818
### `sentry cli fix`
2919

3020
Diagnose and repair CLI database issues
3121

3222
**Flags:**
3323
- `--dry-run - Show what would be fixed without making changes`
3424

35-
**Examples:**
36-
37-
```bash
38-
sentry cli fix
39-
```
40-
4125
### `sentry cli setup`
4226

4327
Configure shell integration
@@ -51,19 +35,6 @@ Configure shell integration
5135
- `--no-agent-skills - Skip agent skill installation for AI coding assistants`
5236
- `--quiet - Suppress output (for scripted usage)`
5337

54-
**Examples:**
55-
56-
```bash
57-
# Run full setup (PATH, completions, agent skills)
58-
sentry cli setup
59-
60-
# Skip agent skill installation
61-
sentry cli setup --no-agent-skills
62-
63-
# Skip PATH and completion modifications
64-
sentry cli setup --no-modify-path --no-completions
65-
```
66-
6738
### `sentry cli upgrade <version>`
6839

6940
Update the Sentry CLI to the latest version
@@ -74,25 +45,4 @@ Update the Sentry CLI to the latest version
7445
- `--offline - Upgrade using only cached version info and patches (no network)`
7546
- `--method <value> - Installation method to use (curl, brew, npm, pnpm, bun, yarn)`
7647

77-
**Examples:**
78-
79-
```bash
80-
sentry cli upgrade --check
81-
82-
# Upgrade to latest stable
83-
sentry cli upgrade
84-
85-
# Upgrade to a specific version
86-
sentry cli upgrade 0.5.0
87-
88-
# Force re-download
89-
sentry cli upgrade --force
90-
91-
# Switch to nightly builds
92-
sentry cli upgrade nightly
93-
94-
# Switch back to stable
95-
sentry cli upgrade stable
96-
```
97-
9848
All commands also support `--json`, `--fields`, `--help`, `--log-level`, and `--verbose` flags.

0 commit comments

Comments
 (0)