feat: use git root for consistent project name detection#1298
Open
Boltthecat19 wants to merge 1 commit intothedotmack:mainfrom
Open
feat: use git root for consistent project name detection#1298Boltthecat19 wants to merge 1 commit intothedotmack:mainfrom
Boltthecat19 wants to merge 1 commit intothedotmack:mainfrom
Conversation
getProjectName() previously used path.basename(cwd), which produces inconsistent project names when Claude is invoked from a subdirectory or from the home directory (e.g. project name becomes 'src' or 'derick'). Add findGitRoot() utility that walks up the directory tree to find the nearest .git entry (directory or file for worktrees), then use that directory name as the project identifier. Falls back to existing basename behavior for non-git directories. - src/utils/git-root.ts: new utility, walks cwd upward looking for .git - src/utils/project-name.ts: prefer git root name, fall back to basename - tests/utils/git-root.test.ts: 6 unit tests covering null, no-git, subdir, worktree - tests/utils/project-name.test.ts: 5 unit tests covering all branches All 11 new tests pass in isolation and with --no-parallel. Note: full suite shows 5 failures for getProjectName due to a pre-existing mock.module() leak in tests/hooks/context-reinjection-guard.test.ts:32 that affects parallel test workers. Tracked separately.
xkonjin
reviewed
Mar 8, 2026
xkonjin
left a comment
There was a problem hiding this comment.
Quick review pass:
- Main risk area here is input validation, path handling, and malformed payload behavior.
- Good to see test coverage move with the code; I’d still make sure it exercises the unhappy path around input validation, path handling, and malformed payload behavior rather than only the happy path.
- Before merge, I’d smoke-test the behavior touched by git-root.ts, project-name.ts, git-root.test.ts (+1 more) with malformed input / retry / rollback cases, since that’s where this class of change usually breaks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
getProjectName()usespath.basename(cwd)to identify the current project. This produces inconsistent names when Claude is invoked from a subdirectory — e.g. working inmy-project/src/utilsyields a project name ofutils, notmy-project. Running from the home directory yields the username.This causes observations and memory to be siloed under incorrect project names, breaking cross-session context.
Solution
Add a
findGitRoot()utility (src/utils/git-root.ts) that walks up the directory tree fromcwdlooking for a.gitentry (directory or file, to support worktrees). The git root directory name is used as the project identifier. Non-git directories fall back to the existingpath.basename(cwd)behavior.Changes
src/utils/git-root.ts— new utility, walks cwd upward to find.gitsrc/utils/project-name.ts— prefer git root name, fall back to basenametests/utils/git-root.test.ts— 6 unit tests: null input, no git, cwd root, subdirectory, worktree (.git file)tests/utils/project-name.test.ts— 5 unit tests covering all branchesTest Results
All 11 new tests pass in isolation and with
--no-parallel.