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

Function useProactive

src/proactive/useProactive.ts:35–140  ·  view source on GitHub ↗
(opts: UseProactiveOpts)

Source from the content-addressed store, hash-verified

33}
34
35export function useProactive(opts: UseProactiveOpts): void {
36 const optsRef = useRef(opts)
37 optsRef.current = opts
38
39 useEffect(() => {
40 if (!isProactiveActive()) return
41
42 let timer: ReturnType<typeof setTimeout> | null = null
43 let disposed = false
44 let generating = false
45
46 function scheduleTick(): void {
47 const nextTs = Date.now() + TICK_INTERVAL_MS
48 setNextTickAt(nextTs)
49
50 timer = setTimeout(() => {
51 timer = null
52
53 // Guard: skip tick if any blocking condition is met
54 if (!shouldTick()) {
55 // Reschedule — conditions may clear later
56 scheduleTick()
57 return
58 }
59
60 const {
61 isLoading,
62 queuedCommandsLength,
63 hasActiveLocalJsxUI,
64 isInPlanMode,
65 } = optsRef.current
66
67 // Don't fire while a query is in-flight, plan mode is active,
68 // a local JSX UI is showing, or commands are queued
69 if (
70 isLoading ||
71 isInPlanMode ||
72 hasActiveLocalJsxUI ||
73 queuedCommandsLength > 0 ||
74 generating
75 ) {
76 scheduleTick()
77 return
78 }
79
80 generating = true
81 void (async () => {
82 const commands = await createProactiveAutonomyCommands({
83 basePrompt: `<${TICK_TAG}>${new Date().toLocaleTimeString()}</${TICK_TAG}>`,
84 currentDir: getCwd(),
85 shouldCreate: () => !disposed,
86 })
87 if (disposed) {
88 await cancelQueuedAutonomyCommands({ commands })
89 return
90 }
91 const queuedCommands: QueuedCommand[] = []
92 try {

Callers 1

REPLFunction · 0.85

Calls 5

isProactiveActiveFunction · 0.85
scheduleTickFunction · 0.85
setNextTickAtFunction · 0.85
isProactivePausedFunction · 0.85
isContextBlockedFunction · 0.85

Tested by

no test coverage detected