Labour has demanded to know how much the Home Office has spent on sending almost 40,000 texts to members of the public saying they should go home if they have overstayed their leave to remain.

The programme being undertaken on behalf of the government by Capita was revealed by the Guardian on Monday.

David Hanson, the shadow Home Office minister, dismissed the programme on Friday as a gimmick, after the Home Office minister, Mark Harper, defended sending vans around London bearing advertisements that urged illegal overstayers to go home. He told BBC's Question Time that if the pilot was shown to have worked it would be used nationwide.

Hanson said: "The reports that the government has allowed a private contractor to send British citizens text messages telling them to leave the country demonstrates once more just how shambolic and incompetent the Home Office's border police is under Theresa May.

"These messages will rightly cause distress and offence to British citizens, many of whom have done much to contribute to our society. It is simply wrong for this sort of message to be sent by text, and to be so poorly targeted.

"Yet again, like the offensive and inappropriate ad vans, the government will be using taxpayers' hard-earned money to offend and alienate its own citizens."

A total of 39,100 text messages have been sent by Capita on behalf of the government as part of a contract to track down about 58,800 individuals who may not have the right to live in the UK.

The text reads: "Message from the UK Border Agency. You are required to leave the UK as you no longer have right to remain." Up to 400 complaints have reportedly been filed, including from individuals who have lived in the country for decades, and have the right to stay. The Home Office says the number of complaints is smaller.

The existence of the texting programme was revealed in a Freedom of Information request.

Labour has tabled parliamentary questions asking how many of the texts had been sent by Capita on behalf of the Border Agency between May 2010 and 10 October 2013. Hanson has asked how many were sent in error.

Capita said it was given the phone numbers in "regular data drops of information detailing applications with a negative outcome on the Home Office immigration database. This data includes contact details that were provided by applicants at the time of, or subsequent to, making an application.

"Where it is identified that Capita have contacted an individual in error, Capita and Home Office records are immediately updated and contact is ceased. Furthermore, if an error has been made at the triage stage of handling the case, this is fed back, any learning incorporated into training and, where applicable, processes are amended."

Earlier this week the home secretary, Theresa May, appeared unenthusiastic about the project, stressing to the home affairs select committee that it had not been her idea.

The former Liberal Democrat minister Jeremy Browne, who was sacked by Nick Clegg in the ministerial reshuffle, revealed he had not been told about the van pilot in any ministerial correspondence, although a special advisor was informed about an enforcement campaign in general but not the wording or detailed plan. Browne concluded that his failure to alert the deputy prime minister to the plan contributed to his dismissal.

During July, the vans were driven around the London boroughs of Barking and Dagenham, Redbridge, Barnet, Brent, Ealing and Hounslow for a week.

Harper said on BBC Question Time on Thursday that the van pilot was being evaluated.

"I don't see any problem with saying to people who have no right to be in the United Kingdom they can't be here any more. If it's successful we'll look at rolling it out, if it's not successful, we won't," he said.