Skip to content

fix: prepend YAML frontmatter to Cursor .mdc files#1699

Open
fsilvaortiz wants to merge 1 commit intogithub:mainfrom
fsilvaortiz:fix/cursor-mdc-frontmatter
Open

fix: prepend YAML frontmatter to Cursor .mdc files#1699
fsilvaortiz wants to merge 1 commit intogithub:mainfrom
fsilvaortiz:fix/cursor-mdc-frontmatter

Conversation

@fsilvaortiz
Copy link

Summary

  • Cursor IDE requires YAML frontmatter (alwaysApply: true) in .mdc rule files for auto-inclusion — without it, rules are silently ignored
  • Adds frontmatter generation to both scripts/bash/update-agent-context.sh and scripts/powershell/update-agent-context.ps1
  • Handles all three scenarios: new file creation, existing file without frontmatter, and existing file with frontmatter (no duplication)

Closes #669

Changes

  • scripts/bash/update-agent-context.sh: Added frontmatter prepend in create_new_agent_file() and update_existing_agent_file()
  • scripts/powershell/update-agent-context.ps1: Added frontmatter prepend in New-AgentFile and Update-ExistingAgentFile
  • tests/test_cursor_frontmatter.py: 7 new tests (3 static analysis + 4 integration)

Test plan

  • Static analysis: bash script contains .mdc frontmatter logic in both functions
  • Static analysis: PowerShell script contains .mdc frontmatter logic in both functions
  • Integration: new .mdc file starts with valid YAML frontmatter (---, alwaysApply: true, ---)
  • Integration: existing .mdc file without frontmatter gets it prepended on update
  • Integration: existing .mdc file with frontmatter does NOT get duplicated
  • Integration: non-.mdc files (e.g., Claude's CLAUDE.md) are NOT affected
  • Full test suite passes (102 tests)

🤖 Generated with Claude Code

Cursor IDE requires YAML frontmatter with `alwaysApply: true` in .mdc
rule files for them to be automatically loaded. Without this frontmatter,
users must manually configure glob patterns for the rules to take effect.

This fix adds frontmatter generation to both the bash and PowerShell
update-agent-context scripts, handling three scenarios:
- New .mdc file creation (frontmatter prepended after template processing)
- Existing .mdc file update without frontmatter (frontmatter added)
- Existing .mdc file with frontmatter (no duplication)

Closes github#669

🤖 Generated with [Claude Code](https://claude.com/code)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

Fix specify-rules.mdc format for Cursor IDE

1 participant