Skip to content

keepClientCwd misses Primary working directory form — env cwd dropped from scrubbed prompt #21

Open

Description

@mradwankhalil

Title: keepClientCwd misses Claude Code's "Primary working directory:" form — env cwd dropped from scrubbed prompt

Problem

scrubOpencodeFingerprints's OPENCODE_ENV_BLOCK replacement calls keepClientCwd, whose capture regex is:

/(?:^|\n)[ \t]*Working directory:[ \t]*([^\n<]+)/i

Claude Code's env block emits Primary working directory: (newer sessions format). The line-start anchor plus exact label means the capture misses that form, keepClientCwd returns "\n", and the kept <env> block loses the working directory entirely.

Consequence

Every consumer that reads the client working directory from the scrubbed system prompt loses it. In Meridian specifically, sessions keyed from the prompt degrade — Meridian's own diagnostics warn about exactly this class of loss:

The directory is read from the <env> block of the system prompt; a plugin implementing experimental.chat.system.transform (for example opencode-scrub) may have removed it.

It also degrades the model's own project-context awareness (no cwd visible in the prompt).

Fix

Make the capture accept the optional Primary prefix:

const cwd = block.match(/(?:^|\n)[ \t]*(?:Primary[ \t]+)?Working[ \t]+directory:[ \t]*([^\n<]+)/i)?.[1]?.trim();

Verified locally against the published dist (0.2.3): legacy Working directory: form still captured, Primary working directory: now captured (case-insensitive), all other scrub rules unaffected (identity/omo-env/fingerprint removal identical), and a live round-trip through the bridge confirms the model sees the cwd while fingerprints remain scrubbed.

Happy to send the PR with tests if the fix shape looks right.

Activity

  1. mradwankhalil commented on Oct 10, 2026

    @mradwankhalil
    Author

    One scope correction: on Meridian's server-side plugin path, cwd/session selection occurs before the plugin transform. The dropped field therefore did not establish a server-side session-keying failure in my installation. The demonstrated defect is that the scrubbed prompt loses Primary working directory, affecting model-visible project context and consumers where scrubbing happens client-side before Meridian parses the request.

    PR #22 still addresses that prompt-preservation bug. A fresh isolated check of its head passed 12 cases covering legacy/Primary forms, case/spacing, negatives, both modes and idempotence; no installed plugin or live service was modified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions