Why is he attacking u lol
I wonder if you're already on thin ice with him, got too many dislikes from him whether it be from stealing or killing random unprovoked people.
Only person that attacked me was that gay dude Danse. I sent him to the sanctuary after he was a companion and sent him to chill there. After I made a decision to side against the BoS, I went to sanctuary hills completely forgot about him, I show up and he says some shit like you betrayed me, pulls out his gun and starts blasting me! My entire settlement swarmed him and started fucking him up. All my people were heavily armed too, kind of an epic battle him in power armor against 18+ people lol. He took out a few random "settlers" before dying. I propped his corpse above the entrance as a warning to others - this is what will happen if you betray me!