The Hammers have announced Swyer will move to the Cobblers when his contract expires at the end of June.
Swyer will join former Hammers captain Kevin Nolan at League One Northampton, where he is now manager.
The youngster has featured for the first team at West Ham, making his debut in the Europa Conference League in 2022.
This past season, Swyer made 30 appearances for West Ham's U21 team.
Nolan said: “Kamarai is a talented young player with huge potential, who I have worked with before so I know all about him. He’s hungry, technically gifted, he takes people on and is a good athlete who is a good size and has an excellent attitude.
"We’re excited to welcome him to the squad and look forward to working with him and to see him develop with us over the next two years.
"We think we are getting him at a good time. He is on an upward curve, he had a standout season in Premier League 2 last season, with eight goals and ten assists, the most number of goal involvements for any West Ham player.
"He is ready to challenge himself and to go to the next level and that is what we will work with him to help him achieve."