In the foothills of the Andes, in the Sierra Piura region of Peru, the problems faced by coffee farmers are clear. Up to 6,600 farmers produce here for the Central Piurana de Cafetaleros co-operative (Cepicafe), growing 4,000 tonnes a year of the finest Peruvian coffee on family plots scattered across the mountainside. Together, year in, year out, they bring in this special harvest, the arabica coffee cherries, which are painstakingly picked by hand, processed and dried in the sun.

However, thanks to "weather change", a continual topic of conversation in the area, the harvest is unpredictable. Last year, there was too little rain in the region. This year there has been a deluge: in some areas an increase of 500% on the "norm".

"I still think coffee is worthwhile," says 47-year-old Gusto Regis. "It's not yet as bad as 1983." That was when the El Niño weather system hit, and landslides and flooding drove his family away to find work labouring in an adjoining region. "Of course we had no land and no money so we needed to come back. I don't know what we would do if we had to leave again."

In the neighbouring village, Alejandro Reyes Ruiz talks his co-farmers through a giant diagram he has drawn explaining likely "weather changes". Paul Santos Santos, 24, a trainee teacher, sings an instructive song about climate and coffee. I explain that where I'm from not everybody thinks that climate change exists. "They should come here and try to grow coffee," Alejandro says.

Peru is rated among the top three nations likely to be most affected by climate change in the world by the Tyndall Centre for Climate Change Research at the University of East Anglia.

A farmer wheels his bicycle across a stream swollen by heavy rainfall. Photograph: Stanton Media

In the Sierra Piura there have been many efforts to adapt, from the installation of a pulley system that takes coffee sacks across swollen rivers to fortifications for the local reservoir which have prevented two low-lying villages from being wiped out in a flash flood. But as the uncertainties grow, so will the bill for tackling them.

A report published today by the UK's leading ethical hot drinks brand Cafédirect (Cepicafe is one of its suppliers) warns that the effects of climate change on arabica production are likely to lead to worldwide shortages and an exodus from coffee growing by small-scale producers. However the company, which was formed 21 years ago to protect small-scale producers from poverty after the collapse of the coffee price, has come up with a potential game changer: a unique way of playing the carbon market to the advantage of the poor that will fund long-term strategies to adapt to climate change.

Up in the Choco region, at an elevation of 3,100m, subsistence farmers – their lineage part Inca, part Spanish conquistador – are unexpectedly trading on the carbon market. In the village the air is full of the smell of wood stoves, which gives a clue as to Choco's big environmental problem: deforestation. As "weather change" hits, the deforestation has exacerbated flash flooding. There is simply no buffer in Choco any longer and the coffee farmers 2,000m below are in danger of being wiped out as a consequence.

"Of course we approached the carbon market cautiously as it doesn't have the best reputation and there was absolutely no blueprint," said Wolfgang Weinmann, head of strategic development at Cafédirect, who for a decade farmed coffee in Ecuador. Carbon-credit schemes are more associated with turbo-charged financial markets looking for a quick buck than the poor on the frontline, but as Cafédirect has worked with local non-governmental organisations, notably Progreso, they have built confidence.

Location of Piura in Peru.

In the nursery that nurtures the pine saplings that represent the first phase of reforestation (the next round will be native trees), it seems they might just have found a workable system that links the poor to the carbon market. For every tonne of carbon captured by the newly planted trees the community receives a carbon credit; later these can be sold on the global market to the benefit of the community. In practice, Cafédirect encourages partners along the supply chain to buy credits, such as Dublin-based Bewley's which roasts the coffee.

Cafédirect's report warns that the major multinational coffee retailers and brands must take urgent action too. This will be hard for multinationals to achieve without major change. Unlike Cafédirect, the big players do not have a relationship with their suppliers, as even fair trade beans are bought anonymously at market. Nothing short of a coffee industry revolution will protect the livelihoods of 25 million small-scale producers who produce 75% of high-quality coffee.

If Cafédirect's project succeeds it could provide a blueprint for indigenous communities all over the world.

Peru's vice president, Marisol Espinoza, said: "Climate change is a huge worry for us in Peru and we hope this initiative in Sierra Piura can be rolled out to other regions too. It is so important because Peruvian coffee is special. It protects biodiversity, and it's about development of whole communities. It also has an amazing aroma and taste. That's the taste of social justice."

Back in Piura, at the coffee-processing plant – which exported 161,000 quintals (7,400 tonnes) of top-quality green coffee last year all over the world – they are gearing up for quality checks. They are acutely aware that in the international coffee market the "taste of social justice" does not necessarily cut it.

"Luckily, we have amazing quality too," beams the factory manager.

In a few weeks the harvest should begin arriving from the mountain. The fight is on to make sure it continues.