“These people deserve it,” he said. “A lot of these guys have the same problems I have.”

At least in the San Francisco Bay Area, where marijuana is more socially accepted than cigarettes in some circles, an informal network already exists to help low-income people obtain medical cannabis. Across the bay in San Francisco, David Theisen, 56, has relied on what he calls “compassion,” a popular term for free medical cannabis, to deal with insomnia.

After moving to the city several years ago, he quickly learned the compassion schedule at several dispensaries, which give away a few dried-out buds to the first comers once or twice a month. When one dispensary cut back, said Mr. Theisen, a former line cook who remains unemployed, he started going days without sleeping.

“I can’t afford to buy it, but my need isn’t any less than anyone else’s,” he said.

The compassion system has now been formalized in Berkeley, where city officials aim to provide low-income patients with a more reliable supply of medical cannabis. Only Berkeley residents are eligible for the free marijuana, and they must show proof of income (less than $32,000 a year for individuals).

Dispensaries, which are prohibited by California law from turning a profit, will also have to hire security guards to patrol nearby, in order to deter crime (though, true to Berkeley’s character, the guards will not be allowed to carry firearms).

One of the city’s largest dispensaries, Berkeley Patients Group, already gives away marijuana to patients who cannot pay. One of them is Arnie Passman, a poet and longtime Berkeley activist, who has been a recipient for about a decade; he could not remember exactly how long, nor was he entirely sure what condition his prescription was meant to treat.

“It could be for my allergies, or my arthritis — you know what happens to us folks: We forget,” Mr. Passman, 78, said. “I can give it a blanket ‘I feel better.’ It helps me get going in the morning.”