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

Function handleSessionFileAccess

src/utils/sessionFileAccessHooks.ts:146–227  ·  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,
155 input.tool_input,
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(input.tool_name, input.tool_input)
169 if (filePath && isAutoMemFile(filePath)) {
170 logEvent('tengu_memdir_accessed', {
171 tool: input.tool_name as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
172 ...subagentProps,
173 })
174
175 switch (input.tool_name) {
176 case FILE_READ_TOOL_NAME:
177 logEvent('tengu_memdir_file_read', { ...subagentProps })
178 break
179 case FILE_EDIT_TOOL_NAME:
180 logEvent('tengu_memdir_file_edit', { ...subagentProps })
181 break
182 case FILE_WRITE_TOOL_NAME:
183 logEvent('tengu_memdir_file_write', { ...subagentProps })
184 break
185 }
186 }
187
188 // Team memory access tracking
189 if (feature('TEAMMEM') && filePath && teamMemPaths!.isTeamMemFile(filePath)) {
190 logEvent('tengu_team_mem_accessed', {
191 tool: input.tool_name as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
192 ...subagentProps,
193 })
194
195 switch (input.tool_name) {
196 case FILE_READ_TOOL_NAME:
197 logEvent('tengu_team_mem_file_read', { ...subagentProps })
198 break
199 case FILE_EDIT_TOOL_NAME:
200 logEvent('tengu_team_mem_file_edit', { ...subagentProps })
201 teamMemWatcher?.notifyTeamMemoryWrite()
202 break
203 case FILE_WRITE_TOOL_NAME:

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected