Children’s book publishers are the most scared about so-called cancel culture, Anthony Horowitz has claimed, saying that he was shocked to be told what he could not write in his latest book for younger readers.

Horowitz, the television screenwriter and author of children’s and adult novels, said that a dangerous “culture of fear” was limiting literary expression. “I’m very, very scared by what you’re calling cancel culture,” he told the Hay Festival. “I think what is happening to writers is extremely dangerous, where certain words are hidden, where certain thoughts are not allowed anymore, where certain activities [are not allowed], obviously to do with gender or to do with ethnicity or to do with trying to share the experiences of others.”

Horowitz, 67, is among a growing number of artists to resist a culture in which public figures, such as his fellow writer JK Rowling, are ostracized from parts of society for their views on sensitive subjects such as trans rights. He has admitted worrying about how people will react when he writes characters from different backgrounds to his. He did, however, tell The Sunday Times in February that middle-aged writers had to “embrace the fact that all change is for the good”.

At Hay, Horowitz said he had “suffered” during the writing of his latest children’s book, Where Seagulls Dare: A Diamond Brothers Case. The novel, aimed at eight to twelve-year-olds, is about “the world’s worst detectives”.

“I have just suffered from my last book notes from my publisher which absolutely shocked me about things which I could or couldn’t say, which is a children’s book, not an adult book,” he said. He said he had needed to extensively rewrite the book, although he declined to say what the specific requests from the publishers were. He said they were “the usual -isms”.

“Children’s book publishers are more scared than anybody,” Horowitz added. “And it seems to me that the forces that are now active in the world — everything to do with the divisiveness of what we’ve been through, plus the sort of stark contrast thrown up by social media whereby something is either very good or very bad but there’s nothing in between — this is leading to a culture of fear and that is the bigger problem.”

“Children’s book publishers are more scared than anybody,” says Anthony Horowitz.

“It’s not about cancellation, it’s not about anger, it is about the fear that all creative people must now feel if they’re going to dare to write. I believe that writers should not be cowed, we should not be made to do things because we’re so scared of starting a storm on Twitter. Because once you start with the writers entering that tunnel, the whole of society will follow them in and we’re all going to be left nudging each other in the dark, too afraid to search for the light. That is sort of where we’re heading.”

Horowitz recommended watching the comic provocateur Ricky Gervais to “pull back from that”. Gervais faced renewed criticism recently for joking about trans people and Aids in a new Netflix show. He talked about “old-fashioned women … They’re the ones with wombs. Those f***ing dinosaurs. I love the new women. They’re great aren’t they … the ones with beards and cocks.”

Gervais also said during the show: “Full disclosure: in real life, of course, I support trans rights … I support all human rights, and trans rights are human rights. Live your best life. Use your preferred pronouns. Be the gender that you feel that you are. But meet me halfway, ladies: lose the cock. That’s all I’m saying.”

Horowitz advocated watching Gervais and other “daring” people, saying that “shrill voices are being amplified by social media but actually they have nothing to say”.

Horowitz has written more than 40 books including three James Bond novels after being chosen by the estate of Ian Fleming.

David Sanderson is the arts correspondent for The Times of London