McCartney said the song was inspired by the Apple Scruffs (dedicated fans who hung around outside the Abbey Road studio and the homes of The Beatles), who broke into McCartney's St. John's Wood home. Jessica Samuels, one of the group, says: "We were bored, he was out and so we decided to pay him a visit. We found a ladder in his garden and stuck it up at the bathroom window which he'd left slightly open. I was the one who climbed up and got in." She then opened the front door to let the others in, and they stole a number of photographs. Another Apple scruff, Margo Bird, remembers being good friends with McCartney — she would often take his dog for walks — and later got a job at Apple Corps. She says that she was asked to retrieve a certain photograph, which she did.
In the 2006 DVD documentary The Classic Artists Series: The Moody Blues (DVD UK, released October 2006), Mike Pinder, the former keyboard player of Birmingham R&B band The Moody Blues, states that the inspiration for the song actually rests with an incident that happened to them — a groupie climbing into an open bathroom window in the band's home and spending the night with band member Ray Thomas. The next day, Pinder and Thomas recounted the story to McCartney, who — guitar in hand — strummed and sang "She came in through the bathroom window...".
The Beatles recorded the rhythm track for this and Polythene Pam as one piece on 25 July 1969. It took them 39 attempts, after which they added lead vocals and re-recorded the drums and bass guitar parts.
On 28 July they added more vocals, guitar, percussion and piano. The song was completed two days later with additional guitar and percussion.
This song was performed directly after "Polythene Pam", the song on the preceding track, without pause.
At the very beginning of the song, in anticipation to the change of meter, John Lennon says "we'll listen to that now... heh-heh" and then shouts "Oh, look out!" A slower, ethereal version of this song, recorded during the Let It Be sessions, appears on Anthology 3.
- Paul McCartney — lead vocals, bass guitar (1968 Fender Jazz Bass)
- John Lennon — acoustic guitar (1964 Framus Hooternanny), backing vocals
- George Harrison — lead guitar (1957 Gibson Les Paul Standard), backing vocals
- Ringo Starr — drums, tambourine
- Joe Cocker's cover of this song reached number 30 on the Billboard top 40 in 1970.
- Los Lonely Boys' cover of this song appears on their 2009 tribute EP entitled 1969.