commitlint guidance
What is the guidance for getting the "dyanmic LLM" commit generation to work well with commitlint without hardcoding the commitlint settings? i tell it to read the commitlint config but it always ends up failing to generate the correct commit message that actually passes the rules and then gives up.
Thanks for reaching out! This looks like a usage question rather than a bug report.
The key insight is that the LLM command only receives the prompt via stdin — it can't read files from your repo (like a commitlint config) unless you include that information directly in the prompt template.
The recommended approach is to use a custom prompt template that embeds your commitlint rules. In your ~/.config/worktrunk/config.toml (or project wt.toml):
[commit.generation]
command = "llm -m claude-haiku-4.5" # or your preferred LLM command
template = """
Write a commit message for the staged changes below.
<format>
- Follow conventional commits: type(scope): description
- Valid types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
- Subject line under 72 chars
- Scope is optional but encouraged
- Output only the commit message, no quotes or code blocks
</format>
<style>
- Imperative mood: "Add feature" not "Added feature"
- Lowercase subject after the colon
- No period at the end of the subject line
</style>
<diffstat>
{{ git_diff_stat }}
</diffstat>
<diff>
{{ git_diff }}
</diff>
<context>
Branch: {{ branch }}
{% if recent_commits %}<recent_commits>
{% for commit in recent_commits %}- {{ commit }}
{% endfor %}</recent_commits>{% endif %}
</context>
"""
squash-template = """
Combine these commits into a single commit message.
<format>
- Follow conventional commits: type(scope): description
- Valid types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
- Subject line under 72 chars
- Scope is optional but encouraged
- For material changes, add a blank line then a body paragraph
- Output only the commit message, no quotes or code blocks
</format>
<commits branch="{{ branch }}" target="{{ target_branch }}">
{% for commit in commits %}- {{ commit }}
{% endfor %}</commits>
<diffstat>
{{ git_diff_stat }}
</diffstat>
<diff>
{{ git_diff }}
</diff>
"""
Replace the type/scope rules with whatever your commitlint config enforces. The idea is to be explicit and concrete in the template — list the exact valid types, scopes, and formatting rules rather than referencing an external config the LLM can't access.
See the Prompt templates section of the docs for all available template variables and syntax.
A maintainer can provide more detail if needed.
it always ends up failing to generate the correct commit message that actually passes the rules and then gives up.
what's the workflow of commitlint? is it a hook that returns an error when the commit attempts to commit?
i tell it to read the commitlint config
what tool are you using?
the default settings remove any system prompt etc, so it's mostly just a request-response, no opportunities to go and find files
it always ends up failing to generate the correct commit message that actually passes the rules and then gives up.
what's the workflow of
commitlint? is it a hook that returns an error when the commit attempts to commit?i tell it to read the commitlint config
what tool are you using?
the default settings remove any system prompt etc, so it's mostly just a request-response, no opportunities to go and find files
im using lint staged so yeah its a hook that returns error
The bot gave a really nice response wow. even had the prompt engineering xml tags too. ima try that out
another option, if you care more about the accuracy than the speed, is to use claude -p and remove the options removing the system prompt from our default options — and instead actually tell it to read the commitlint config. But it will be much slower once it starts thinking and reading files etc.
let us know how you get on; I imagine others will find your experience valuable!