codemap icon indicating copy to clipboard operation
codemap copied to clipboard

hygiene: codemap leaves .codemap/ state in every repo it touches, unignored and sometimes committed; agent worktrees pollute scans

Open JordanCoin opened this issue 3 months ago • 2 comments

Symptoms, measured 2026-09-04 on one machine

  • Every repository under that a hook or scan touched has a .codemap/ directory. In at least 10 repos it shows as untracked in git status because nothing ever added it to an ignore list.
  • In business-skills, .codemap/agent_edits.jsonl and .codemap/status were committed, and they change on every session, so every later commit carries state churn.
  • codemap . on this repo counted watch/testdata five times because agent worktrees under .claude/worktrees/ are scanned; that produced a wrong before/after figure in PR #179's original body.
  • The reputation this earns: "codemap leaves a lot behind."

Proposed fix

  1. State goes somewhere the repo does not see. Prefer a per-repo directory under the user cache ($XDG_CACHE_HOME/codemap/<hash of repo root>/), or, if the in-repo location must stay, write .codemap/ into .git/info/exclude on first use so it is ignored without touching a tracked .gitignore.
  2. codemap setup and codemap doctor report any tracked .codemap/* files and offer git rm --cached.
  3. Ignore .claude/worktrees/ and .git/ worktree checkouts by default in the walker, alongside vendor and testdata.
  4. Hooks must never create .codemap/ in a repo that has no codemap config and was only visited by a scan (e.g. a one-off codemap . in someone else's project).

Exit test

Fresh clone of any repo, run codemap ., run a session with hooks, then git status --porcelain is empty and codemap . file counts match git ls-files | wc -l modulo ignore rules.

Related: #179, #183, #172.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TcyheQmM3HCvxF5wRL3s5t

JordanCoin avatar Sep 04 '26 15:09 JordanCoin

The exit test here is now green on main via #198: a fresh clone of a repo with no codemap config, codemap ., and git status --porcelain is empty. The auto-written config from #189 stays, but whenever codemap creates .codemap/ in a checkout and nothing already ignores it, the rule goes to <git-common-dir>/info/exclude, never a tracked .gitignore. codemap doctor now reports already-committed .codemap/* files with the git rm -r --cached command, and nested worktrees under .claude/worktrees/ are skipped by the walker (#131).

Left open for the two remaining items: whether runtime state should move out of the repo entirely (an $XDG_CACHE_HOME/codemap/<hash>/ location), and the rule that hooks never create .codemap/ in a repo that has no codemap config.


Generated by Claude Code

JordanCoin avatar Oct 07 '26 03:10 JordanCoin

Will there be a migration feature, to auto move from non-cache to cache location?

reneleonhardt avatar Nov 15 '26 12:11 reneleonhardt