Miranda July found the experience of writing her first novel The First Bad Man a welcome respite from the collaboration of film and performance. At first Cheryl is confronted by the unsuitability of Clee, an entitled primitive with no manners and no personal hygiene, but eventually the dynamic between the two women becomes physical in a surreal cocktail of sexual fantasy and fight sequences involving a pummel suit. "I work from my unconscious but I started the book when I was pregnant," says July, who has a two-year-old son, Hopper, with her partner, artist-filmmaker Mike Mills. "So I was feeling a lot of new things in my body. When I get too inert from writing all day, part of me wants to punch myself. Cheryl is so much in her head, she could use a little body work. I acted out the fights, which was a bit startling, but not too brutal." The First Bad Man slips from light comedy-of-manners social satire to something wilder, exploring darker desires, and then morphs again to a visceral core of love, focussing on the baby born to Clee. These scenes feel intensely real. "I wrote that section while I was still swimming with hormones. I felt I was writing notes from an asylum. I was thinking, 'Jesus, no one told me, I have to bring back evidence'. The book was a liferaft for me at that point. It was also a welcome respite from the collaboration of film and performance. Being a writer suits my temperament," she says. "I thought of it as cosy torture."

At 40 July is close to heroine Cheryl in at least one other way: she has suffered from globus hystericus, a psychosomatic condition of feeling she has a lump in her throat. "I am a bit of a recluse, I suffer from bouts of anxiety and depression,' she says. "If I swallow my anger, I can barely talk. My oldest anxiety has to do with how to be in each moment, the feeling that I am always doing something wrong. This dovetails with a workaholic nature and a tendency to feel very, very alone." July's father, Richard Grossinger, and mother, Lindy Hough, are writers and founded North Atlantic Books in Berkley, California, specialising in New Age titles. "They were into raw foods and healing and they made that their niche," July says. "I found them embarrassing but they taught me that you don't have to be normal to be successful." Having counterculture parents, before their ideas became mainstream, made rebellion hard: "I did it by wanting to live in the suburbs and have Laura Ashley sheets. For a while I also spoke with a British accent." As a reaction to the 'rarefied exclusive Berkeley snobby' world of her parents, July moved to Portland, Oregon, where she changed her name and worked in a strip club and in nude peep shows. Heaping irony upon irony, she has appeared in an episode of Portlandia, the satirical TV show that mocks the laid-back culture of the city.

July observed the heyday of the women's self-defence movement in Portland and wrote her novel from a feminist perspective.

"That sexy blonde who is sold to straight men as an object of desire is actually mostly consumed by women, so we have to relate to her. Clee is blonde and busty and it's easy to dismiss her, but she has power, like the sun." Discussing the relationship between Cheryl and Clee, she says, "My first two serious relationships were with women, in my early 20s. At the time, I was drawn into the circle of the Riot Grrrls [an underground feminist hardcore punk movement]. I was reading fanzines made by other young women and listening to Patti Smith lyrics. Almost all the women I knew were lesbians." "I've always been interested in age-mismatched couples. As a child, I always wanted the love of adults. When I studied ballet I had a crush on an older man – I was seven, he was 25. It was me that was inappropriate in my desires, not him. Ever since that time I have always concocted fantasies of being molested," she says. "I saw those boundaries as permeable. I knew that children had feelings that made propriety inapplicable." Such statements are bound to provoke those with politically correct imaginations, but they are not the ones that have fuelled a certain bitchy animosity towards her, epitomised by the blog Why I Hate Miranda July. She has the same effect in arthouse circles as Gwyneth Paltrow does in tabloids and on social media. Detractors frequently describe July as twee and denounce her work as pretentiously slight. July is philosophical about the personal vitriol: "I wish kids were taught to ask themselves to ask why they hate what they hate, but who is going to teach them that? Certainly not the internet."

Yet July also belongs to a posse of cool girls, including Kirsten Dunst and Lena Dunham, who she thanks in the novel's acknowledgements. Her films have screened at Sundance and Cannes, where Me and You and Everyone We Know won a Camera d'Or for best first feature in 2005. An urban boho whose personal style is much commented on, she has moved on from her post-punk days of wearing eyeliner on her mouth and tights over shoes. "I love clothes and getting dressed. It's not a love of fashion per se, just the enjoyment of being able to so easily shape how I feel and am perceived. I don't have very many pure pleasures, I'm pretty strict with myself, so clothes are a real comfort." July is comfortable navigating a seamless relationship between creativity and commercial opportunities. "I don't distinguish between art and marketing, the ideas come together," she says. "The commercial projects come by invitation. I am very careful about what I accept. Most things I say no to unless they match my fault lines of interest." As a tongue-in-cheek teaser for The First Bad Man, she established an online store that offers 40 objects mentioned in the book, including the pummel suit and a one dollar bill that fetched more than $100 at auction on the site, with all proceeds going to charity. She recently did a promotional video for a handbag named after her. It's a playful little sketch about a magical accessory equipped with special features that anticipate every crisis a girl might face. July prances and shimmies on screen, reed thin, her delivery deadpan and whimsical. Then there's the Somebody App she designed, sponsored by fashion label Miu Miu, that sends volunteers to deliver and perform messages, including hugs.

"That was based on my preoccupation with strangers," she says. "They are like raw material: a whole person as real as you." She also has a fascination with social awkwardness and clumsiness. "There is so much emphasis in the world today on doing things well and on connection but I have a fondness for mistakes. I enjoy making my characters stumble around and miss each other's meaning. There would be no stories if people understood themselves. That's my job as a writer." The First Bad Man is published by Canongate, $27.99. And another thing: July's 2011 film, The Future, was narrated by a stray cat.