@@ -310,6 +310,35 @@ export class GitCommitRewriter {
310310 return redacted ;
311311 }
312312
313+ private findCommitMessageContext ( ) : string | null {
314+ // Search for COMMIT_MESSAGE.md in order of priority:
315+ // 1. Current root directory
316+ // 2. .git directory
317+ // 3. .github directory
318+ const searchPaths = [
319+ path . join ( process . cwd ( ) , 'COMMIT_MESSAGE.md' ) ,
320+ path . join ( process . cwd ( ) , '.git' , 'COMMIT_MESSAGE.md' ) ,
321+ path . join ( process . cwd ( ) , '.github' , 'COMMIT_MESSAGE.md' ) ,
322+ ] ;
323+
324+ for ( const filePath of searchPaths ) {
325+ try {
326+ if ( fs . existsSync ( filePath ) ) {
327+ const content = fs . readFileSync ( filePath , 'utf-8' ) ;
328+ if ( this . options . verbose && ! this . options . quiet ) {
329+ console . log ( chalk . blue ( `📝 Found custom commit message context at: ${ path . relative ( process . cwd ( ) , filePath ) } ` ) ) ;
330+ }
331+ return content . trim ( ) ;
332+ }
333+ } catch ( error ) {
334+ // Continue searching if file can't be read
335+ continue ;
336+ }
337+ }
338+
339+ return null ;
340+ }
341+
313342 private async generateCommitMessage (
314343 diff : string ,
315344 files : string [ ] ,
@@ -319,6 +348,9 @@ export class GitCommitRewriter {
319348 // Redact sensitive data from diff before sending to AI provider
320349 const redactedDiff = this . redactSensitivePatterns ( diff ) ;
321350
351+ // Look for custom commit message context
352+ const customContext = this . findCommitMessageContext ( ) ;
353+
322354 let formatInstructions = '' ;
323355
324356 if ( this . options . template ) {
@@ -350,7 +382,7 @@ Example: If template is "[JIRA-XXX] type: message", generate something like "[JI
350382 // User provided custom prompt - use it with basic context
351383 prompt = `You are a git commit message generator. Analyze the following git diff and file changes, then ${ this . options . prompt }
352384
353- Old commit message: "${ oldMessage } "
385+ ${ customContext ? `Project-specific guidelines:\n ${ customContext } \n\n` : '' } Old commit message: "${ oldMessage } "
354386
355387Files changed:
356388${ files . join ( '\n' ) }
@@ -366,7 +398,7 @@ Return ONLY the commit message, nothing else.`;
366398 // Use default prompt with all standard instructions
367399 prompt = `You are a git commit message generator. Analyze the following git diff and file changes, then generate a clear, concise commit message.
368400
369- Old commit message: "${ oldMessage } "
401+ ${ customContext ? `Project-specific guidelines:\n ${ customContext } \n\n` : '' } Old commit message: "${ oldMessage } "
370402
371403Files changed:
372404${ files . join ( '\n' ) }
0 commit comments