Skip to content

feat(config): support .sentryclirc config file for per-directory defaults#693

Open
BYK wants to merge 1 commit intomainfrom
feat/sentryclirc-config
Open

feat(config): support .sentryclirc config file for per-directory defaults#693
BYK wants to merge 1 commit intomainfrom
feat/sentryclirc-config

Conversation

@BYK
Copy link
Copy Markdown
Member

@BYK BYK commented Apr 8, 2026

Summary

  • Adds backward-compatible .sentryclirc INI config file support, matching the legacy sentry-cli format
  • Walks up from CWD to find config files, merging them (closest file wins per-field) with ~/.sentryclirc as global fallback
  • Enables per-directory org/project defaults for monorepos
  • Token and URL are applied via env shim (SENTRY_AUTH_TOKEN, SENTRY_URL); org/project are inserted directly into the resolution chain with source tracking

Resolution chain (updated)

1. Explicit CLI args          (highest)
2. Environment variables
3. .sentryclirc file          ← NEW
4. SQLite defaults
5. DSN auto-detection
6. Directory name inference   (lowest)

Monorepo example

monorepo/
  .sentryclirc              # [defaults] org = my-company
  packages/
    frontend/.sentryclirc   # [defaults] project = frontend-web
    backend/.sentryclirc    # [defaults] project = backend-api

New files

File Purpose
src/lib/ini.ts Zero-dep INI parser (BOM, quotes, case-insensitive)
src/lib/sentryclirc.ts Walk-up discovery + merge + env shim + cache
test/lib/ini.test.ts 26 unit tests
test/lib/ini.property.test.ts 6 property-based tests (fast-check)
test/lib/sentryclirc.test.ts 24 unit tests
test/lib/sentryclirc.property.test.ts 3 property-based tests

Modified files

  • src/cli.ts — call applySentryCliRcEnvShim() early in boot
  • src/lib/resolve-target.ts — insert step 3 in all 4 resolution functions
  • docs/src/content/docs/configuration.md — new .sentryclirc section with monorepo guide
  • docs/src/content/docs/features.md — link to resolution priority + tip
  • docs/src/content/docs/agent-guidance.md — updated auto-detection references
  • plugins/sentry-cli/skills/sentry-cli/SKILL.md — regenerated

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • (commands) Add buildRouteMap wrapper with standard subcommand aliases by BYK in #690
  • (config) Support .sentryclirc config file for per-directory defaults by BYK in #693

Bug Fixes 🐛

  • (dashboard) Render tracemetrics widgets in dashboard view by BYK in #695
  • (init) Narrow command validation to actual shell injection vectors by betegon in #697
  • (init,feedback) Default to tracing only in feature select and attach user email to feedback by MathurAditya724 in #688

Internal Changes 🔧

  • (docs) Gitignore generated command docs, extract fragments by BYK in #696
  • (eval) Replace OpenAI with Anthropic SDK in init-eval judge by betegon in #683
  • (init) Use markdown pipeline for spinner messages by betegon in #686
  • Regenerate skill files and command docs by github-actions[bot] in 584ec0e0

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/pr-preview/pr-693/

Built to branch gh-pages at 2026-04-09 12:41 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

Codecov Results 📊

134 passed | Total: 134 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

✅ Patch coverage is 88.42%. Project has 1516 uncovered lines.
❌ Project coverage is 95.38%. Comparing base (base) to head (head).

Files with missing lines (2)
File Patch % Lines
src/lib/resolve-target.ts 34.88% ⚠️ 28 Missing
src/lib/sentryclirc.ts 96.35% ⚠️ 5 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    95.47%    95.38%    -0.09%
==========================================
  Files          224       227        +3
  Lines        32534     32779      +245
  Branches         0         0         —
==========================================
+ Hits         31059     31263      +204
- Misses        1475      1516       +41
- Partials         0         0         —

Generated by Codecov Action

@BYK BYK force-pushed the feat/sentryclirc-config branch 2 times, most recently from 7ca1150 to e0b746c Compare April 8, 2026 19:42
@BYK BYK marked this pull request as ready for review April 8, 2026 19:42
@BYK BYK force-pushed the feat/sentryclirc-config branch from e0b746c to c0ef499 Compare April 8, 2026 20:00
@BYK BYK force-pushed the feat/sentryclirc-config branch from c0ef499 to 8d86cbd Compare April 8, 2026 20:09
@BYK BYK force-pushed the feat/sentryclirc-config branch 2 times, most recently from 465e9f9 to 519dc5f Compare April 9, 2026 09:12
@BYK BYK force-pushed the feat/sentryclirc-config branch from c2f32be to 05d4dae Compare April 9, 2026 09:26
@BYK BYK force-pushed the feat/sentryclirc-config branch from 05d4dae to e141d2f Compare April 9, 2026 09:39
@BYK BYK force-pushed the feat/sentryclirc-config branch from 448efc2 to ae7499c Compare April 9, 2026 09:47
@BYK BYK force-pushed the feat/sentryclirc-config branch 2 times, most recently from 50670a8 to 9653462 Compare April 9, 2026 10:28
@BYK BYK force-pushed the feat/sentryclirc-config branch from 0a10704 to 6148c3f Compare April 9, 2026 10:44
@BYK BYK force-pushed the feat/sentryclirc-config branch from 1b34396 to 3b880a9 Compare April 9, 2026 12:22
Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3b880a9. Configure here.

}

// Populate sentryclirc cache from accumulated data
setSentryCliRcCache(resolvedStart, rcConfig);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cache overwrite drops global fallback config values

Medium Severity

walkUpDirectories accumulates .sentryclirc data via applySentryCliRcDir, which explicitly skips global paths (~/.sentryclirc, $SENTRY_CONFIG_DIR/.sentryclirc) because they're meant to be "applied as fallback after the walk." However, walkUpDirectories never calls applyGlobalFallbacks before calling setSentryCliRcCache, so the cached config is missing global fallback values. This overwrites any correctly-populated cache entry from a prior loadSentryCliRc call (which does call applyGlobalFallbacks in doLoad). The walk may also exit early (on DSN or repo root), further missing ancestor configs.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 3b880a9. Configure here.

@BYK BYK force-pushed the feat/sentryclirc-config branch from 3b880a9 to 496a257 Compare April 9, 2026 12:31
…ults

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.
@BYK BYK force-pushed the feat/sentryclirc-config branch from 496a257 to dfe7a29 Compare April 9, 2026 12:40
state.levelsTraversed
);
if (dsnResult && currentDir !== stopBoundary) {
setSentryCliRcCache(resolvedStart, rcConfig);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The .sentryclirc cache is populated prematurely by walkUpDirectories without global fallbacks, causing loadSentryCliRc to use an incomplete configuration.
Severity: HIGH

Suggested Fix

Delay populating the .sentryclirc cache until after all configuration sources, including global fallbacks, have been fully resolved and merged. Alternatively, ensure that loadSentryCliRc invalidates or ignores the incomplete cache entry created by walkUpDirectories and performs a complete configuration load.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/lib/dsn/project-root.ts#L487

Potential issue: The `.sentryclirc` configuration cache is prematurely populated by
`walkUpDirectories` with a configuration that omits global fallbacks, such as those from
`~/.sentryclirc`. Subsequent calls to `loadSentryCliRc` then access this incomplete
cache. This causes global settings like `auth.token` or `defaults.url` to be ignored,
which can lead to authentication or connection failures when the CLI attempts to
communicate with Sentry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant