feat: support .claude/rules/ directory for scoped Claude Code rules#26
Conversation
The Claude Code exporter now produces a hybrid output: always-apply rules go to CLAUDE.md (as before), while scoped/conditional rules are written as individual .md files in .claude/rules/ with YAML frontmatter (description, globs, alwaysApply). This matches Claude Code's native rules directory format. Also adds importClaudeCodeRules() to read .claude/rules/ with frontmatter parsing, and importAll now detects both CLAUDE.md and .claude/rules/.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis change extends Claude Code handling from a single Changes
Sequence DiagramssequenceDiagram
participant CLI
participant Importers
participant FS
participant Parser
Note over CLI,Importers: Importing scoped Claude rules from directory
CLI->>Importers: importClaudeCodeRules(rulesDir)
Importers->>FS: recurse read `.claude/rules/` -> list `.md` files
loop per file
Importers->>FS: read file contents
FS-->>Importers: file + frontmatter
Importers->>Parser: normalize id, globs, alwaysApply
Parser-->>Importers: RuleBlock
end
Importers-->>CLI: ImportResult { format: "claude", filePath: rulesDir, rules[] }
sequenceDiagram
participant Exporter
participant Filter
participant Writer
participant FS
Note over Exporter,Writer: Exporting rules to directory structure
Exporter->>Filter: filter private (unless includePrivate)
Filter-->>Exporter: filtered rules
Exporter->>Filter: split by alwaysApply
Filter-->>Exporter: [alwaysApply], [scoped]
Exporter->>Writer: write alwaysApply → outputDir/CLAUDE.md
Writer->>FS: create `outputDir/CLAUDE.md`
loop per scoped rule
Exporter->>Writer: write scoped → outputDir/.claude/rules/.../id.md
Writer->>FS: create nested `.md` with frontmatter+content
end
Writer-->>Exporter: done
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/exporters.ts`:
- Around line 388-406: In exportToClaudeCode, the mainContent written to
CLAUDE.md lacks a trailing newline; update the logic that builds/writes
mainContent (variable mainContent and the writeFileSync call that writes to
claudeMdPath) to append a single '\n' at the end before calling writeFileSync
(preserving ensureDirectoryExists and existing content assembly) so the file
always ends with a newline.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a69bb0eb-96fb-4949-9ee6-e612d51e749f
📒 Files selected for processing (8)
src/cli.tssrc/exporters.tssrc/importers.tssrc/index.tstest/claude-code.test.tstest/conditional-export.test.tstest/export-conditional-smoke.test.tstest/gitignore-prompt-conditional.test.ts
|
Hi @johnlindquist, do you think you could spare a second to look at this and possibly merge? Thanks! |
|
Thank you @johnlindquist! Sorry to ping again, but the release seems to be failing due to missing/bad npm token. |
Hi! We want to use dotagent at work to keep our AI rules in sync across tools. One thing we ran into is that the Claude Code export only produces a single
CLAUDE.md, which means scoped rules lose their metadata and get flattened into reference links.Claude Code natively supports
.claude/rules/with individual.mdfiles that have YAML frontmatter (description,globs,alwaysApply), so this PR adds that:CLAUDE.md, scoped rules →.claude/rules/*.mdwith proper frontmatterimportClaudeCodeRules()reads.claude/rules/with frontmatter parsing and mapsglobs↔scopefor cross-format compatibilityimportAllpicks up bothCLAUDE.mdand.claude/rules/The pattern follows the existing Cursor/Roo directory-based exporters.
scopegets mapped toglobswhenglobsisn't already set (since Claude calls them "globs" not "scope"). Nested rule IDs produce subdirectories (e.g.,api/auth→.claude/rules/api/auth.md).All existing tests updated, new tests added for the directory export/import and round-tripping.
Summary by CodeRabbit
New Features
Tests