MCPcopy
hub / github.com/claude-code-best/claude-code / handleSessionFileAccess

Function handleSessionFileAccess

src/utils/sessionFileAccessHooks.ts:146–230  ·  view source on GitHub ↗

* PostToolUse callback to log session file access events.

(
  input: HookInput,
  _toolUseID: string | null,
  _signal: AbortSignal | undefined,
)

Source from the content-addressed store, hash-verified

144 * PostToolUse callback to log session file access events.
145 */
146async function handleSessionFileAccess(
147 input: HookInput,
148 _toolUseID: string | null,
149 _signal: AbortSignal | undefined,
150): Promise<HookJSONOutput> {
151 if (input.hook_event_name !== 'PostToolUse') return {}
152
153 const fileType = getSessionFileTypeFromInput(
154 input.tool_name as string,
155 input.tool_input as string,
156 )
157
158 const subagentName = getSubagentLogName()
159 const subagentProps = subagentName ? { subagent_name: subagentName } : {}
160
161 if (fileType === 'session_memory') {
162 logEvent('tengu_session_memory_accessed', { ...subagentProps })
163 } else if (fileType === 'session_transcript') {
164 logEvent('tengu_transcript_accessed', { ...subagentProps })
165 }
166
167 // Memdir access tracking
168 const filePath = getFilePathFromInput(
169 input.tool_name as string,
170 input.tool_input as string,
171 )
172 if (filePath && isAutoMemFile(filePath)) {
173 logEvent('tengu_memdir_accessed', {
174 tool: input.tool_name as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
175 ...subagentProps,
176 })
177
178 switch (input.tool_name) {
179 case FILE_READ_TOOL_NAME:
180 logEvent('tengu_memdir_file_read', { ...subagentProps })
181 break
182 case FILE_EDIT_TOOL_NAME:
183 logEvent('tengu_memdir_file_edit', { ...subagentProps })
184 break
185 case FILE_WRITE_TOOL_NAME:
186 logEvent('tengu_memdir_file_write', { ...subagentProps })
187 break
188 }
189 }
190
191 // Team memory access tracking
192 if (feature('TEAMMEM') && filePath && teamMemPaths!.isTeamMemFile(filePath)) {
193 logEvent('tengu_team_mem_accessed', {
194 tool: input.tool_name as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
195 ...subagentProps,
196 })
197
198 switch (input.tool_name) {
199 case FILE_READ_TOOL_NAME:
200 logEvent('tengu_team_mem_file_read', { ...subagentProps })
201 break
202 case FILE_EDIT_TOOL_NAME:
203 logEvent('tengu_team_mem_file_edit', { ...subagentProps })

Callers

nothing calls this directly

Calls 6

getSubagentLogNameFunction · 0.85
logEventFunction · 0.85
getFilePathFromInputFunction · 0.85
isAutoMemFileFunction · 0.85
memoryScopeForPathFunction · 0.85

Tested by

no test coverage detected