MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / isAgentMemoryPath

Function isAgentMemoryPath

source code/tools/AgentTool/agentMemory.ts:70–106  ·  view source on GitHub ↗
(absolutePath: string)

Source from the content-addressed store, hash-verified

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