Summary
When a Netclaw session is working on a specific project directory, it needs to:
- Carry a
CurrentWorkingDirectory field in SessionState.WorkingContext.
- Re-read project-scoped identity files (
.netclaw/AGENTS.md, CLAUDE.md, AGENTS.md) on every turn, walking up from the CWD so project instructions survive compaction and stay current as CWD changes mid-session.
Not in scope here: making tool calls respect the session CWD. That's tracked separately — see the paired issue "Resolve shell + file tool paths against session CWD".
Why this is separate from the working-context-grounding OpenSpec change
Scope protection. The durable task-state change (WorkingContext with RecentFiles / OpenGoals / ProgressMarkers) should not gate on the CWD tracking, and CWD tracking has its own design questions:
- Where does CWD come from when the session is created?
- Who sets it — user command? session-join metadata? tool-call side effect?
- Precedence when multiple project identity files exist at different levels of the directory tree
- Backward compat with sessions that have no CWD set
Reference implementations
- OpenCode
packages/opencode/src/session/instruction.ts:127-135, 164-178 — findUp walker for AGENTS.md / CLAUDE.md / CONTEXT.md. First match wins at each level. Framing: Instructions from: {path}\n{content}.
- Claude Code memory docs — project-root
CLAUDE.md is re-injected from disk after compaction. Nested CLAUDE.md files only re-inject when a file in that subdirectory is read. OpenCode's walker is the cleaner simplification.
Acceptance criteria
Background
Filed as a follow-up to the compaction architecture rework. The failing Slack session on 2026-04-11 lost grounding about the project it was working on after compaction. The structured summary in the compaction-rework change gets us 80% of the way there; project identity file re-reading closes the remaining gap for sessions that shift context across projects.
Summary
When a Netclaw session is working on a specific project directory, it needs to:
CurrentWorkingDirectoryfield inSessionState.WorkingContext..netclaw/AGENTS.md,CLAUDE.md,AGENTS.md) on every turn, walking up from the CWD so project instructions survive compaction and stay current as CWD changes mid-session.Not in scope here: making tool calls respect the session CWD. That's tracked separately — see the paired issue "Resolve shell + file tool paths against session CWD".
Why this is separate from the
working-context-groundingOpenSpec changeScope protection. The durable task-state change (
WorkingContextwithRecentFiles/OpenGoals/ProgressMarkers) should not gate on the CWD tracking, and CWD tracking has its own design questions:Reference implementations
packages/opencode/src/session/instruction.ts:127-135, 164-178—findUpwalker forAGENTS.md/CLAUDE.md/CONTEXT.md. First match wins at each level. Framing:Instructions from: {path}\n{content}.CLAUDE.mdis re-injected from disk after compaction. NestedCLAUDE.mdfiles only re-inject when a file in that subdirectory is read. OpenCode's walker is the cleaner simplification.Acceptance criteria
WorkingContext.CurrentWorkingDirectoryfield added, settable via a session-level API and persisted inSessionSnapshot+SessionCompactedevent.[working-context]block emitted byInjectDynamicContextLayersincludes CWD.[project-instructions]block emitted byInjectDynamicContextLayers, populated by walking up from CWD to find project identity files, framed asInstructions from: {path}\n{content}.EveryTurnsemantics).FireLlmCall. Integration test forces a compaction and asserts the block is still present with correct content.CLAUDE.mdfrom X injected; switching CWD to Y mid-session picks up Y'sCLAUDE.mdon the next turn.[project-instructions]block is simply empty.Background
Filed as a follow-up to the compaction architecture rework. The failing Slack session on 2026-04-11 lost grounding about the project it was working on after compaction. The structured summary in the
compaction-reworkchange gets us 80% of the way there; project identity file re-reading closes the remaining gap for sessions that shift context across projects.