At commit 85e7a24, oh-my-openagent’s highest structural risk is concentrated in two subsystems: the event plugin (src/plugin/event.ts) and the claude-code-hooks layer (src/hooks/claude-code-hooks/). The anonymous top-level function in event.ts carries an activity risk score of 19.74 with a recent commit activity of 18.68 — meaning it is not just complex (CC 90, ND 8) but is being actively committed against right now, which transforms what might otherwise be a static cleanup note into a live regression risk. Across 3,389 total functions, 395 are rated critical and every one of the top 5 hotspots lands in the “fire” quadrant, signaling that complexity and commit churn are co-located rather than spread evenly across the codebase.
The table below ranks functions by activity-weighted risk — a score that multiplies structural complexity by recent commit frequency. A function that is both hard to understand (high cyclomatic complexity) and actively changing is a higher priority than one that is complex but untouched. CC = cyclomatic complexity (independent execution paths); ND = max nesting depth; FO = fan-out (distinct callees).
Top 5 Hotspots
| Function | File | Risk | CC | ND | FO |
|---|---|---|---|---|---|
<anonymous> | src/plugin/event.ts | 19.7 | 90 | 8 | 55 |
createEventHandler | src/plugin/event.ts | 19.4 | 43 | 8 | 62 |
executePreToolUseHooks | src/hooks/claude-code-hooks/pre-tool-use.ts | 19.2 | 36 | 9 | 11 |
executePostToolUseHooks | src/hooks/claude-code-hooks/post-tool-use.ts | 18.9 | 42 | 7 | 16 |
formatFullSession | src/tools/background-task/full-session-format.ts | 18.1 | 23 | 7 | 18 |
Hotspot Analysis
<anonymous> — src/plugin/event.ts
This anonymous function sits at the top level of the event plugin file, suggesting it likely serves as the module’s primary initialization or dispatch entry point — the kind of scope that wires together event registration, routing, and plugin lifecycle in a single block. A cyclomatic complexity of 90 means there are roughly 90 independent execution paths to reason about and test; a max nesting depth of 8 indicates those paths are deeply interleaved rather than flat. With a fan-out of 55 and a recent commit activity of 18.68, this function is both broadly coupled — touching 55 distinct callees — and under active churn, meaning every recent commit to this file risks touching logic that branches in 90 different directions.
Recommendation: Before any refactoring, write characterization tests that exercise the dominant event paths so regressions surface immediately. Then apply extract-method refactoring to pull distinct event-type handlers into named, independently testable functions, reducing the anonymous scope to an orchestrator with single-digit CC.
createEventHandler — src/plugin/event.ts
Based on its name and file location, createEventHandler likely constructs and returns a configured handler for plugin events — a factory-style function responsible for assembling the logic that responds to agent events. Its CC of 43 and ND of 8 indicate that handler construction involves substantial conditional branching nested at least 8 levels deep, while a fan-out of 62 — the highest of any function in the top 5 — means it calls out to 62 distinct functions, giving it the widest blast radius in the codebase. With a recent commit activity of 18.25 and activity risk of 19.39, it is being changed nearly as frequently as the anonymous function above it in the same file, compounding the regression surface.
Recommendation: Audit the 62 callees to identify which are genuinely required at construction time versus which could be deferred or injected; reducing fan-out through dependency injection or lazy initialization will shrink the blast radius of future changes and make the construction logic testable in isolation.
executePreToolUseHooks — src/hooks/claude-code-hooks/pre-tool-use.ts
This function almost certainly runs before any tool invocation in the claude-code agent lifecycle, acting as a gate that evaluates and executes registered pre-tool-use hooks — a critical control point for intercepting or modifying tool calls. Its CC of 36 and ND of 9 — the deepest nesting in the entire top 5 — suggest the hook evaluation logic branches heavily on tool type, hook configuration, or execution context, with conditions nested 9 levels deep. The exit_heavy pattern alongside these values means there are also multiple early-return paths, each of which represents a branch that must be independently covered by tests; the recent commit activity of 17.96 confirms this gating logic is still evolving.
Recommendation: Flatten the nesting by extracting each distinct hook-evaluation concern (e.g., per-tool-type dispatch, condition checks, abort paths) into dedicated functions, and add tests that explicitly cover each early-exit path before making further changes.
Patterns Found
Antipatterns detected across the top functions in this snapshot:
| Pattern | Occurrences |
|---|---|
complex_branching | 5 |
deeply_nested | 5 |
god_function | 5 |
long_function | 5 |
exit_heavy | 3 |
These labels belong to two tiers — Tier 1 (structural): complex_branching, deeply_nested, exit_heavy, long_function, god_function. Tier 2 (relational/temporal): hub_function, cyclic_hub, middle_man, neighbor_risk, stale_complex, churn_magnet, shotgun_target, volatile_god.
Key Takeaways
src/plugin/event.tscontains two of the top three hotspots — the anonymous function (CC 90, FO 55) andcreateEventHandler(CC 43, FO 62) — and both have recent commit activity levels above 18, making this file the single highest-priority refactoring target in the repo right now.executePreToolUseHooksandexecutePostToolUseHooksboth carry theexit_heavypattern alongside nesting depths of 9 and 7 respectively; add characterization tests covering every early-exit path in these functions before the next commit touches either file.- Fan-out of 62 on
createEventHandleris the widest coupling in the top 5 — map its callees before refactoring to understand the full blast radius, since changes to this factory function can ripple into 62 distinct downstream functions.
Reproduce This Analysis
git clone https://github.com/code-yeongyu/oh-my-openagent
cd oh-my-openagent
git checkout 85e7a24e265aa4c2e60ae63abef138a0b80856e7
hotspots analyze . --mode snapshot --explain-patterns --force
To run the same analysis on your own codebase, run hotspots analyze . --mode snapshot in any local git repo — no configuration required.
Hotspots highlights structural and activity risk — not “bad code.” Findings are a prioritization aid, not a bug predictor. Editorial policy →