BELGICA explains in Spanish why she is getting kicked out of the small two-bedroom apartment she shares with her two children in the Bronx, in New York City. Her husband was sent to Rikers Island jail in February, the same month that she lost her job at a local restaurant. She now owes nearly $5,000 in back rent, for which her landlord is hauling her to court. As Belgica tells her story, her hands rest uncomfortably on her swollen belly: her third child is due in a matter of days.

If Belgica loses her home, she and her children will probably end up in a homeless shelter. This would cost the city a bundle. By law, New York must provide emergency shelter to anyone who needs it, at more than $100 per night for a family. Families then linger for around 415 nights, on average, as placing them in new homes is both costly and difficult (landlords dislike tenants who have been evicted). When children become homeless, the secondary costs are higher, as studies show they are more likely to enter foster care, drop out of school and wind up in jail. With around 60,000 people now in shelters, up from about 38,000 in 2010 (see chart), the city is spending over $870m a year on emergency beds alone.

So it makes sense to keep people like Belgica in their homes, and this is exactly what New York is trying to do. Bill de Blasio, the city’s mayor, recently pledged an extra $100m in the 2016 budget to cover new rent subsidies and provide legal help to fight evictions, among other benefits. The city has also doubled to $42m the budget for a programme called Homebase, started in 2004, which offers specialised services to people on the verge of eviction. For example at BronxWorks, one of 23Homebase outposts, a caseworker will help pay off Belgica’s debts and contest her eviction in court. She will also get financial counselling and, in a few months, some job training. Of the 16,000 families taken on by Homebase caseworkers this year, 95% are still in their homes. It pays off; Abt Associates, a consulting firm, has found that for every dollar Homebase spends, the city saves $1.06 in shelter expenses.

Sometimes an emergency grant of $1,000 makes all the difference. Because over a third of New Yorkers spend more than half of their income on rent and utilities, unexpected expenses, such as an illness or a car accident, can wreck an entire budget. Between 2002 and 2014 the percentage of families entering shelter after being evicted nearly doubled to 32%, according to the Coalition for the Homeless, an advocacy group. With more poor people doubling up with friends and family (a nearly 4% rise from 2012 to 2013, according to national census figures), some clients simply need help getting along better with their mothers.

But for a programme like Homebase to be cost-effective, the city has to make sure it is reaching the people who are most likely to enter the shelter system. The biggest indicator of future homelessness is past time spent in a shelter. Applicants with limited education, young children and a history of moving around also ring alarm bells. Screeners now subject every candidate to a questionnaire that calculates a risk score, which has helped improve the targeting of resources by 26%, according to a study by Marybeth Shinn, a professor at Vanderbilt University who studies how to prevent and end homelessness. Homebase also plots the addresses of people who are either destined for housing court or applying for shelter, allowing them to be contacted before they are on the street.

Homebase is the biggest homelessness-prevention programme in the country, but other cities have been trying similar schemes. This approach is especially popular in places with high homelessness rates and mandatory-shelter laws, such as Massachusetts, which offers emergency grants of $4,000 to struggling families. In Hennepin County, Minnesota (around Minneapolis), where about half the state’s homeless people live, a new pilot programme has found that simply checking vulnerable families every few months can reduce shelter use by 20%. In Washington, DC, where the homelessness rate is nearly seven times the national average, the new mayor, Muriel Bowser, is drawing up a plan informed by Homebase.

Critics of such programmes say it is foolish to divert resources away from people who are already homeless. Defenders claim that modest, well-targeted interventions keep shelter beds free for the most urgent cases. “The closer you get to the shelter door, the more expensive the intervention,” says Melissa Mowery of CAMBA, a Homebase operator in New York. Now that the number of Americans who spend more than half their income on rent has risen by 49% since 2003, according to the Department of Housing and Urban Development, this seems a lesson worth spreading.