MCPcopy
hub / github.com/anthropics/claude-code / load_rules

Function load_rules

plugins/hookify/core/config_loader.py:198–241  ·  view source on GitHub ↗

Load all hookify rules from .claude directory. Args: event: Optional event filter ("bash", "file", "stop", etc.) Returns: List of enabled Rule objects matching the event.

(event: Optional[str] = None)

Source from the content-addressed store, hash-verified

196
197
198def load_rules(event: Optional[str] = None) -> List[Rule]:
199 """Load all hookify rules from .claude directory.
200
201 Args:
202 event: Optional event filter ("bash", "file", "stop", etc.)
203
204 Returns:
205 List of enabled Rule objects matching the event.
206 """
207 rules = []
208
209 # Find all hookify.*.local.md files
210 pattern = os.path.join('.claude', 'hookify.*.local.md')
211 files = glob.glob(pattern)
212
213 for file_path in files:
214 try:
215 rule = load_rule_file(file_path)
216 if not rule:
217 continue
218
219 # Filter by event if specified
220 if event:
221 if rule.event != 'all' and rule.event != event:
222 continue
223
224 # Only include enabled rules
225 if rule.enabled:
226 rules.append(rule)
227
228 except (IOError, OSError, PermissionError) as e:
229 # File I/O errors - log and continue
230 print(f"Warning: Failed to read {file_path}: {e}", file=sys.stderr)
231 continue
232 except (ValueError, KeyError, AttributeError, TypeError) as e:
233 # Parsing errors - log and continue
234 print(f"Warning: Failed to parse {file_path}: {e}", file=sys.stderr)
235 continue
236 except Exception as e:
237 # Unexpected errors - log with type details
238 print(f"Warning: Unexpected error loading {file_path} ({type(e).__name__}): {e}", file=sys.stderr)
239 continue
240
241 return rules
242
243
244def load_rule_file(file_path: str) -> Optional[Rule]:

Callers 4

mainFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90

Calls 1

load_rule_fileFunction · 0.85

Tested by

no test coverage detected