If the setting already exists, you can just do this:
$cs = $modx->getObject('modContextSetting',
array(
'context_key' => 'web',
'key' => 'someKey
),
);
if ($cs) {
$cs->set('value', 'someValue');
$cs->save();
/* clear context_setting cache here if desired */
}
BTW, retrieving them is tricky if there is a System Setting with the same key. See this:
http://bobsguides.com/blog.html/2013/06/19/displaying-modx-context-settings/
As an alternative -- it's a little clunky, but you could create an empty resource for each context and store the data in a set of TVs (or a MIGX TV).
Instead of TVs, you could also put the data in the content field of the Resource.
Or, it could go in chunks named for the contexts or even chunks named something like 'contextNameSettingName'.
Or, it could go in a file or files.