When you recruit a Companion in Fallout 4, you have an opportunity to raise your relationship/affection with them by bringing them along in quests, engage in meaningful conversations, and do their own personal quests.
Once the companion feels that they’re comfortable with you, meaning you have gained their maximum affection or affinity, you can then unlock their exclusive Perk.
Below is the list of Companion Perks that you can unlock and their requirements:
Codsworth
Perk: Robot Sympathy
Requirements: Gain maximum affinity
Effect: Gain +10 Damage Resistance against robot energy.
Piper
Perk: Gift of Gab
Requirements: Gain maximum affinity
Effect: Receive double XP for speech challenges and discovering new locations.
Hancock
Perk: Isodoped
Requirements: Gain maximum affinity
Effect: You get criticals 20% faster at 250 Rads or Higher
Deacon
Perk: Cloak and Dagger
Requirements: Gain maximum affinity
Effect: Receive +40% Stealth Boy duration and deal +20 percent more sneak attack damage.
Nick Valentine
Perk: Close to Metal
Requirements: Gain maximum affinity and do his personal quest, Long Time Coming
Effect: Get extra one guess and 50% faster terminal cooldown when hacking.
Currie
Perk: Combat Medic
Requirements: Gain maximum affinity and do her personal quest, Emergent Behavior
Effect: Deal 100 Hit Points if your health falls below 10%.
MacCready
Perk: Killshot
Requirements: Gain maximum affinity and do her personal quest, Long Road Ahead
Effect: Headshot accuracy in V.A.T.S is increased by 20%
Danse
Perk: Know Your Enemy
Requirements: Gain maximum affinity
Effect: Deal 20% more damage against Feral Ghouls, Super Mutants, and Synths.
Cait
Perk: Trigger Rush
Requirements: Gain maximum affinity and do her personal quest, Benign Intervention
Effect: AP regenerates faster if your health is below 25%
X6-88
Perk: Shield Harmonics
Requirements: Gain maximum affinity
Effect: Get +20 Energy Resistance