style.ts
1 import { existsSync, readFileSync } from 'fs' 2 import { join, parse, dirname } from 'path' 3 import { memoize } from 'lodash-es' 4 import { getCwd } from './state.js' 5 6 const STYLE_PROMPT = 7 'The codebase follows strict style guidelines shown below. All code changes must strictly adhere to these guidelines to maintain consistency and quality.' 8 9 export const getCodeStyle = memoize((): string => { 10 const styles: string[] = [] 11 let currentDir = getCwd() 12 13 while (currentDir !== parse(currentDir).root) { 14 const stylePath = join(currentDir, 'CLAUDE.md') 15 if (existsSync(stylePath)) { 16 styles.push( 17 `Contents of ${stylePath}:\n\n${readFileSync(stylePath, 'utf-8')}`, 18 ) 19 } 20 currentDir = dirname(currentDir) 21 } 22 23 if (styles.length === 0) { 24 return '' 25 } 26 27 return `${STYLE_PROMPT}\n\n${styles.reverse().join('\n\n')}` 28 })