thedotmack/claude-mem · error · AdapterRejectedInput

adapter rejected input: invalid_cwd

Error message

adapter rejected input: invalid_cwd

What it means

windsurfAdapter.normalizeInput throws AdapterRejectedInput('invalid_cwd') when the cwd taken from toolInfo.cwd or the process.cwd() fallback is not a non-empty string. Windsurf nests the working directory inside tool_info, so failure means tool_info.cwd was empty/invalid and no fallback applied.

Solutions

  1. Ensure the Windsurf payload includes tool_info.cwd as a valid directory string
  2. Omit toolInfo.cwd so the process.cwd() fallback applies (only works if toolInfo itself is fine and fallback needed)
  3. Check Windsurf/plugin version for schema changes to tool_info
  4. Catch AdapterRejectedInput with .reason === 'invalid_cwd' and inject a default cwd before re-invoking

Example fix

// before
windsurfAdapter.normalizeInput({ tool_info: { cwd: '' }, agent_action_name: 'edit' });
// after
windsurfAdapter.normalizeInput({ tool_info: { cwd: '/absolute/path/to/workspace' }, agent_action_name: 'edit' });
Defensive patterns

Strategy: validation

Validate before calling

const tc = raw?.tool_info?.cwd;
if (tc !== undefined && (typeof tc !== 'string' || tc.length === 0)) throw new Error('tool_info.cwd must be a non-empty string');

Type guard

function hasValidToolCwd(t: unknown): t is { cwd: string } { return typeof (t as any)?.cwd === 'string' && (t as any).cwd.length > 0; }

Try / catch

try { adapter.normalizeInput(raw); } catch (e) { if (e instanceof AdapterRejectedInput && e.reason === 'invalid_cwd') { /* inject default cwd into tool_info and retry */ } else throw e; }

Prevention

When it happens

Trigger: Windsurf hook payload with tool_info missing, tool_info: {}, or tool_info.cwd set to '' / a non-string while process.cwd() is also unusable; an explicitly invalid toolInfo.cwd value that fails the guard.

Common situations: Windsurf plugin updates dropping tool_info from the payload; running the hook from a deleted directory; hand-written automation sending partial payloads without tool_info.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of thedotmack/claude-mem@d8bc9755e7 (2026-09-17). Data as JSON: /api/errors/6064cf28368dc4ff. Report an issue: GitHub.

Appendix: source

Thrown at src/cli/adapters/windsurf.ts:12

import type { PlatformAdapter, NormalizedHookInput, HookResult } from '../types.js';
import { AdapterRejectedInput, isValidCwd } from './errors.js';

export const windsurfAdapter: PlatformAdapter = {
  normalizeInput(raw) {
    const r = (raw ?? {}) as any;
    const toolInfo = r.tool_info ?? {};
    const actionName: string = r.agent_action_name ?? '';

    const cwd = toolInfo.cwd || process.cwd();
    if (!isValidCwd(cwd)) {
      throw new AdapterRejectedInput('invalid_cwd');
    }

    const base: NormalizedHookInput = {
      sessionId: r.trajectory_id ?? r.execution_id,
      cwd,
      platform: 'windsurf',
    };

    switch (actionName) {
      case 'pre_user_prompt':
        return {
          ...base,
          prompt: toolInfo.user_prompt,
        };

      case 'post_write_code':
        return {
          ...base,

View on GitHub (pinned to d8bc9755e7)