A non-resident's branches and offices in Japan are deemed residents, even if their principal office is abroad1. The Bank of Japan's Q&A treats a foreign branch or office of a Japanese corporation as a non-resident and a Japanese branch or office of a foreign corporation as a resident2.
For individuals, residency depends on the purpose and length of stay and the place of work, in addition to nationality. A Japanese national who has left Japan to stay abroad for two years or more is a non-resident. A foreign national who works at an office in Japan is a resident2.