Full-featured desktop application built with Next.js + Electron: - Streaming chat with Claude Code via Agent SDK - Session management with SQLite persistence - Project file tree and file preview - MCP server and custom skills management - Permission controls with Code/Plan/Ask modes - Dark/light theme, token tracking - macOS DMG packaging with electron-builder Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
61 lines
1.5 KiB
TypeScript
61 lines
1.5 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import fs from "fs";
|
|
import path from "path";
|
|
import os from "os";
|
|
|
|
const SETTINGS_PATH = path.join(os.homedir(), ".claude", "settings.json");
|
|
|
|
function readSettingsFile(): Record<string, unknown> {
|
|
try {
|
|
if (fs.existsSync(SETTINGS_PATH)) {
|
|
const content = fs.readFileSync(SETTINGS_PATH, "utf-8");
|
|
return JSON.parse(content);
|
|
}
|
|
} catch {
|
|
// Return empty object if file doesn't exist or is invalid
|
|
}
|
|
return {};
|
|
}
|
|
|
|
function writeSettingsFile(data: Record<string, unknown>): void {
|
|
const dir = path.dirname(SETTINGS_PATH);
|
|
if (!fs.existsSync(dir)) {
|
|
fs.mkdirSync(dir, { recursive: true });
|
|
}
|
|
fs.writeFileSync(SETTINGS_PATH, JSON.stringify(data, null, 2), "utf-8");
|
|
}
|
|
|
|
export async function GET() {
|
|
try {
|
|
const settings = readSettingsFile();
|
|
return NextResponse.json({ settings });
|
|
} catch (error) {
|
|
return NextResponse.json(
|
|
{ error: "Failed to read settings" },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|
|
|
|
export async function PUT(request: Request) {
|
|
try {
|
|
const body = await request.json();
|
|
const { settings } = body;
|
|
|
|
if (!settings || typeof settings !== "object") {
|
|
return NextResponse.json(
|
|
{ error: "Invalid settings data" },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
writeSettingsFile(settings);
|
|
return NextResponse.json({ success: true });
|
|
} catch (error) {
|
|
return NextResponse.json(
|
|
{ error: "Failed to save settings" },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|