Skip to content

A self-organizing Obsidian vault that gives AI coding agents persistent memory.

fix: quote vault path in environment export (#145)

Kushida1f32c736bd5b
diff --git a/.claude/scripts/lib/session-start.ts b/.claude/scripts/lib/session-start.ts
index d13960b..d18f603 100644
--- a/.claude/scripts/lib/session-start.ts
+++ b/.claude/scripts/lib/session-start.ts
@@ -204,6 +204,13 @@ export function formatDateHeader(d: Date): string {
return `${y}-${m}-${day} (${weekday})`;
}
+/** Quote one value for the POSIX shell syntax used by `CLAUDE_ENV_FILE`.
+ * The split/reopen sequence is the only way to retain a literal apostrophe.
+ */
+export function quoteForPosixShell(value: string): string {
+ return `'${value.replaceAll("'", "'\\''")}'`;
+}
+
/**
* Format the "Active Work" section from a list of filenames in work/active.
* Strips `.md`, keeps the first `limit`, returns "(none)" for empty input.
diff --git a/.claude/scripts/session-start.ts b/.claude/scripts/session-start.ts
index 2b21da0..836f231 100644
--- a/.claude/scripts/session-start.ts
+++ b/.claude/scripts/session-start.ts
@@ -23,6 +23,7 @@ import { join } from "node:path";
import {
take,
formatDateHeader,
+ quoteForPosixShell,
injectionMode,
formatInjectionSize,
formatActiveWork,
@@ -111,7 +112,7 @@ process.chdir(cwd);
const envFile = process.env["CLAUDE_ENV_FILE"];
if (envFile) {
try {
- appendFileSync(envFile, `export VAULT_PATH="${cwd}"\n`);
+ appendFileSync(envFile, `export VAULT_PATH=${quoteForPosixShell(cwd)}\n`);
} catch {
/* best-effort — session continues even if persistence fails */
}
diff --git a/.claude/scripts/tests/session-start.test.ts b/.claude/scripts/tests/session-start.test.ts
index 4f7472a..d10aa37 100644
--- a/.claude/scripts/tests/session-start.test.ts
+++ b/.claude/scripts/tests/session-start.test.ts
@@ -11,6 +11,7 @@ import { join } from "node:path";
import {
take,
formatDateHeader,
+ quoteForPosixShell,
formatInjectionSize,
injectionMode,
applyInjectionBudget,
@@ -63,6 +64,16 @@ describe("formatDateHeader", () => {
});
});
+describe("quoteForPosixShell", () => {
+ test("keeps shell syntax literal and escapes apostrophes", () => {
+ const value = "vault/\"$(echo owned)\`echo owned\`/$HOME/it's\nnext";
+ assert.equal(
+ quoteForPosixShell(value),
+ "'vault/\"$(echo owned)\`echo owned\`/$HOME/it'\\''s\nnext'",
+ );
+ });
+});
+
describe("formatActiveWork", () => {
test("strips .md, respects limit, returns sorted input order", () => {
const out = formatActiveWork(