MCPcopy Index your code
hub / github.com/codeaashu/claude-code / isAgentMemoryPath

Function isAgentMemoryPath

src/tools/AgentTool/agentMemory.ts:68–104  ·  view source on GitHub ↗
(absolutePath: string)

Source from the content-addressed store, hash-verified

66
67// Check if file is within an agent memory directory (any scope).
68export function isAgentMemoryPath(absolutePath: string): boolean {
69 // SECURITY: Normalize to prevent path traversal bypasses via .. segments
70 const normalizedPath = normalize(absolutePath)
71 const memoryBase = getMemoryBaseDir()
72
73 // User scope: check memory base (may be custom dir or config home)
74 if (normalizedPath.startsWith(join(memoryBase, 'agent-memory') + sep)) {
75 return true
76 }
77
78 // Project scope: always cwd-based (not redirected)
79 if (
80 normalizedPath.startsWith(join(getCwd(), '.claude', 'agent-memory') + sep)
81 ) {
82 return true
83 }
84
85 // Local scope: persisted to mount when CLAUDE_CODE_REMOTE_MEMORY_DIR is set, otherwise cwd-based
86 if (process.env.CLAUDE_CODE_REMOTE_MEMORY_DIR) {
87 if (
88 normalizedPath.includes(sep + 'agent-memory-local' + sep) &&
89 normalizedPath.startsWith(
90 join(process.env.CLAUDE_CODE_REMOTE_MEMORY_DIR, 'projects') + sep,
91 )
92 ) {
93 return true
94 }
95 } else if (
96 normalizedPath.startsWith(
97 join(getCwd(), '.claude', 'agent-memory-local') + sep,
98 )
99 ) {
100 return true
101 }
102
103 return false
104}
105
106/**
107 * Returns the agent memory file path for a given agent type and scope.

Callers 3

isAgentMemFileFunction · 0.85

Calls 3

getMemoryBaseDirFunction · 0.85
getCwdFunction · 0.85
normalizeFunction · 0.50

Tested by

no test coverage detected