Skip to content

Claude Code. Any Model. The most powerful AI coding agent now speaks every language.

fix(logging): disable the always-on log when its directory is unwritable

Jack Rudenkocbbad806b85f
diff --git a/packages/cli/src/logger-mcp.test.ts b/packages/cli/src/logger-mcp.test.ts
index 09bc06e5..e61a9278 100644
--- a/packages/cli/src/logger-mcp.test.ts
+++ b/packages/cli/src/logger-mcp.test.ts
@@ -25,7 +25,7 @@ async function runLogger(body: string): Promise<void> {
`
import { homedir } from "node:os";
if (homedir() !== process.env.HOME) throw new Error("HOME isolation failed");
- const { initLogger, log } = await import(${JSON.stringify(loggerUrl)});
+ const { initLogger, log, getAlwaysOnLogPath } = await import(${JSON.stringify(loggerUrl)});
${body}
process.exit(0);
`,
@@ -115,6 +115,19 @@ describe("MCP always-on file logging", () => {
expect(names).toHaveLength(4);
});
+ test("an unusable logs path disables always-on logging without throwing", async () => {
+ rmSync(logsDir, { recursive: true });
+ writeFileSync(logsDir, "not a directory");
+ await runLogger(`
+ const { strict: assert } = await import("node:assert");
+ assert.doesNotThrow(() => initLogger(false, "info", false, "claudish-mcp"));
+ assert.equal(getAlwaysOnLogPath(), null);
+ log("[mcp] diagnostic entry after logger initialization failed");
+ `);
+ expect(readFileSync(logsDir, "utf8")).toBe("not a directory");
+ expect(readdirSync(join(root, ".claudish"))).toEqual(["logs"]);
+ });
+
test("noLogs suppresses creation of the always-on file on a fresh logger", async () => {
await runLogger(
'initLogger(false, "info", true, "claudish-mcp"); log("[mcp] diagnostic entry");'
diff --git a/packages/cli/src/logger.ts b/packages/cli/src/logger.ts
index 782edf58..308838a0 100644
--- a/packages/cli/src/logger.ts
+++ b/packages/cli/src/logger.ts
@@ -247,18 +247,24 @@ export function initLogger(
): void {
// Tier 1: Always-on structural logging (unless --log-off)
if (!noLogs) {
- const logsDir = join(homedir(), ".claudish", "logs");
- if (!existsSync(logsDir)) {
- mkdirSync(logsDir, { recursive: true });
+ // A log exists for diagnostics: an unwritable ~/.claudish/logs (read-only home,
+ // sandbox, full disk) turns it off instead of failing the process that asked.
+ try {
+ const logsDir = join(homedir(), ".claudish", "logs");
+ if (!existsSync(logsDir)) {
+ mkdirSync(logsDir, { recursive: true });
+ }
+ alwaysOnLogPath = join(logsDir, `${name}_${logFileStamp()}.log`);
+ writeFileSync(
+ alwaysOnLogPath,
+ `Claudish Session Log - ${new Date().toISOString()}\nMode: structural (content redacted)\n${"=".repeat(60)}\n\n`
+ );
+ rotateOldLogs(logsDir, keep, name);
+ // Start flush timer if not already running
+ scheduleFlush();
+ } catch {
+ alwaysOnLogPath = null;
}
- alwaysOnLogPath = join(logsDir, `${name}_${logFileStamp()}.log`);
- writeFileSync(
- alwaysOnLogPath,
- `Claudish Session Log - ${new Date().toISOString()}\nMode: structural (content redacted)\n${"=".repeat(60)}\n\n`
- );
- rotateOldLogs(logsDir, keep, name);
- // Start flush timer if not already running
- scheduleFlush();
}
// Tier 2: Debug verbose logging (existing behavior, only with --debug-claudish)
diff --git a/packages/cli/src/providers/effort-recommendations.ts b/packages/cli/src/providers/effort-recommendations.ts
index ec1345de..edbe5ddb 100644
--- a/packages/cli/src/providers/effort-recommendations.ts
+++ b/packages/cli/src/providers/effort-recommendations.ts
@@ -283,7 +283,7 @@ export function writeEffortRecommendations(
if (foreign !== undefined) {
_foreignFormatLogged = true;
log(
- `[EffortRecommendations] replacing a sidecar of format ${String(foreign)} with format ${SIDECAR_FORMAT} at ${path}; its generations are dropped`
+ `[effort] replacing a sidecar of format ${String(foreign)} with format ${SIDECAR_FORMAT} at ${path}; its generations are dropped`
);
}
}