Klara and the Sun is told from the point of view of Klara, an Artificial Friend, or AF. AFs are solar-powered, humanoid robots designed to serve as companions to children as they grow up. The book takes place in a future version of the United States, in which well-off parents buy Artificial Friends for their children, and participate in “lifting,” a genetic-enhancement process that most parents have done to their children in order to make their children smarter. 

Klara is living in an AF store, waiting to be bought and taken home by a family. She spends her time observing people that come into the store and talking to Rosa (another girl AF who is her close friend), a boy AF named Rex, and the store’s manager, whom Klara refers to as Manager. Klara and the other AFs view the Sun as a god-like figure, providing them with necessary nourishment. When she and Rosa get their coveted chance to sit in the store’s display window, advertising themselves to the public, Klara is delighted, as the window allows her to see human activity in the outside world.

While Klara and Rosa are on display, a fourteen-year-old girl with a strange, cautious gait approaches the window. The girl’s name is Josie, and she converses with Klara, promising to come back again soon. Josie returns to the window a few days later and asks Klara if she’d like to come live with her, to which Klara nods excitedly. Josie promises again to return. 

Klara and Rosa’s turn in the window ends, and when they come back into the store they find that a new, updated line of AFs have arrived—the B3s. Klara is placed mid-store. A construction machine that Klara calls the Cootings Machine is placed in front of the store; it spews out smoke and Pollution, and Klara worries that the Sun will not be able to give the AFs the nourishment they need. 

Boy AF Rex and Rosa get bought and shipped off, and Klara gets a last turn in the window. While there, she thinks she sees a homeless man die overnight only to come back to life in a miracle caused by what Klara dubs the Sun’s special nourishment. When her time in the window is up, Klara is moved to the back of the store. Finally one day Josie and her mother return—the Mother tests Klara by having her mimic Josie’s gait, and agrees to buy her after Klara successfully imitates the girl.

Klara adjusts to life at Josie’s house with Josie, the Mother, and Melania Housekeeper, Josie’s caretaker. Once there, she discovers that Josie has a chronic illness caused by the lifting process. Josie introduces Klara to her best friend Rick, the only other child who lives nearby; Rick and Josie love each other, and often refer to a nondescript “plan” they’ve made for the future. The Mother hosts an interaction meeting, an opportunity for children to socialize as they do all their schooling online, and the kids at the meeting mock Rick, as he is different from them for not being lifted. 

Josie grows ill, and the Mother arranges a trip for them to go to Morgan Falls as an incentive for her to get better. Josie shows Klara pictures of the falls, and tells Klara about her sister Sal, who died from illness when she was young. On the day of the trip, Josie is too sick to go, and the Mother takes Klara with her alone. At the falls, the Mother asks Klara to imitate Josie again. 

Josie spends her days drawing in bed, and Rick visits often; they play a game in which Josie draws a cartoon and Rick fills in the drawing’s speech bubble. Over time their resentment of each other shows through in the game, and one day they both insult each other harshly, causing Rick to storm out. Josie draws an apology picture, and Klara brings it to Rick’s house. There, she meets Rick’s mother, Miss Helen, who lives in poverty and has been slowly losing her mind over the years. She is dreamy and eccentric, but wants badly for Rick to go to college despite his not being lifted. 

At Klara’s request, Rick helps Klara travel through the field between the two houses to an empty barn that she believes is the Sun’s resting place. She goes inside alone and silently prays to the Sun at sunset, vowing to destroy the Cootings Machine and its Pollution if the Sun will send his special nourishment to save Josie.

Josie, the Mother, Klara, Rick, and Miss Helen drive into the city, where they meet up with Josie’s father before going to Josie’s appointment with Mr Capaldi. Mr Capaldi is making a portrait of Josie and needs her to sit for him, but Klara discovers that he has actually been commissioned by the Mother to make an AF version of Josie, so that if Josie dies there will still be a living version of her. Josie is unaware of this, and the Father is against the idea. He storms out of the appointment, taking Josie with him. Once they’ve gone, the Mother tells Klara that if Josie should die, she wants Klara herself to become Josie. 

The Mother picks up Josie from the Father, telling Klara to go with the Father alone. They drive around the city, and Klara tells the Father that in order to save Josie, he needs to help her destroy the Cootings Machine. They find the machine and use a chemical solution from Klara’s body to destroy it, slightly damaging her mental faculties. They meet up with the others for dinner, and afterwards Klara goes with Rick and Miss Helen to meet Mr Vance, an old flame of Miss Helen’s who she hopes will help Rick get into college. Mr Vance appears to like Rick, but he humiliates Miss Helen before leaving them, taunting her with dark memories from their romantic past. On the way back home, Klara sees a new Cootings Machine has taken the place of the old one.

Josie’s illness takes over after their return, and things begin to look hopeless. Klara goes back to the barn at sunset and begs the Sun once more to save Josie, bartering with him by pledging that if he does, Josie and Rick will love each other forever. On a stormy, dark day, just as it is looking like Josie will die, the Sun casts a brilliant light on her and she awakens, beginning to feel better.

Josie grows up into a young adult, needing Klara less. Josie and Rick grow apart as they mature, but remain fond of each other. The day that Josie goes off to college, she hugs Klara tightly and thanks her for being a wonderful AF. Klara lives out the rest of her days in a junkyard, contentedly going back over her memories and feeling glad. One day, Manager runs into her in the Yard, and Klara tells her that she is happy with how her life has gone.