spacehub

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

claude-code / mods / agents-md / hooks / files / project-dir-of.ts
16 lines · 540 BRaw
1import Frames from '../frames'
2
3/**
4 * The project directory an instruction file speaks for: the directory
5 * holding it, or the one holding its `.claude` folder.
6 *
7 * @param path the file's path, absolute
8 * @returns the directory, in the walk's normal spelling
9 */
10export function projectDirOf(path: string): string {
11 const spelled = Frames.normalSpellingOf(path)
12 const claudeAt = spelled.lastIndexOf('/.claude/')
13 const cut = claudeAt === -1 ? spelled.lastIndexOf('/') : claudeAt
14
15 return cut <= 0 ? '/' : spelled.slice(0, cut)
16}