The error is right, Claude is wrong. A Server Component page renders after the response headers have started, so it can read cookies but not set them. Setting has to happen where a response is being built:
// app/actions.ts
'use server'
import { cookies } from 'next/headers'
export async function setLanguage(lang: string) {
(await cookies()).set('lang', lang, { path: '/', maxAge: 60 * 60 * 24 * 365 })
}Call it from a form or button in a client component. Reading in the page with (await cookies()).get('lang') is fine.
'use server' at the top of a page file is not a thing, remove that.