agent: Add commit message project rules toggle (#56867)

This follows up on discussion #56551.

Right now, when Zed generates a commit message, it includes project
rules files like `AGENTS.md`, `CLAUDE.md`, and `.rules` in the prompt
alongside the git diff. That can add a lot of extra context for a task
that is really just summarizing the changes in a commit.

This PR adds an `include_project_rules` option to
`agent.commit_message_model`. When it is set to `false`, Zed skips
loading project rules when generating commit messages. If the option is
omitted, the current behavior stays the same.

Example:

```json
   {
     "agent": {
       "commit_message_model": {
         "provider": "anthropic",
         "model": "claude-3-5-haiku",
         "include_project_rules": false
       }
     }
   }
 ```

I also updated the settings plumbing so this option is only used for commit message generation and defaults to true when not specified.

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

 Release Notes:

 - agent: Added setting to exclude project rules files from commit message generation prompts (`agent.commit_message_include_project_rules`)

---------

Co-authored-by: Bennet Bo Fenner <bennetbo@gmx.de>
This commit is contained in:
Lavi SharmaandBennet Bo Fenner authored and GitHub committed 2026-06-30 10:21:40 +00:00
1 parent 268186cd9a
commit 36a291b0e9
6 files changed
+31 -6

No files matched your search

+3
View File
@@ -1034,6 +1034,9 @@
"agent": {
// Whether the inline assistant should use streaming tools, when available
"inline_assistant_use_streaming_tools": true,
// Whether to include project rules files (AGENTS.md, CLAUDE.md, .rules, etc.)
// in the prompt when generating git commit messages.
"commit_message_include_project_rules": true,
// Whether the agent is enabled.
"enabled": true,
// Whether to show the agent panel button in the status bar.
+1
View File
@@ -580,6 +580,7 @@ mod tests {
inline_assistant_model: None,
inline_assistant_use_streaming_tools: false,
commit_message_model: None,
commit_message_include_project_rules: true,
commit_message_instructions: None,
thread_summary_model: None,
inline_alternatives: vec![],
@@ -216,6 +216,7 @@ pub struct AgentSettings {
pub inline_assistant_model: Option<LanguageModelSelection>,
pub inline_assistant_use_streaming_tools: bool,
pub commit_message_model: Option<LanguageModelSelection>,
pub commit_message_include_project_rules: bool,
pub commit_message_instructions: Option<String>,
pub thread_summary_model: Option<LanguageModelSelection>,
pub inline_alternatives: Vec<LanguageModelSelection>,
@@ -747,6 +748,9 @@ impl Settings for AgentSettings {
inline_assistant_use_streaming_tools: agent
.inline_assistant_use_streaming_tools
.unwrap_or(true),
commit_message_include_project_rules: agent
.commit_message_include_project_rules
.unwrap(),
commit_message_model: agent.commit_message_model,
commit_message_instructions: agent.commit_message_instructions,
thread_summary_model: agent.thread_summary_model,
+1
View File
@@ -993,6 +993,7 @@ mod tests {
inline_assistant_model: None,
inline_assistant_use_streaming_tools: false,
commit_message_model: None,
commit_message_include_project_rules: true,
commit_message_instructions: None,
thread_summary_model: None,
inline_alternatives: vec![],
+17 -6
View File
@@ -3041,6 +3041,10 @@ impl GitPanel {
});
let temperature = AgentSettings::temperature_for_model(&model, cx);
let include_project_rules =
AgentSettings::get_global(cx).commit_message_include_project_rules;
let instructions = AgentSettings::get_global(cx)
.commit_message_instructions
.clone();
@@ -3080,12 +3084,19 @@ impl GitPanel {
const MAX_DIFF_BYTES: usize = 20_000;
diff_text = Self::compress_commit_diff(&diff_text, MAX_DIFF_BYTES);
let rules_content =
Self::load_project_rules(&project, &repo_work_dir, &mut cx).await;
let user_agents_md = cx.update(|cx| {
UserAgentsMd::global(cx)
.and_then(|user_agents_md| user_agents_md.content().cloned())
});
let rules_content = if include_project_rules {
Self::load_project_rules(&project, &repo_work_dir, &mut cx).await
} else {
None
};
let user_agents_md = if include_project_rules {
cx.update(|cx| {
UserAgentsMd::global(cx)
.and_then(|user_agents_md| user_agents_md.content().cloned())
})
} else {
None
};
let prompt = include_str!("../src/commit_message_prompt.txt");
+5
View File
@@ -248,6 +248,11 @@ pub struct AgentSettingsContent {
pub inline_assistant_use_streaming_tools: Option<bool>,
/// Model to use for generating git commit messages. Defaults to default_model when not specified.
pub commit_message_model: Option<LanguageModelSelection>,
/// Whether to include project rules files (AGENTS.md, CLAUDE.md, .rules, etc.)
/// in the prompt when generating git commit messages.
///
/// Default: true
pub commit_message_include_project_rules: Option<bool>,
/// Custom instructions to include in the prompt when generating git commit messages.
/// Applied in addition to any project rules files (such as `.rules` or `AGENTS.md`).
pub commit_message_instructions: Option<String>,