MCPcopy
hub / github.com/codeaashu/claude-code / getAllHooks

Function getAllHooks

src/utils/hooks/hooksSettings.ts:92–161  ·  view source on GitHub ↗
(appState: AppState)

Source from the content-addressed store, hash-verified

90}
91
92export function getAllHooks(appState: AppState): IndividualHookConfig[] {
93 const hooks: IndividualHookConfig[] = []
94
95 // Check if restricted to managed hooks only
96 const policySettings = getSettingsForSource('policySettings')
97 const restrictedToManagedOnly = policySettings?.allowManagedHooksOnly === true
98
99 // If allowManagedHooksOnly is set, don't show any hooks in the UI
100 // (user/project/local are blocked, and managed hooks are intentionally hidden)
101 if (!restrictedToManagedOnly) {
102 // Get hooks from all editable sources
103 const sources = [
104 'userSettings',
105 'projectSettings',
106 'localSettings',
107 ] as EditableSettingSource[]
108
109 // Track which settings files we've already processed to avoid duplicates
110 // (e.g., when running from home directory, userSettings and projectSettings
111 // both resolve to ~/.claude/settings.json)
112 const seenFiles = new Set<string>()
113
114 for (const source of sources) {
115 const filePath = getSettingsFilePathForSource(source)
116 if (filePath) {
117 const resolvedPath = resolve(filePath)
118 if (seenFiles.has(resolvedPath)) {
119 continue
120 }
121 seenFiles.add(resolvedPath)
122 }
123
124 const sourceSettings = getSettingsForSource(source)
125 if (!sourceSettings?.hooks) {
126 continue
127 }
128
129 for (const [event, matchers] of Object.entries(sourceSettings.hooks)) {
130 for (const matcher of matchers as HookMatcher[]) {
131 for (const hookCommand of matcher.hooks) {
132 hooks.push({
133 event: event as HookEvent,
134 config: hookCommand,
135 matcher: matcher.matcher,
136 source,
137 })
138 }
139 }
140 }
141 }
142 }
143
144 // Get session hooks
145 const sessionId = getSessionId()
146 const sessionHooks = getSessionHooks(appState, sessionId)
147 for (const [event, matchers] of sessionHooks.entries()) {
148 for (const matcher of matchers) {
149 for (const hookCommand of matcher.hooks) {

Callers 2

getHooksForEventFunction · 0.85

Calls 9

getSettingsForSourceFunction · 0.85
getSessionIdFunction · 0.85
getSessionHooksFunction · 0.85
entriesMethod · 0.80
resolveFunction · 0.50
hasMethod · 0.45
addMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected