Skip to content

Anthropic.ts saveState() ENOENT on first run when State/ directory missing #1272

Description

@chrisquorum

Summary

saveState() in skills/PAIUpgrade/Tools/Anthropic.ts writes to State/last-check.json but doesn't create the parent directory if it doesn't exist. On first run after a fresh install (or after State/ is deleted), the initial write ENOENT's. The tool currently retries via fallback path and succeeds, but the initial error is noise and could mask other failures.

Repro

rm -rf ~/.claude/skills/PAIUpgrade/State/
bun ~/.claude/skills/PAIUpgrade/Tools/Anthropic.ts
# First save attempt: ENOENT on State/last-check.json
# Retry: succeeds

Observed during a PAIUpgrade audit run 2026-05-15.

Proposed fix

Add a mkdir -p equivalent before the first write in saveState():

import { mkdirSync } from 'fs';
import { dirname } from 'path';

// At the top of saveState(), before fs.writeFileSync(STATE_PATH, ...)
mkdirSync(dirname(STATE_PATH), { recursive: true });

One-line fix, idempotent, no behavior change when directory already exists.

Environment

  • PAI 5.0.0
  • skills/PAIUpgrade tool

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