surshar / claude-code
Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.
Built by Anthropic · github.com/anthropics
| 1 | import type { InstructionFile } from 'claude-code' |
| 2 | |
| 3 | import Frames from '../frames' |
| 4 | import Names from '../names' |
| 5 | import { isProjectOwn } from './is-project-own.js' |
| 6 | import { projectDirOf } from './project-dir-of.js' |
| 7 | |
| 8 | /** |
| 9 | * Whether a handed instruction file is a CLAUDE.md, `.claude/CLAUDE.md` or |
| 10 | * CLAUDE.local.md of a directory on the walk down to the session's root. |
| 11 | * |
| 12 | * What makes a project "have a CLAUDE.md of its own" for |
| 13 | * `claude-md-or-agents-md`, the same files the Read walk asks for; a rules |
| 14 | * file, an imported file or an added directory's CLAUDE.md is not one. |
| 15 | * |
| 16 | * @param file the handed instruction file |
| 17 | * @param root the session's project root, absolute |
| 18 | * @returns true for the project's own CLAUDE.md files on the walk |
| 19 | */ |
| 20 | export function isClaudeFileOnWalk( |
| 21 | file: InstructionFile, |
| 22 | root: string, |
| 23 | ): boolean { |
| 24 | const isOwnClaudeFile = |
| 25 | isProjectOwn(file) && |
| 26 | file.parent === undefined && |
| 27 | Names.CLAUDE_NAMES.some(name => |
| 28 | Frames.normalSpellingOf(file.path).endsWith(`/${name}`), |
| 29 | ) |
| 30 | |
| 31 | if (!isOwnClaudeFile) { |
| 32 | return false |
| 33 | } |
| 34 | |
| 35 | const dir = projectDirOf(file.path) |
| 36 | const spelledRoot = Frames.normalSpellingOf(root) |
| 37 | |
| 38 | return dir === spelledRoot || Frames.isBelow(spelledRoot, dir) |
| 39 | } |