The grammar pattern うちに means "while", "during", or "before (a change occurs)". It expresses the idea that something should be done – or something happens – within a certain time frame before conditions change. It carries a nuance of urgency: the current situation won't last forever, so you should take advantage of it while you can.
うちに attaches to different word forms:
One of the most common patterns is Verb[ない] + うちに, which means "before something happens" or "while something has not yet happened". This emphasizes doing something before a change occurs.
With positive verbs, adjectives, or nouns, うちに expresses doing something while favorable conditions still exist.
When combined with ~ているうちに, it often describes something that happened naturally or unintentionally while another action was going on.
This nuance – that the result was not planned but happened naturally – is a key feature of うちに.
Both うちに and 間に can mean "while" or "during", but they differ in nuance:
Compare:
In this sentence, うちに emphasizes that the child could wake up at any time.