Skip to content

Latest commit

 

History

History

codebase-mapper

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

README.md

codebase-mapper

A map of your codebase that Claude Code loads by itself. The map is plain rules files in your project, so a teammate who never installed this plugin still gets it.

claude plugin marketplace add Eigenwise/eigenwise-toolshed
claude plugin install codebase-mapper@eigenwise-toolshed

What you get

.claude/rules/codebase-map.md     the index: what the system is, the areas, the key flows
.claude/rules/map/<area>.md       one card per area
.claude/rules/guides/<name>.md    only when an older map held hand-written guidance: copied, never rewritten

The index has no paths frontmatter, so it is always loaded, and it comes back after a compaction. It stays under 40 lines, the last one saying how to edit a card by hand.

A card has paths frontmatter with the globs of its area. Claude Code loads it the first time a file in that area is touched. Cards stay under 2.5 KB. Each one records verified-at: <commit sha>, the commit it was last checked against.

The map keeps itself current: a session working in an area that changed checks that card against the diff by itself and asks you nothing. No process runs per tool call; one background process runs at session start, after a refresh at each main turn end until the agents it started have reported (40 at most), and once more at a main turn end after a commit or a branch switch, and only where the card folder .claude/rules/map exists. CLAUDE.md is never touched.

Skills

map creates the map. It investigates first, reading the repo itself or, for a large one, sending read-only scouts in parallel (routed to the cheap tier when Sidequest is installed, plain Explore agents otherwise). Then it proposes the areas and key flows in one message, with a recommended answer, and you confirm or correct. Only then does it write the index and cards and show you the diff. For a new project it asks two or three questions and writes a lean starting map.

refresh is the full pass, when you ask for one. For each card whose area changed it reads the diff since the card's last check and compares the card's claims with it: a card that still holds gets its check recorded, a line that no longer holds is edited and verified-at moved. A card that cannot be checked that way (no usable stamp, or a diff too large to read) is re-derived from the code. It shows the diff. Both skills leave the files in your working tree and never commit. Subagents never write the map.

What changed since a card was last checked

scripts/map-status.mjs needs only Node and git. For each card it counts the commits under that card's globs since a starting commit, with the files each one changed there:

git log --no-merges --name-only <starting commit>..HEAD -- <globs>

A commit that changes only dependency manifests, lockfiles or tests inside the area is not counted, even when it changes a manifest's scripts or entry point. The list is built in, with no setting: the common package managers' files (package.json, yarn.lock, go.sum and the like), anything under a test, tests, __tests__, __snapshots__, spec or testdata folder, and code files named like *.test.ts, *_test.go or test_*.py. The cost: a card that names library versions or describes the test layout can drift unseen, and a card whose whole area is such files never reads as changed.

A card has changes since its last check by every commit under its globs since its stamp that did not also change the card file, so a card changed together with its area stays fresh however it lands, by merge, squash or rebase. A refresh moves verified-at to HEAD, and the stamp vouches for everything before it, even before the stamp is committed. Fixing a card's wording or renaming it vouches for nothing. When the stamp is a commit that is not on this history (a branch commit that was squashed or rebased away), the check counts from the last commit that moved the stamp, so two clones agree. A commit id this clone does not hold is counted the same way, with a reason. A card with no stamp, or a stamp that cannot be a commit id, cannot be checked: it says why in reason and nothing is counted, even when an earlier commit of the card held one. One case stays hidden: a stamp from a branch commit that was squashed away, plus a teammate's change to the area made while that branch was open, reads fresh.

Because each card has its own commit and its own globs, checking one card never vouches for another.

A check that changed nothing needs no commit. The plugin's record_check tool writes the card and the commit it was checked up to into .claude/codebase-mapper/checked.json, on this machine only, in a folder that keeps itself out of git, and the count starts from whichever is later in history: the stamp or that record. A recorded commit this history does not hold is ignored. The tool is the plugin's own code, so it asks nobody; a subagent's call is refused.

A card with commits also carries what the fast check needs, so nobody has to guess: since (the commit to compare from), diffStatCommand and diffCommand (git diff [--stat] <since>..HEAD -- <its paths>, with the card's patterns written as git pathspecs). Both are null for a card with more than 12 patterns. The status value stays stale in the JSON for a card with changes and for one that cannot be checked; changed and unusable count the two, and the line says each in its own words.

The check runs from the folder that holds .claude, found by walking up from the working directory (or --root) to the git top level, so a project in a subfolder of a larger repository is judged by its own commits.

It also reports cards whose globs match no file, cards with a ./ pattern (the host never loads it, and nothing is counted for it), cards over 2.5 KB (oversize, the same on every checkout whatever its line endings), and cards whose index file .claude/rules/codebase-map.md is gone (indexMissing). The one-line summary names each of these, so a map with any of them never reads as up to date.

node plugins/codebase-mapper/scripts/map-status.mjs            # JSON
node plugins/codebase-mapper/scripts/map-status.mjs --line     # a one-line summary, such as: Codebase map: 2 of 7 areas changed since their last check.
node plugins/codebase-mapper/scripts/map-status.mjs --root <dir>

The check hands each pattern to git as a glob pathspec, so negation is not read. Braces are: Claude Code expands them, and the check does the same before git sees the pattern, so src/**/*.{ts,tsx} is checked as src/**/*.ts and src/**/*.tsx. Braces with no comma inside stay as written, and so does a pattern that would become more than 256 patterns. Claude Code reads a card's paths from the folder that holds its .claude folder, and the status check reads them the same way: a name with no slash (README.md, *.md) loads at any depth, and a leading slash (/README.md) means that top folder only.

The session line

The hooks run in-process from one module. At session start, where the card folder exists, they start the status script in the background, never waiting for it.

When areas changed since their last check, the session reads one line beside the first prompt you type after the script finished. It names up to three areas, each with the commit to diff from, and tells the session: before you rely on one of these cards or work in its area, check it with git diff; every claim holds, record it with record_check; correct a card only where a claim no longer holds and move its stamp; never ask the person. It also says that a card which still holds is recorded and nothing is committed for it, and that no commit is made only to move a verified-at. A prompt before the script finished goes in without it, a session that draws nowhere (claude -p) gets nothing, and a /codebase-mapper: command drops it. Areas nobody works in stay unchecked and cost nothing.

After the session's own commit (or a branch switch or a pull) the same check runs again, and when it shows areas the session was not told about, its next prompt carries one short line naming only those: the card still holds, so call record_check, no commit and no stamp edit; a claim no longer holds, so correct that line in the commit that changes the area. It is given once per set of newly changed areas, never when nothing new changed, and never to you. Where the project's index lacks the current sentence about keeping a card up, either line adds that the index's line is missing or old and that the next change that edits a card may bring it up to date in the same commit. The plugin never writes the index: it is a tracked file.

You see a line under the prompt only for what no session can put right on its own: the status check could not run, or a card cannot be checked at all (no usable verified-at or paths). It says so in plain words. It is computed at session start, at main turn ends after a refresh until its agents have reported (40 at most), and at a main turn end after a commit or a branch switch, seen in the files under .git with no process when nothing moved. Only the newest computation sets it; with nothing to say it is cleared.

In a team

The map is committed like code. Everyone who clones the repository gets it, with or without this plugin, because Claude Code loads rules files by itself.

  • Who keeps a card up. The session that works in an area. The index tells every session, with or without the plugin, to check the card against git diff <verified-at> -- <its paths>, correct only a line that no longer holds and move verified-at to HEAD in the same commit as its change. A card that still holds stays as it is; with the plugin the check is recorded on that machine. No stamp-only commits: a commit whose only purpose is to move verified-at is never needed, because the stamp does not have to name the commit it sits in, and a commit that changes an area and its card together already reads as checked. A stamp is never moved on a card nobody checked.
  • What Claude Code asks. In the default permission mode Claude Code asks before a file under .claude/ is edited, so you are asked when a card is corrected. That is why a session corrects a card only when a claim no longer holds. A check that changed nothing asks nothing.
  • When. In the change that makes the card untrue. A card changed in the same commit as its area reads fresh once that commit lands, by merge, squash or rebase.
  • Nothing forces it. No hook holds up a commit or a turn over a changed card, and nobody sees a warning about one. A card stays a few commits behind until someone works in that area again.
  • Conflicts. Different areas never conflict: each card is its own file. Two people who refresh the same card do, at least on its verified-at line. The way out is to take either side and refresh that card.

Keeping the map current from CI

In most teams the session that works in an area keeps its card up, and that is enough. A scheduled job is for a team where cards keep colliding because many branches touch them at once, or where few people run the plugin. It runs the refresh on a clean checkout and opens one pull request with the cards it corrected.

name: Codebase map
on:
  schedule:
    - cron: "0 6 * * 1"
  workflow_dispatch:
jobs:
  refresh:
    runs-on: ubuntu-latest
    permissions:
      contents: write
      pull-requests: write
      id-token: write
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - uses: anthropics/claude-code-action@v1
        with:
          anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
          plugin_marketplaces: "https://github.com/Eigenwise/eigenwise-toolshed.git"
          plugins: "codebase-mapper@eigenwise-toolshed"
          prompt: "/codebase-mapper:refresh Correct the cards only. Do not commit and do not push."
          claude_args: "--permission-mode bypassPermissions --max-turns 30"
      - name: Open a pull request when a card changed
        env:
          GH_TOKEN: ${{ github.token }}
        run: |
          git diff --quiet -- .claude/rules && exit 0
          git config user.name "github-actions[bot]"
          git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
          git switch -c "codebase-map-${{ github.run_id }}"
          git add .claude/rules
          git commit -m "Bring the codebase map in line with the code"
          git push origin HEAD
          gh pr create --fill --base "${{ github.event.repository.default_branch }}"
  • The whole history. fetch-depth: 0 is required. The map counts commits since each card's verified-at, and a shallow checkout does not hold those commits.
  • The plugin comes from the action's inputs. plugin_marketplaces and plugins install it for the run. A job does not take plugins from the repository's own settings.
  • The permission mode. Claude Code protects the .claude/ folder: in an unattended run it refuses to edit a card under .claude/rules/ in every mode but bypassPermissions, also when an allow rule names the folder. A throwaway runner is where that mode belongs. What the run can reach is set by the job's permissions block and by --max-turns.
  • Signing in. ANTHROPIC_API_KEY is an API key, billed as API usage, and the right choice for a secret a team shares. With a Claude subscription, run claude setup-token once, store the token it prints as the secret CLAUDE_CODE_OAUTH_TOKEN and pass it as claude_code_oauth_token instead; that token belongs to the person who made it and the runs count against their plan. The action also signs in through Bedrock, Vertex or Foundry with its use_bedrock, use_vertex and use_foundry inputs.
  • The pull request. Claude only corrects the cards; the last step commits them and opens the pull request, and does nothing when no card changed. The repository setting "Allow GitHub Actions to create and approve pull requests" has to be on. A pull request opened with the job's own token does not start other workflows.

What it does not do

No acknowledgment line, no Stop hook, no per-turn documentation check, no hash manifest, no warning about changed areas, no full refresh nobody asked for. A card changes only when a session found a claim on it that no longer holds, or when you run refresh.

Moving from an older map

Where .claude/.codebase-info/ exists and this map does not, the first session in that project says once that the older map is not used and that /codebase-mapper:map builds a new one from it. When Quartermaster is installed it says it instead.

Older versions kept the map in .claude/.codebase-info/ and injected it with hooks. Run map in that project. It reads the old documents as source material, checks what it uses against the code, and writes the new index and cards. It then asks whether to delete .claude/.codebase-info/, and removes it only on a yes. Not everything in an old map describes code. A style guide, a how-to or an evaluation guide that someone wrote by hand never goes on a card, because refresh rewrites a card from the code and would erase it. map copies each such document to .claude/rules/guides/<name>.md, in its own words, with paths for the files it is about, and refresh never touches that folder. Lessons and incident notes go to your memory when the map is your own, and into a guide when git tracks the map, so the team keeps them. map ends by listing every old document and where it went.

Where git tracks the old folder, the map is the team's, so move it for everyone in one commit: the new index and cards and the old folder removed. The plugin key in the committed settings needs no edit: keep it for map and refresh, or take it out. The cards are plain rules files, so they load with the plugin off or never installed. Until that commit merges, a teammate on this version has no map, and one person's own copy drifts from the team's. After the merge a teammate needs to install nothing. A branch that still edits a file in the old folder gets a conflict when it merges the move, and puts that fact on the card instead.

Check it

From a checkout of this repository. An installed copy has the same script in its install folder, and the skills run it for you.

claude plugin validate plugins/codebase-mapper
claude plugin test plugins/codebase-mapper
node --test plugins/codebase-mapper/scripts/map-status.test.mjs