[verb (dict. form)] + か + [same verb (ない-form)] + かのうちに
Note: The same verb is repeated in both dictionary form and ない-form.
The grammar structure か~ないかのうちに expresses that something happens immediately after – or practically at the same time as – a preceding action. It emphasizes that the second event occurs so quickly that the first action has barely been completed (or may not even be fully completed yet). It often translates to "just as," "barely had … when," or "no sooner had … than."
The structure repeats the same verb in both its dictionary form and its ない-form, creating a sense of "whether (the action happened) or not":
This pattern highlights the speed and immediacy of the second event. The speaker is often surprised or impressed by how quickly things happened.
In practice, the ないか portion is sometimes omitted, leaving just Verb + かのうちに, though the full form is more standard.