Skip to content

feat: Add Claude Code rules output format support and set up CLI for additional format support in the future#6

Open
poiley wants to merge 1 commit into
mainfrom
feat/claude-code-format-awareness
Open

feat: Add Claude Code rules output format support and set up CLI for additional format support in the future#6
poiley wants to merge 1 commit into
mainfrom
feat/claude-code-format-awareness

Conversation

@poiley

@poiley poiley commented Aug 7, 2025

Copy link
Copy Markdown
Contributor

Overview

Implements Claude Code output format support by building a complete formatter architecture to replace the existing hardcoded Cursor format generation. This enables multi-IDE compatibility and extensible format support.

Technical Changes

New Formatter Architecture (rules_engine/formatters/)

Base Classes:

  • BaseFormatter: Abstract base class defining formatter interface with convert(), save(), and get_info() methods
  • FormatError: Custom exception class for formatter-specific errors

Concrete Implementations:

  • CursorFormatter: Refactored existing logic into formatter class, maintains .cursor/rules/*.mdc output with YAML frontmatter
  • ClaudeFormatter: New implementation generating CLAUDE.md with structured markdown sections

Management Layer:

  • FormatManager: Registry pattern with formatter discovery, validation, and batch processing
  • Plugin system foundation for third-party formatters via setuptools entry points

CLI Integration (rules_engine/cli.py)

Parameter Addition:

  • Added --output-format/-o click option with choices: cursor, claude, all, comma-separated lists
  • Format validation and error handling with descriptive messages
  • Backward compatibility: defaults to cursor when not specified

Architecture Changes:

  • Replaced inline format generation with FormatManager.convert_and_save()
  • Removed _legacy_save_rules_with_format() function and fallback mechanisms
  • Added _get_format_action_text() and _get_format_description() helpers for format-aware messaging
  • Updated all user prompts to use appropriate terminology per selected format

Format Specifications

Cursor Format (existing, now formalized):

.cursor/rules/
├── rule-001.mdc
├── rule-002.mdc
└── ...

File structure:

title: "Rule Title"
tags: ["tag1", "tag2"]
priority: "high"

Rule content here...

Claude Format (new):

CLAUDE.md Project Rules

Rule: Rule Title

Priority: high | Tags: tag1, tag2

Rule content here...

Core Logic Changes (rules_engine/analyzer.py)

  • Updated save_rules_with_format() to use new formatter architecture
  • Enhanced error handling and progress reporting
  • Maintained existing analysis pipeline while enabling multiple output formats

Usage

# Claude Code format (new)
rules-engine start -o claude /path/to/repo

# Cursor format (existing behavior)
rules-engine start -o cursor /path/to/repo
rules-engine start /path/to/repo  # default

# Multiple formats
rules-engine start -o cursor,claude /path/to/repo
rules-engine start -o all /path/to/repo

This commit addresses the Claude Code rules output format issue by implementing
format-aware messaging throughout the CLI and fixing Claude formatter bugs.

Key changes:
- Remove legacy _legacy_save_rules_with_format function and fallback mechanisms
- Fix ClaudeFormatter _convert_mdc_to_claude_section method to properly return formatted content
- Add _get_format_action_text() helper for format-specific user prompts
- Replace hardcoded Cursor-centric messages with format-aware alternatives
- Update all user-facing prompts to use appropriate format terminology
- Fix f-string syntax error in CLI prompt formatting

Technical details:
- Enhanced FormatManager to handle multiple output formats cleanly
- Improved error handling in formatter conversion methods
- Maintained backward compatibility for existing Cursor format workflows
- Added comprehensive formatter architecture with base classes and registry pattern

Fixes empty CLAUDE.md generation bug and ensures shell output matches selected format.

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

Co-Authored-By: Claude <noreply@anthropic.com>
@poiley poiley requested a review from etbyrd August 20, 2025 22:54
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