Skip to content

armgit / cogit

Public Imported from GitHub
0

Git for the intent behind agent-written code. Records what your coding agent decided and why, and links every commit to it.

feat(record): record sessions from git worktrees in the main checkout

Eren8b0ad91f313c
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7d26045..4bacef3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
+- Git worktree support: a Claude Code session in a linked worktree (`claude -w`) now records into the main checkout's `.codelineage/` when it is git-ignored (a worktree with its own committed copy keeps it), found by reading `.git` files without running git. Hooks, `session write/show`, `epoch add`, `build` and `open` all resolve it; the session keeps the worktree path and branch, and the map's drill-down shows them.
- Decision detail in the record and the map: nodes take `decidedBy` (`user`, `agent` or `agreed`), `alternatives` (options considered and rejected, with the reason), `commits` and `files`; decision cards show their reason and a short line such as "agreed · 1 commit · 2 options rejected", and the drill-down panel lists the rejected options, the commits and files, who decided, and when the node was recorded and last changed. The `/codelineage:lineage` skill asks the agent to fill them in.
- Map shows where the work left off: `session write` now stamps each node it adds or changes (`touchedAt`, set by the CLI and never taken from agent input), and the map opens the branches down to the nodes the last write of the latest session added or changed, marks each "left off here" and frames that session.
- Claude Code plugin skeleton: the `codelineage` npm package is also the plugin (`.claude-plugin/plugin.json`, bundled `dist/cli.js`), and the repository root carries a `codelineage` marketplace that installs it from npm.
diff --git a/biome.json b/biome.json
index 1cd63a3..080b6f6 100644
--- a/biome.json
+++ b/biome.json
@@ -1,7 +1,15 @@
{
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
"files": {
- "includes": ["packages/**", "*.json", "*.ts", "!**/dist", "!**/coverage", "!**/*.md"]
+ "includes": [
+ "packages/**",
+ "*.json",
+ "*.ts",
+ "!**/dist",
+ "!**/coverage",
+ "!**/*.md",
+ "!!**/.claude"
+ ]
},
"formatter": { "indentStyle": "space", "indentWidth": 2, "lineWidth": 100 },
"linter": { "rules": { "preset": "none" } }
diff --git a/packages/cli/src/commands/build.ts b/packages/cli/src/commands/build.ts
index 7e1ced1..5fa7819 100644
--- a/packages/cli/src/commands/build.ts
+++ b/packages/cli/src/commands/build.ts
@@ -1,8 +1,8 @@
-import { resolve } from "node:path";
import { CliError, type Io } from "../io.js";
import { redactDeep } from "../redact.js";
import { atomicWrite } from "../store/fs.js";
import { projectPaths } from "../store/paths.js";
+import { resolveProjectRoot } from "../store/root.js";
import { loadAllSessions, loadProject } from "../store/stores.js";
import { buildViewModel, embedViewModel } from "../view/lineage.js";
import type { LineageViewModel } from "../view/model.js";
@@ -26,7 +26,7 @@ export interface BuildOptions {
*/
export async function buildProject(opts: BuildOptions): Promise<LineageViewModel> {
const { io } = opts;
- const root = resolve(opts.dir);
+ const { root } = await resolveProjectRoot(opts.dir);
const project = await loadProject(root);
if (!project.found)
throw new CliError(`${root} is not initialized; run \`codelineage init\` first`);
diff --git a/packages/cli/src/commands/epoch.ts b/packages/cli/src/commands/epoch.ts
index 689e3d7..0e33b8a 100644
--- a/packages/cli/src/commands/epoch.ts
+++ b/packages/cli/src/commands/epoch.ts
@@ -1,10 +1,10 @@
-import { resolve } from "node:path";
import { CliError, type Io } from "../io.js";
import { Slug } from "../schema/common.js";
+import { resolveProjectRoot } from "../store/root.js";
import { loadProject, updateProject } from "../store/stores.js";
export async function epochAdd(dir: string, id: string, title: string, io: Io): Promise<void> {
- const root = resolve(dir);
+ const { root } = await resolveProjectRoot(dir);
if (!Slug.safeParse(id).success) {
throw new CliError(`invalid epoch id "${id}": use letters, digits, _ . -`);
}
diff --git a/packages/cli/src/commands/open.ts b/packages/cli/src/commands/open.ts
index 1b954ee..b1fd7c8 100644
--- a/packages/cli/src/commands/open.ts
+++ b/packages/cli/src/commands/open.ts
@@ -1,7 +1,7 @@
import { type SpawnOptions, spawn } from "node:child_process";
-import { resolve } from "node:path";
import type { Io } from "../io.js";
import { globalPaths, projectPaths } from "../store/paths.js";
+import { resolveProjectRoot } from "../store/root.js";
import { buildPanel } from "../view/panel.js";
import { buildProject } from "./build.js";
@@ -68,7 +68,7 @@ async function openFile(file: string, opts: OpenOptions): Promise<void> {
/** Rebuilds the map, then hands `lineage.html` to the OS opener. */
export async function openProject(opts: OpenProjectOptions): Promise<void> {
const { io } = opts;
- const root = resolve(opts.dir);
+ const { root } = await resolveProjectRoot(opts.dir);
await buildProject({
dir: root,
io,
diff --git a/packages/cli/src/commands/session.ts b/packages/cli/src/commands/session.ts
index 9756dc4..68fe3cb 100644
--- a/packages/cli/src/commands/session.ts
+++ b/packages/cli/src/commands/session.ts
@@ -6,6 +6,7 @@ import { Slug } from "../schema/common.js";
import { mergeSession } from "../schema/merge.js";
import { SessionInput } from "../schema/session.js";
import { projectPaths } from "../store/paths.js";
+import { resolveProjectRoot } from "../store/root.js";
import { loadConfig, loadProject, loadSession, updateSession } from "../store/stores.js";
import { buildProject } from "./build.js";
@@ -32,7 +33,7 @@ export async function sessionWrite(
io: Io,
stdin: () => Promise<string> = readStdin,
): Promise<void> {
- const root = resolve(opts.dir);
+ const { root, worktree } = await resolveProjectRoot(opts.dir);
const project = await loadProject(root);
if (!project.found)
throw new CliError(`${root} is not initialized; run \`codelineage init\` first`);
@@ -65,7 +66,8 @@ export async function sessionWrite(
const saved = await updateSession(root, input.sessionId, (cur) => {
const merged = mergeSession(cur, input, io.now());
warnings = merged.warnings;
- return merged.session;
+ // A write from the main checkout (e.g. after a resume) keeps the stored worktree.
+ return worktree ? { ...merged.session, worktree } : merged.session;
});
for (const w of warnings) io.warn(w);
if (opts.file && opts.consume) await rm(opts.file, { force: true });
@@ -85,14 +87,23 @@ export async function sessionWrite(
* parents, kinds and titles, without summaries, which merging keeps anyway).
* Always exits 0 for an uninitialized project or an unreadable record, because a
* failing injected command aborts the whole skill; the JSON says what is wrong.
+ *
+ * `dir` is the directory the agent passes back to later commands; in a linked
+ * worktree that is the worktree, so writes still learn which worktree they came
+ * from, while `store` names the main checkout that holds the record. The inbox
+ * stays under `dir`, where the skill's edit permission points.
*/
export async function sessionShow(dir: string, sessionId: string, io: Io): Promise<void> {
if (!Slug.safeParse(sessionId).success) throw new CliError(`invalid session id: ${sessionId}`);
- const root = resolve(dir);
+ const given = resolve(dir);
+ const { root } = await resolveProjectRoot(given);
+ const store = root === given ? {} : { store: root };
const project = await loadProject(root);
if (!project.found || !project.ok) {
const error = project.found && !project.ok ? project.error : undefined;
- io.out(JSON.stringify({ initialized: false, dir: root, ...(error ? { error } : {}) }));
+ io.out(
+ JSON.stringify({ initialized: false, dir: given, ...store, ...(error ? { error } : {}) }),
+ );
return;
}
@@ -100,7 +111,8 @@ export async function sessionShow(dir: string, sessionId: string, io: Io): Promi
const loaded = await loadSession(root, sessionId);
const view: Record<string, unknown> = {
initialized: true,
- dir: root,
+ dir: given,
+ ...store,
project: project.data.name,
language: config.language,
epochs: project.data.epochs.map(({ id, title }) => ({ id, title })),
@@ -118,6 +130,6 @@ export async function sessionShow(dir: string, sessionId: string, io: Io): Promi
} else if (loaded.found) {
view.sessionError = loaded.error;
}
- view.inbox = projectPaths(root).inbox(sessionId);
+ view.inbox = projectPaths(given).inbox(sessionId);
io.out(JSON.stringify(view, null, 2));
}
diff --git a/packages/cli/src/hooks/run.ts b/packages/cli/src/hooks/run.ts
index 48125fd..e0d0952 100644
--- a/packages/cli/src/hooks/run.ts
+++ b/packages/cli/src/hooks/run.ts
@@ -1,8 +1,8 @@
import { existsSync } from "node:fs";
-import { resolve } from "node:path";
import { z } from "zod";
import { Slug } from "../schema/common.js";
import { projectPaths } from "../store/paths.js";
+import { resolveProjectRoot } from "../store/root.js";
import { onStop } from "./stop.js";
/** The common fields of a Claude Code hook input we rely on. */
@@ -16,7 +16,7 @@ export type HookInput = z.infer<typeof HookInput>;
export interface HookContext {
input: HookInput;
sessionId: string;
- /** The project root: `CLAUDE_PROJECT_DIR`, else the hook's `cwd`. */
+ /** Where `.codelineage/` lives: `CLAUDE_PROJECT_DIR`, else the hook's `cwd`, mapped out of a worktree. */
root: string;
env: NodeJS.ProcessEnv;
now: string;
@@ -48,7 +48,8 @@ export async function runHook(
if (!handler) return undefined;
const input = HookInput.parse(JSON.parse(stdin));
if (!Slug.safeParse(input.session_id).success) return undefined;
- const root = resolve(env.CLAUDE_PROJECT_DIR ?? input.cwd ?? ".");
+ // In a linked worktree both point at the worktree; the record lives in the main checkout.
+ const { root } = await resolveProjectRoot(env.CLAUDE_PROJECT_DIR ?? input.cwd ?? ".");
// Before `init` every hook is a no-op; projects are never registered here.
if (!existsSync(projectPaths(root).project)) return undefined;
const out = await handler({ input, sessionId: input.session_id, root, env, now });
diff --git a/packages/cli/src/schema/session.ts b/packages/cli/src/schema/session.ts
index 21ff9df..2060f51 100644
--- a/packages/cli/src/schema/session.ts
+++ b/packages/cli/src/schema/session.ts
@@ -61,6 +61,8 @@ export const Session = z.object({
updatedAt: IsoDate,
status: Status.default({ goal: "", done: [], pending: [], next: "" }),
nodes: z.array(LineageNode).default([]),
+ /** The linked git worktree the session ran in; set by the CLI, never by the agent. */
+ worktree: z.object({ path: z.string().min(1), branch: z.string().min(1).nullable() }).optional(),
});
/** In input, a missing parent keeps the stored one (null for a new node). */
diff --git a/packages/cli/src/store/root.ts b/packages/cli/src/store/root.ts
new file mode 100644
index 0000000..3edc9d2
--- /dev/null
+++ b/packages/cli/src/store/root.ts
@@ -0,0 +1,66 @@
+import { existsSync } from "node:fs";
+import { readFile, stat } from "node:fs/promises";
+import { dirname, join, relative, resolve } from "node:path";
+import { projectPaths } from "./paths.js";
+
+/** The linked git worktree a directory belongs to. */
+export interface WorktreeInfo {
+ /** The worktree's top directory. */
+ path: string;
+ /** Checked-out branch; null when HEAD is detached. */
+ branch: string | null;
+}
+
+export interface ProjectRoot {
+ /** Where `.codelineage/` lives for this directory. */
+ root: string;
+ /** Set when the directory is inside a linked worktree. */
+ worktree?: WorktreeInfo;
+}
+
+interface LinkedWorktree {
+ top: string;
+ gitdir: string;
+}
+
+/** Walks up to the nearest `.git`; a file (not a directory) there marks a linked worktree. */
+async function findLinkedWorktree(start: string): Promise<LinkedWorktree | undefined> {
+ for (let dir = start; ; dir = dirname(dir)) {
+ const dotGit = join(dir, ".git");
+ const info = await stat(dotGit).catch(() => undefined);
+ if (info?.isFile()) {
+ const match = /^gitdir:\s*(.+?)\s*$/m.exec(await readFile(dotGit, "utf8"));
+ return match ? { top: dir, gitdir: resolve(dir, match[1] as string) } : undefined;
+ }
+ if (info || dirname(dir) === dir) return undefined;
+ }
+}
+
+async function readBranch(gitdir: string): Promise<string | null> {
+ const head = await readFile(join(gitdir, "HEAD"), "utf8").catch(() => "");
+ const match = /^ref:\s*refs\/heads\/(.+?)\s*$/m.exec(head);
+ return match ? (match[1] as string) : null;
+}
+
+/**
+ * Finds the `.codelineage/` for a directory. A linked git worktree has no copy of
+ * a git-ignored `.codelineage/`, so it shares the main checkout's, the same way
+ * Claude Code keeps worktree state in the main checkout. With `.codelineage/`
+ * committed, the worktree has its own copy and keeps it. Only files are read
+ * (`.git` → `gitdir` → `commondir`), so git itself is never needed.
+ */
+export async function resolveProjectRoot(dir: string): Promise<ProjectRoot> {
+ const start = resolve(dir);
+ try {
+ const linked = await findLinkedWorktree(start);
+ if (!linked) return { root: start };
+ const worktree = { path: linked.top, branch: await readBranch(linked.gitdir) };
+ if (existsSync(projectPaths(start).project)) return { root: start, worktree };
+ const common = (await readFile(join(linked.gitdir, "commondir"), "utf8")).trim();
+ const mainTop = dirname(resolve(linked.gitdir, common));
+ return { root: join(mainTop, relative(linked.top, start)), worktree };
+ } catch {
+ // An unreadable or odd `.git` layout falls back to the directory itself.
+ return { root: start };
+ }
+}
diff --git a/packages/cli/src/view/lineage.ts b/packages/cli/src/view/lineage.ts
index ffab802..b337093 100644
--- a/packages/cli/src/view/lineage.ts
+++ b/packages/cli/src/view/lineage.ts
@@ -159,6 +159,7 @@ function toViewSession(session: Session, transcripts?: ReadonlySet<string>): Vie
// Undefined means the caller did not ask (fixtures, unit tests); then the
// record is shown as resumable rather than pretending the transcript is gone.
transcriptAvailable: transcripts === undefined ? true : transcripts.has(session.sessionId),
+ ...(session.worktree ? { worktree: session.worktree } : {}),
};
}
diff --git a/packages/cli/src/view/model.ts b/packages/cli/src/view/model.ts
index f36bea9..cb0dec2 100644
--- a/packages/cli/src/view/model.ts
+++ b/packages/cli/src/view/model.ts
@@ -61,6 +61,8 @@ export interface ViewSession {
nodes: ViewNode[];
/** False when the Claude Code transcript is gone, so resume cannot work. */
transcriptAvailable: boolean;
+ /** The linked git worktree the session ran in, if any. */
+ worktree?: { path: string; branch: string | null };
}
export interface ViewEpoch {
diff --git a/packages/cli/test/worktree.test.ts b/packages/cli/test/worktree.test.ts
new file mode 100644
index 0000000..b75d0f3
--- /dev/null
+++ b/packages/cli/test/worktree.test.ts
@@ -0,0 +1,154 @@
+import { existsSync } from "node:fs";
+import { mkdir, writeFile } from "node:fs/promises";
+import { join } from "node:path";
+import { beforeEach, describe, expect, it } from "vitest";
+import { buildProject } from "../src/commands/build.js";
+import { configSet } from "../src/commands/config.js";
+import { epochAdd } from "../src/commands/epoch.js";
+import { init } from "../src/commands/init.js";
+import { sessionShow, sessionWrite } from "../src/commands/session.js";
+import { runHook } from "../src/hooks/run.js";
+import { projectPaths } from "../src/store/paths.js";
+import { resolveProjectRoot } from "../src/store/root.js";
+import { loadProject, loadSession } from "../src/store/stores.js";
+import { DATA_ELEMENT_ID } from "../src/view/model.js";
+import { envFor, fakeIo, T0, tempDir } from "./helpers.js";
+
+/**
+ * A git layout made of plain files, the way `git worktree add` leaves it: the
+ * main checkout has a `.git/` directory, the worktree a `.git` file pointing at
+ * `.git/worktrees/<name>/`, which holds `HEAD` and `commondir`.
+ */
+async function gitLayout(dir: string, head = "ref: refs/heads/feature\n") {
+ const main = join(dir, "main");
+ const wt = join(dir, "wt");
+ const gitdir = join(main, ".git", "worktrees", "wt");
+ await mkdir(gitdir, { recursive: true });
+ await mkdir(join(wt, "src"), { recursive: true });
+ await writeFile(join(gitdir, "HEAD"), head);
+ await writeFile(join(gitdir, "commondir"), "../..\n");
+ await writeFile(join(wt, ".git"), `gitdir: ${gitdir}\n`);
+ return { main, wt, gitdir };
+}
+
+describe("resolveProjectRoot", () => {
+ let dir: string;
+ beforeEach(async () => {
+ dir = await tempDir();
+ });
+
+ it("keeps a directory outside git or in a main checkout", async () => {
+ const { main } = await gitLayout(dir);
+ expect(await resolveProjectRoot(join(dir, "nowhere"))).toEqual({ root: join(dir, "nowhere") });
+ expect(await resolveProjectRoot(main)).toEqual({ root: main });
+ });
+
+ it("maps a worktree to the main checkout and names the branch", async () => {
+ const { main, wt } = await gitLayout(dir);
+ expect(await resolveProjectRoot(wt)).toEqual({
+ root: main,
+ worktree: { path: wt, branch: "feature" },
+ });
+ expect((await resolveProjectRoot(join(wt, "src"))).root).toBe(join(main, "src"));
+ });
+
+ it("keeps a worktree that has its own committed .codelineage/", async () => {
+ const { wt } = await gitLayout(dir);
+ await mkdir(join(wt, ".codelineage"));
+ await writeFile(projectPaths(wt).project, "{}");
+ expect(await resolveProjectRoot(wt)).toEqual({
+ root: wt,
+ worktree: { path: wt, branch: "feature" },
+ });
+ });
+
+ it("reads a relative gitdir and a detached HEAD", async () => {
+ const { main, wt } = await gitLayout(dir, "0123456789abcdef0123456789abcdef01234567\n");
+ await writeFile(join(wt, ".git"), "gitdir: ../main/.git/worktrees/wt\n");
+ expect(await resolveProjectRoot(wt)).toEqual({
+ root: main,
+ worktree: { path: wt, branch: null },
+ });
+ });
+
+ it("falls back to the directory for a broken .git file", async () => {
+ const { wt, gitdir } = await gitLayout(dir);
+ await writeFile(join(wt, ".git"), "not a pointer\n");
+ expect(await resolveProjectRoot(wt)).toEqual({ root: wt });
+ await writeFile(join(wt, ".git"), `gitdir: ${join(gitdir, "..", "gone")}\n`);
+ expect(await resolveProjectRoot(wt)).toEqual({ root: wt });
+ });
+});
+
+describe("commands in a worktree", () => {
+ let dir: string;
+ let main: string;
+ let wt: string;
+ let env: NodeJS.ProcessEnv;
+
+ beforeEach(async () => {
+ dir = await tempDir();
+ ({ main, wt } = await gitLayout(dir));
+ env = envFor(dir);
+ await init(main, { name: "p", retention: "keep", language: "auto" }, fakeIo(env));
+ });
+
+ it("writes the record to the main checkout and keeps the worktree on it", async () => {
+ await sessionWrite({ dir: wt }, fakeIo(env), async () => '{"sessionId":"s1","title":"a"}');
+ expect(existsSync(join(wt, ".codelineage"))).toBe(false);
+ const first = await loadSession(main, "s1");
+ expect(first.found && first.ok && first.data.worktree).toEqual({ path: wt, branch: "feature" });
+
+ // After a resume from the main checkout, a write there keeps the stored worktree.
+ await sessionWrite({ dir: main }, fakeIo(env), async () => '{"sessionId":"s1","title":"b"}');
+ const second = await loadSession(main, "s1");
+ expect(second.found && second.ok && second.data).toMatchObject({
+ title: "b",
+ worktree: { path: wt },
+ });
+
+ const templateHtml = `<script id="${DATA_ELEMENT_ID}" type="application/json"></script>`;
+ const model = await buildProject({ dir: wt, io: fakeIo(env), templateHtml });
+ expect(model.unassigned[0]?.worktree).toEqual({ path: wt, branch: "feature" });
+ });
+
+ it("shows the main record, the worktree as dir and the inbox under it", async () => {
+ const io = fakeIo(env);
+ await sessionShow(wt, "s1", io);
+ expect(JSON.parse(io.lines[0] ?? "")).toMatchObject({
+ initialized: true,
+ dir: wt,
+ store: main,
+ inbox: projectPaths(wt).inbox("s1"),
+ });
+
+ const plain = fakeIo(env);
+ await sessionShow(main, "s1", plain);
+ expect(JSON.parse(plain.lines[0] ?? "")).not.toHaveProperty("store");
+ });
+
+ it("reports the store of an uninitialized main checkout", async () => {
+ const other = await gitLayout(join(dir, "x"));
+ const io = fakeIo(env);
+ await sessionShow(other.wt, "s1", io);
+ expect(JSON.parse(io.lines[0] ?? "")).toEqual({
+ initialized: false,
+ dir: other.wt,
+ store: other.main,
+ });
+ });
+
+ it("adds epochs to the main project", async () => {
+ await epochAdd(wt, "e1", "Epoch", fakeIo(env));
+ const project = await loadProject(main);
+ expect(project.found && project.ok && project.data.epochs.map((e) => e.id)).toEqual(["e1"]);
+ });
+
+ it("counts hook turns for a worktree session in the main checkout", async () => {
+ await configSet("updateEveryTurns", "1", fakeIo(env));
+ const input = JSON.stringify({ session_id: "s1", cwd: wt });
+ const out = await runHook("stop", input, { ...env, CLAUDE_PROJECT_DIR: wt }, T0, () => {});
+ expect(out).toBeDefined();
+ expect(existsSync(projectPaths(main).state("s1"))).toBe(true);
+ });
+});
diff --git a/packages/template/src/SidePanel.tsx b/packages/template/src/SidePanel.tsx
index ee48315..4d9856d 100644
--- a/packages/template/src/SidePanel.tsx
+++ b/packages/template/src/SidePanel.tsx
@@ -111,6 +111,17 @@ function Field({ label, children }: { label: string; children: React.ReactNode }
);
}
+/** Where a session ran when it was not the main checkout. */
+function WorktreeField({ session }: { session: ViewSession }) {
+ const { worktree } = session;
+ if (!worktree) return null;
+ return (
+ <Field label="Worktree">
+ {worktree.branch ?? "detached HEAD"} <code>{worktree.path}</code>
+ </Field>
+ );
+}
+
function SessionSummary({ model, session }: { model: LineageViewModel; session: ViewSession }) {
return (
<>
@@ -121,6 +132,7 @@ function SessionSummary({ model, session }: { model: LineageViewModel; session:
</Field>
<Field label="Started">{formatTime(session.startedAt)}</Field>
<Field label="Updated">{formatTime(session.updatedAt)}</Field>
+ <WorktreeField session={session} />
</dl>
<ResumeRow model={model} session={session} />
</>
@@ -202,6 +214,7 @@ function NodeDetails({ model, node }: { model: LineageViewModel; node: NodeDetai
<>
<Field label="Session started">{formatTime(session.startedAt)}</Field>
<Field label="Session updated">{formatTime(session.updatedAt)}</Field>
+ <WorktreeField session={session} />
</>
) : null}
</dl>
diff --git a/specs/codelineage-mvp.md b/specs/codelineage-mvp.md
index 4accbd7..178b5eb 100644
--- a/specs/codelineage-mvp.md
+++ b/specs/codelineage-mvp.md
@@ -246,6 +246,18 @@ Settings in `config.json`: `language`, `updateEveryTurns`, `sessionEndCatchUp`,
the same session; the session lock plus read → merge → write keeps both changes.
- **`~/.config/codelineage` not writable** (containers, CI, read-only home): registry
and panel updates are skipped with a warning; project-local writes still work.
+- **Session in a linked git worktree** (`claude -w`, `.claude/worktrees/<name>/`): hook
+ `cwd` and `CLAUDE_PROJECT_DIR` both point at the worktree (verified 2026-10-23,
+ Claude Code 2.1.300). With `gitPolicy=ignore` the worktree has no `.codelineage/`, so
+ hooks and every `-C`/`[dir]` command map the worktree to the main checkout by reading
+ files only (`.git` → `gitdir` → `commondir`), the way Claude Code itself keeps
+ worktree state in the main checkout. With `gitPolicy=commit` the worktree has its own
+ copy and keeps it. The CLI stamps `worktree: {path, branch}` on the session, and the
+ drill-down shows it. `session show` returns the worktree as `dir`, the main checkout
+ as `store`, and an inbox under the worktree, so the skill's edit permission still
+ matches. `claude --resume <id>` run from the main checkout re-enters the worktree, so
+ the resume command stays the same. `.worktreeinclude` is not used: copying live
+ records into a worktree would fork them and lose them when the worktree is removed.
## Tech stack