Skip to content

Record a session's own writes in a CLI journal so the Claude Code plugin stops reading shell lines, and report a deleted item apart from a failed read #3642

Closed

Description

@malibio

Overview

The Claude Code plugin watches the item a session is working on and refuses tool calls when that item changes under the session. To do that it has to know whether the session itself made a change. Today it guesses by parsing the agent's shell lines. This issue replaces the guess with a record the CLI keeps, and makes a deleted item distinguishable from a failed read.

Problem Statement

  • The plugin reads each Bash command to decide whether it may have written to NodeSpace (nodespaceInvocations, mayWrite, isRead in the hooks module). A write it cannot see is read as someone else's change and stops the session: a write inside a script (./scripts/finish-task.sh), or by a command left running in the background.
  • In a session with nobody at the prompt, a false stop ends the work, since tool calls stay refused until the user replies.
  • After any command that may write, the plugin re-reads the item and takes it as the baseline. A change someone else makes while that command runs is absorbed.
  • A context read of a deleted node fails with Error: Not found: <id> on stderr and exit 1, the same exit as an unreachable daemon. The plugin treats every failed check as "say nothing", so a deleted item never stops the session.

Proposed Solution

A write journal kept by the CLI.

  1. The plugin sets one environment variable at session start that names the session. Every command the harness starts inherits it.
  2. A nodespace command that writes a node while the variable is set appends {node_id, version} to that session's journal: a file on this machine under the NodeSpace home, holding ids and versions and no content.
  3. When the watched item's own version differs from the one last seen, the plugin reads the journal. A version the journal holds is the session's own; any other is a change made under it.
  4. The journal is removed when the session ends, and a stale one is removed by the next session start.

The shell-line parsing that exists only to attribute writes (mayWrite, isRead, the forced check before a write, the re-read after one) is deleted. Reading the shell line to learn which item the session is working on, and which skills it fetched, stays.

A deleted item. node context <id> --version-only --json on a node that does not exist prints {"error": "not_found", "node_id": "<id>"} and exits non-zero, in the shape version_conflict already uses. The plugin treats that as the item changing under the session. Any other failure still blocks nothing.

Core records nothing about who changed a node: the journal is the CLI's own file, outside the database.

Documentation

  • Prompt and Skill System, Harness plugins - the journal and the deleted-item rule this issue implements
  • ADR-093 §5 - what the plugin does during a turn; Consequences - plugins are thin, the CLI operations are a contract
  • ADR-081 - why the record is a local CLI file and not a field on the node
  • ADR-053 - the journal entry names the database the write went to
  • Updates: packages/skill/references/cli.md (the not-found output of a context read), packages/skill/README.md (the paragraph on writes the plugin cannot see)

Architecture Impact

Extends ADR-093 §5 item 4 without changing it: the plugin still compares the context version and refuses tool calls when the item changed under the session. Only how it attributes a change moves, from the plugin to the CLI. No decision is reversed and no ADR change is needed.

Acceptance Criteria

  • The plugin sets a session-naming environment variable at session start, and again after a /clear
  • Every CLI command that changes a node's version appends the node id, the database and the new version to the session's journal when the variable is set, and writes nothing when it is not set
  • A write made from a script, from a loop and from a command left running in the background is recognised as the session's own, with a test for each through the journal
  • A change made by another process while the session's own write is running is still reported
  • The plugin holds no list of read or write commands, and makes no extra CLI call before or after the agent's own commands
  • The journal holds ids and versions only, lives under the NodeSpace home, and is removed at session end; a journal left by a crashed session is removed at the next session start
  • A failed journal read or write never fails the agent's command and never blocks a tool call
  • A context read of a missing node prints {"error": "not_found", "node_id": ...} with --json and exits non-zero
  • The plugin refuses tool calls when the watched item no longer exists, and still says nothing when the read failed for any other reason
  • packages/skill/README.md no longer says a write inside a script stops the session
  • bun run --cwd packages/skill test:plugin passes
  • Code passes bun run quality:fix
  • Tests pass (bun run test:changed)

Technical Specifications

Reference Files

  • packages/skill/plugins/claude-code/hooks/register.ts - mayWrite, isRead, beforeTool, learn, checkItem
  • packages/skill/plugins/claude-code/tests/register.test.ts - the item-watch tests, which run under claude plugin test
  • packages/cli/src/commands/ - the write commands (node update, set-status, move, delete, batch-update, create), and node context
  • packages/cli/src/output.rs - print_node_context_version, and the version_conflict error shape to follow
  • packages/daemon/src/lib.rs - how the NodeSpace home is resolved (NODESPACE_HOME)

Implementation Details

  • The plugin API gives $.env.set(name, value) with a literal name, $.session.id(), and $.fs for reading the journal. No Node API is available in the hooks module.
  • A write's new version is in the response every write command already prints, so the CLI needs no extra request to journal it.
  • Append one line per write; a reader takes the last entry for a node id. Appends from concurrent commands must not corrupt a line.
  • The plugin's check stays one --version-only call per interval. It reads the journal only when the version differs.

Related Issues

Non-Goals

  • Recording who changed a node in the database
  • Handing the system prompt section to subagents

Activity

  1. malibio commented on Oct 5, 2026

    @malibio
    CollaboratorAuthor

    A second copy of this logic now exists

    #3546 shipped a Pi extension and an OpenCode plugin. They share one module, packages/skill/plugins/shared/nodespace-session.ts, which is a port of the Claude Code plugin's watch: it holds its own nodespaceInvocations, mayWrite and isRead, the forced check before a write and the re-read after one. Everything this issue says of the Claude Code plugin's shell-line reading is true of that module too.

    Two things for whoever takes this:

    • Scope. The acceptance criteria name the Claude Code plugin only. If the journal replaces shell-line attribution there and not in the shared module, the three plugins attribute writes two different ways. The session-naming variable has to be set by the Pi and OpenCode files as well (Pi's session_start; OpenCode has a shell.env hook for the commands it runs).
    • What it removes. Review of Ship Pi and OpenCode plugins that list NodeSpace's skills in the session, and an instructions block for harnesses without one #3546 found that a session was refused over its own write when two writes overlapped, and both copies now carry state for that: a count of the session's own writes in flight (start times that expire after two minutes in the shared module, a counter released in a finally in register.ts) and a counter of baseline moves made by its own writes. The journal makes all of it unnecessary, in both files. The shared module's tests for those cases are in packages/skill/src/tests/plugin-session.test.ts.

    The deleted-item rule applies to the shared module as it stands: its checkItem also says nothing when a read fails.

  2. malibio commented on Oct 6, 2026

    @malibio
    CollaboratorAuthor

    Frontend: 5880 passed

  3. self-assigned this
    on Oct 6, 2026
  4. added a commit that references this issue on Oct 6, 2026
    60208dd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions