Repository navigation
Description
Problem
After #687 made basename(git rev-parse --show-toplevel) the default project key, two failure modes remain:
- Basename collisions —
~/work/utils(github.com/acme/utils) and~/clients/foo/utils(github.com/foo/utils) both resolve toutilsand silently share memory. - Cross-machine fragmentation — a single agentmemory pod serving multiple MCP clients sees the same repo as different projects when contributor checkouts differ in basename. Concrete shape: central pod at
/srv/projects/foo, dev box at/home/<user>/src/foo, or simplyfoo-prodvsfooon a fork.AGENTMEMORY_PROJECT_NAMEworks around this but requires per-machine config for what is intrinsic to the repo.
Both fall away once the resolver consults remote.origin.url — the same identity src/hooks/post-commit.ts:65 already uses for commit attribution.
Proposal
Insert one step between the env override and the toplevel-basename fallback:
AGENTMEMORY_PROJECT_NAME
→ canonical(git config --get remote.origin.url)
→ basename(git rev-parse --show-toplevel) ← #687, unchanged
→ basename(cwd) ← unchanged
canonical produces host/owner/repo:
| Input | Output |
|---|---|
https://github.com/acme/widgets.git |
github.com/acme/widgets |
git@github.com:Acme/Widgets.git |
github.com/acme/widgets |
ssh://git@host.example:2222/acme/widgets.git |
host.example/acme/widgets |
https://user:token@github.com/acme/widgets |
github.com/acme/widgets |
Lowercased end-to-end (host providers treat owner/repo case-insensitively; preserving path case would re-fragment same-repo clones). Trailing .git stripped, credentials stripped. Unparseable remotes fall through to basename.
Why this and not #530
#530 proposed canonicalization plus multi-key matching across canonical/cwd/worktree-top/main-root/aliases. This issue keeps the single-key partitioning #687 just shipped — the change is where the key comes from, not how it's matched. No migration of existing data; deployments that already set AGENTMEMORY_PROJECT_NAME see no behavior change.
Non-goals
- Monorepo sub-package partitioning. Every package under
github.com/acme/monoreporesolves to the same key by design — partitioning within a monorepo is an orthogonal concern (theprojectaxis isn't the right one for it). Operators who need per-package memory continue to setAGENTMEMORY_PROJECT_NAMEper-package. - Multi-remote awareness (forks).
originis sufficient for the two failure modes above.AGENTMEMORY_PROJECT_NAMEremains the override for fork workflows that need to point atupstream. - SSH config aliases,
insteadOfrewrites. Resolver consumes the raw URL git emits; if a contributor configures an alias differently across machines, that's the same class of problem as setting different env vars and is solved by the same escape hatch.
Performance
One git config --get remote.origin.url invocation, capped at 500ms (same budget the rest of _project.ts already uses). Same shape as #530's tightened lookup discussed by @rockarxiv on that PR.
Patch shape
~60 LOC in src/hooks/_project.ts, 12 new unit tests, full suite (1303 tests) green. Happy to discuss the approach before opening the PR if there's a different shape you'd prefer; otherwise the PR will follow.
Activity
garyelephant commentedon May 30, 2026
This is very useful for me to use agentmemory across multi agent, claude, codex, opencode to keep consistent project name, I think your proposal should be a standard for project name.
garyelephant commentedon Jun 3, 2026
Hi @rohitg00 , what do you think about this, can this proposal and impl be accepted ?
thekoma commentedon Jun 6, 2026
Consolidating the project-identity work. Several open PRs now propose the same fix. Let's give @rohitg00 one direction instead of three competing diffs.
The cluster:
remote.origin.url→host/owner/repo, single-key, always-on, ~60 LOC in_project.ts.AGENTMEMORY_PROJECT_FROM_REMOTEflag, plus abackfill-project-identity.mjsmigration and MCP wiring.We agree on three things already: keep #687's single-key partitioning, source the key from the canonical remote (
host/owner/repo, lowercased, credentials and.gitstripped), and fall through to toplevel-basename then cwd when no remote parses.One decision stays open: migration. Switching the key from
agentmemorytogithub.com/rohitg00/agentmemoryorphans every existing basename-keyed row, which breaks auto-context and the rolling project profile (see the analysis in #733). #717 ships always-on with no migration. #738 already covers this with the flag and the backfill. That gap shouldn't fork the work.Proposed synthesis:
@devon3000 I'll fold #717 into this and co-own whatever shape wins. @rohitg00 does single-key + canonical-remote + backfill match your plan, and do you want a flag or a clean default flip?
rohitg00 commentedon Jun 6, 2026
Bug is real and worth fixing. The part that needs more care is default-on without migration. Anyone on v0.9.x has memory keyed by basename, and orphaning that data on upgrade is something I want to avoid even when the new key is more correct.
Preferred direction:
AGENTMEMORY_PROJECT_FROM_REMOTE=1) for a release or two so users can migrate on their own schedule.memory_savescope-defaulting. Separate seams, separate PRs.#738 has roughly that shape (flag + backfill) but bundles the scope-default change. #717 has the cleaner identity-resolver code but ships without migration. #829 is project isolation enforcement and stays on its own track.
Could the two of you regroup on a single PR that takes #717's resolver + tests, gates it behind the opt-in flag, and ships #738's backfill alongside? The
memory_savechange can land separately. I'll review once it's in that shape.Durocks commentedon Jun 6, 2026
Let me add a little more context of what I think is the right direction. I'm using this logic in my branch and honestly it's saving me a lot of headaches trying to set the right variables in the MCP settings and plugins.
The way it works is simple. The AGENTMEMORY_PROJECT_ISOLATION variable is set to true by default. When set to true, the project variable becomes mandatory and the MCP instructs the AI to include the variable, failing with a 400 error if not provided. And if AGENTMEMORY_PROJECT_NAME is not passed (Even better if it's not passed, as it's less effort from the user part and less bugs with harness' MCP settings), The MCP tells the AI that the project variable should be set to the name of the folder of the project. Simple as that. It's been working great on my branch to be honest.
Pretty much my solution involves no work from the user since by default the isolation is set to true and it relies on the AI to decide what the project variable should be set to, which most times it will accurately get right if the instruction is correct. By default, it will set the project variable to the name of the folder of the project. I thought about using other values like the path or a code or a URL but all of them will present issues if you migrate or move the project or involve work from the user having to set those variables which honestly I think is not worth it.
(From here, it's written with AI)
Standardized Project Scoping Logic
To ensure a consistent and predictable foundation, I have defined the logic for all four combinations of project isolation (
AGENTMEMORY_PROJECT_ISOLATION) and project naming.AGENTMEMORY_PROJECT_ISOLATIONfalsefalsefalse, the system ignores the project name and treats memory as global (unscoped).truetruetrue, and the project is explicitly locked to the provided name.Why this is the right direction:
AGENTMEMORY_PROJECT_ISOLATION=truethe default and having the MCP error message instruct the AI to use the folder basename, I remove the need for manual configuration. The AI learns the expectation instantly via the error feedback loop.falseif they require legacy, global memory behavior.Visualization
graph TD classDef default fill:#f9f9f9,stroke:#333,stroke-width:1px; classDef highlight fill:#e1f5fe,stroke:#01579b,stroke-width:2px; Start[Receive Request] --> CheckIsolation{AGENTMEMORY_PROJECT_ISOLATION is true?} CheckIsolation -- false (It's true by default, so it needs to be explicitaly passed as false. This would be an uncommon case) --> Global[Treat as Global/Unscoped] CheckIsolation -- true --> CheckProject{Project Name Passed?} CheckProject -- true --> Strict[Strictly Scoped by Project Name] CheckProject -- false --> TeachAI[Instruct AI to use folder basename, reject if nothing is passed] Global --> End[Process Request] Strict --> End TeachAI --> End class Global,Strict,TeachAI highlight;This model ensures that the "Common Case" creates a self-healing loop where the AI learns the expected project name through standard error feedback, while the other combinations provide predictable global or strict isolation overrides.
devon3000 commentedon Jun 6, 2026
@Durocks if I'm not mistaken, you propose to postpone resolution by the canonical remote URL? That's actually the single most important use case for me, and per @thekoma we agree on the need for this.
I think the emphasis on AGENTMEMORY_PROJECT_NAME may be misplaced. AGENTMEMORY_PROJECT_NAME requires manual configuration, which is less than ideal. I think users shouldn't have to set AGENTMEMORY_PROJECT_NAME at all unless they need to somehow force unification or separation of projects that would otherwise be resolved as the same.
I suspect there are two different user intents at work here, which perhaps suggests two different flags.
AGENTMEMORY_PROJECT_NAME_FROM_REMOTE would resolve the project name from the remote git URL (if available) rather than the local filepath. Personally I think this should default to true although there would be migration issues with that.
AGENTMEMORY_PROJECT_ISOLATION would control whether different clients using the same project name share a single memory system. This should default to false.
Durocks commentedon Jun 6, 2026
@devon3000 to clarify my position: I believe AGENTMEMORY_PROJECT_ISOLATION (which currently exists in my branch) is fundamentally more critical than AGENTMEMORY_PROJECT_NAME. My experience attempting to configure AGENTMEMORY_PROJECT_NAME across various AI harnesses was friction-heavy; it is significantly more effective to let the AI handle this value dynamically. While manual overrides in MCP settings should remain an option, the system should ideally guide the user via specific error messages if the variable is missing, instructing them on the expected value.
Also, I disagree with the proposal that AGENTMEMORY_PROJECT_ISOLATION should be false by default. It should be true by default for the following reasons:
fix(project): lowercase the owner/repo path, not just the host