One day last summer – a short while after Edward Snowden revealed himself as the source behind the momentous leak of classified intelligence – the Guardian editor Alan Rusbridger got in touch. Would I write a book on Snowden's story and that of the journalists working with him? The answer, of course, was yes. At this point Snowden was still in Hong Kong. He was in hiding. He had leaked documents that revealed the US National Security Agency (NSA) and its British equivalent GCHQ were surveilling much of the planet.

Our conversation took place not in Alan's office but in an anonymous sideroom at the Guardian's King's Cross HQ. Was Rusbridger's office bugged? Nobody knew. But given the Guardian's ongoing publication of sensitive stories based on Snowden's files this seemed a reasonable assumption. Britain's spy agencies were good at what they did. Thus the project to chronicle Snowden's story began in an atmosphere of furtiveness. And perhaps mild paranoia.

I was part of a small team that examined Snowden's documents in a secure fourth-floor room overlooking Regent's Canal. Security was tight. Only a few trusted reporters were allowed in. Guards were posted outside. None of the laptops were connected to the internet or any other network. Cleaners were banned. Soon the room grew unkempt. Discarded sandwich packets and dirty coffee cups piled up.

Downing Street's response to Snowden's leak was initially slow – then strident. David Cameron sent his cabinet secretary Jeremy Heywood to visit the Guardian. Heywood demanded the return of Snowden's files. And, in passing, suggested the newspaper was now itself under secret observation. "I wonder where our guys are?" he said, gesturing vaguely to the flats opposite. These interactions culminated with the Guardian, under threat of government injunction, smashing up its laptops in an underground carpark as two boffins from GCHQ watched. It was beyond the plot of any thriller.

There were curious moments in New York, too, from where many Snowden stories were reported. Within hours of publication of the first one – which revealed that the NSA was mass-scooping data from the US telecoms company Verizon – diggers arrived outside the Guardian's loft office in Broadway. It was a Wednesday evening. They dug up the pavement and replaced it. The same thing happened outside the Guardian's Washington bureau, four blocks from the White House, and the Brooklyn home of US editor-in-chief Janine Gibson. Coincidence? Perhaps.

In July I flew to Rio de Janeiro to interview Glenn Greenwald, the then Guardian columnist to whom Snowden entrusted his files. The trip was pleasant. My hotel overlooked Copacabana beach; from the rooftop I could watch the surf and Rio's rich walking their dogs. Greenwald suggested we meet along the coast in the Royal Tulip hotel. We sat in the lobby. To our left a man with his back to us played with his iPhone; another individual lurked nearby. We shifted locations, twice. Eventually we hid in the business centre.

Greenwald's response to this apparent stalking – by who exactly? – was good humoured. He seemed unfazed. The CIA's station chief in Rio was known for his aggressive methods, Greenwald told me cheerfully. Weeks earlier an intruder had broken into the Rio home he shared with David Miranda and had stolen his laptop. (Nothing was on it.) I had been leaving my own laptop in the safe of my hotel room each day; returning from meeting Greenwald I found the safe would no longer lock.

I ventured out the next morning. My laptop was in the unlocked safe. (It didn't contain any secrets; merely a work in progress.) A tall American immediately accosted me. He suggested we go sightseeing. He said his name was Chris. "Chris" had a short, military-style haircut, new trainers, neatly pressed khaki shorts, and a sleek steel-grey T-shirt. He clearly spent time in the gym. Tourist or spook? I thought spook.

I decided to go along with Chris's proposal: why didn't we spend a couple of hours visiting Rio's Christ the Redeemer statue? Chris wanted to take my photo, buy me a beer, go for dinner. I declined the beer and dinner, later texting my wife: "The CIA sent someone to check me out. Their techniques as clumsy as Russians." She replied: "Really? WTF?" I added: "God knows where they learn their spycraft." This exchange may have irritated someone. My iPhone flashed and toggled wildly between two screens; the keyboard froze; I couldn't type.

Such moments may, of course, have an innocent explanation. Still, back at my home in Hertfordshire I took a few precautions. I worked offline. I stored each draft chapter in a TrueCrypt folder, a virtual encrypted disk accessible only via a long, complicated password. When I conducted interviews I left my mobile behind. Having seen Snowden's documents, I knew something of the NSA's and GCHQ's extraordinary capabilities. As of April 2013, the US spy agency had 117,675 active surveillance targets. Was I perhaps now one of them?

By September the book was going well – 30,000 words done. A Christmas deadline loomed. I was writing a chapter on the NSA's close, and largely hidden, relationship with Silicon Valley. I wrote that Snowden's revelations had damaged US tech companies and their bottom line. Something odd happened. The paragraph I had just written began to self-delete. The cursor moved rapidly from the left, gobbling text. I watched my words vanish. When I tried to close my OpenOffice file the keyboard began flashing and bleeping.

Over the next few weeks these incidents of remote deletion happened several times. There was no fixed pattern but it tended to occur when I wrote disparagingly of the NSA. All authors expect criticism. But criticism before publication by an anonymous, divine third party is something novel. I began to leave notes for my secret reader. I tried to be polite, but irritation crept in. Once I wrote: "Good morning. I don't mind you reading my manuscript – you're doing so already – but I'd be grateful if you don't delete it. Thank you." There was no reply.

A month later the mysterious reader – him, her, they? – abruptly disappeared. At a literary event in Berlin my Guardian colleague David Leigh told a journalist about my unusual computer experiences; he led with the anecdote in a piece for the leftwing daily Taz. After that, nothing. I finished The Snowden Files: The Inside Story of the World's Most Wanted Man in December.

In idle moments I wonder who might have been my surreptitious editor. An aggrieved analyst at the NSA's Fort Meade spy city? GCHQ? A Russian hacker? Someone else intent on mischief? Whoever you are, what did you think of my book? I'd genuinely like to know.