Where can I file for child custody? (Which state has jurisdiction)?
Under a law called the Massachusetts Child Custody Jurisdiction Act, you can only file for custody in the "home state" of the child unless you meet one of the exceptions. The child's "home state" is the state where your child has lived with a parent or a person acting as a parent for the past six consecutive months. If your child is less than six months old, then your child's home state is the state where s/he has lived since birth. (Leaving the state for a short period of time does not change your child's home state.)1
If you and your child recently moved to a new state, generally you cannot file for custody in that new state until you have lived there for at least six months. Until then, you or the other parent can start a custody action in the state where your child has most recently lived for at least six months. (There are some exceptions explained in the next question.)
Here are some examples:
My children lived in Texas their whole lives. We just moved to Massachusetts five months ago. In my case, Texas is my children's "home state." If I want to file for custody right now, I will probably need to file in Texas.
My children lived in Texas until we moved to Massachusetts six months ago. Because the children have lived in Massachusetts for six months, Massachusetts is their "home state." I will likely need to file for custody in Massachusetts (assuming there was no prior case in Texas). However, the other parent can ask Massachusetts to defer to Texas because Texas has more information about my children's lives that does Massachusetts. It would be up to the judge in Massachusetts.
My children lived in Massachusetts until they left to live with their father in Texas two months ago. Because they haven't lived in Texas for six months yet, their home state is still Massachusetts. If I want to file for custody, I can file in Massachusetts as long as I haven't moved out of Massachusetts.
1 M.G.L. 209B § 1