Skip to content

Add configurable commit message styles#2

Open
camUrban wants to merge 1 commit intoJohannLai:mainfrom
camUrban:feature/style_configuration
Open

Add configurable commit message styles#2
camUrban wants to merge 1 commit intoJohannLai:mainfrom
camUrban:feature/style_configuration

Conversation

@camUrban
Copy link
Copy Markdown

@camUrban camUrban commented Mar 4, 2026

Summary

  • Add a style system that lets users configure commit message formats (e.g., conventional commits, simple) instead of relying solely on git history auto-detection
  • Ship two built-in styles (conventional and simple) and support user-created custom styles stored in ~/.claude-commit/styles/
  • Add claude-commit style sub-command for managing styles (list, show, set, clear, create, delete) and a --style CLI flag for per-run overrides

Changes

  • config.py: Add style management methods: get/set/clear default style, list available styles (bundled+user), read style content, and create/delete custom styles
  • main.py: Wire style system into commit generation: resolve style from CLI flag or config, inject style instructions into the system prompt, and skip git history detection when a style is active. Add style sub-command handler and
    --style/-s argument
  • styles/conventional.txt: Built-in conventional commits style definition
  • styles/simple.txt: Built-in simple/plain style definition
  • pyproject.toml: Include styles/*.txt as package data

- Add style management subcommand (list, show, set, clear, create, delete)
- Bundle conventional and simple built-in style templates
- Support --style CLI flag for one-off style override
- Allow user-defined custom styles in ~/.claude-commit/styles/
- Style instructions override auto-detection from git history
@camUrban camUrban changed the title feat: add configurable commit message styles Add configurable commit message styles Mar 4, 2026
Copy link
Copy Markdown
Owner

@JohannLai JohannLai left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! The style system is a nice feature — clean API design with good layering (CLI flag > config default > auto-detect). A few things to address before merging:


Bug: console.print() with file=sys.stderr

In main(), the style-not-found error block uses:

console.print(f"[red]❌ Style '{style_name}' not found.[/red]", file=sys.stderr)
console.print("[yellow]   Run ...[/yellow]", file=sys.stderr)

Rich's Console.print() does not accept a file keyword — this will raise a TypeError at runtime. Should use error_console.print() instead (which is already configured with stderr=True).

Inconsistency: get_user_styles_dir() ignores custom config_path

Config.__init__ accepts a config_path parameter (used heavily in tests), but get_user_styles_dir() hardcodes Path.home() / ".claude-commit" / "styles". This means tests that use tmp_path for config will still read/write styles from the real home directory.

Suggest deriving from self.config_path.parent:

def get_user_styles_dir(self) -> Path:
    return self.config_path.parent / "styles"

Missing tests

The project now has a test suite (tests/). This PR should include tests for the new config methods (get_style, set_style, clear_style, list_styles, create_custom_style, delete_custom_style) and the handle_style_command function. Most of these are pure logic and straightforward to test.

Minor: handle_style_command doesn't use error_console

handle_alias_command uses print(..., file=sys.stderr) for errors (which works), but for consistency with the rest of the codebase you might want to keep the same pattern. Not a blocker.


Overall the design is solid — the style override injection into the system prompt and the conditional step1 logic both make sense. Just the file=sys.stderr bug needs fixing before merge.

@JohannLai
Copy link
Copy Markdown
Owner

Also, sorry about the conflicts — I recently added a test suite and refactored some helpers in main.py, which will likely require rebasing your branch. Apologies for the extra work! 🙏

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.

2 participants