Please follow https://www.irs.gov/newsroom/claiming-a-child-as-a-dependent-when-parents-are-divorced-separated-or-live-apart.