mirror of
https://github.com/Egonex-AI/Understand-Anything.git
synced 2026-06-22 10:58:03 +08:00
When /understand or /understand-domain runs from a CWD inside an ephemeral git worktree (the default for parallel-agent / isolation sessions), every output file goes to the worktree path. Claude Code deletes the worktree on session end, taking knowledge-graph.json, domain-graph.json, meta.json, intermediate batches and ~hundreds of K of analysis tokens with it. Resolve PROJECT_ROOT through a worktree check before any output: compare git rev-parse --git-dir against --git-common-dir; in a normal checkout (and in a submodule) they're the same path, in a worktree they differ and parent(--git-common-dir) is the main repo root. UNDERSTAND_NO_WORKTREE_REDIRECT=1 opts out for the rare per-worktree case. - skills/understand/SKILL.md Phase 0 step 1: add the redirect after PROJECT_ROOT is set from $ARGUMENTS or CWD, so an explicit arg path is also rescued from a worktree but can be opted out of. - skills/understand-domain/SKILL.md: add an explicit Phase 0 (it previously inferred "current project" implicitly), then thread $PROJECT_ROOT through Phases 2-5 so subsequent steps honor the redirect. - New worktree-redirect.test.mjs: 5 vitest cases covering main repo, worktree root, worktree subdir, opt-out env var, and non-git CWD. Mirrors the bash snippet inline (no shared lib in this repo). Submodule false-positive ruled out by probe — submodules see git-dir == git-common-dir (both point at <super>/.git/modules/<name>).