Skip to content

Claude Code CLI fails to create project log path; ENOENT + lock contention + OOM in multi-agent environment #513

@jamiequint

Description

@jamiequint

Environment

  • Running Claude CLI via claude_agent_sdk subprocess.
  • Each agent sets HOME to a per-agent directory (e.g. /home/myapp/{agent-id}).
  • Working directory is a workspace path (e.g. /tmp/myapp-agents/{agent-id} or /home/myapp/{agent-id}/{workspace}).
  • Multiple concurrent agents/processes on same host.

Observed Behavior

  • CLI attempts to open a project log file under:

    $HOME/.claude/projects/{normalized_cwd}/{session_id}.jsonl

  • When {normalized_cwd} includes slashified paths like -tmp-myapp-agents-{agent-id}, the CLI does not create the intermediate directory.

  • Results in:

    Error opening file .../.claude/projects/-tmp-myapp-agents-{agent-id}/{session}.jsonl
    ENOENT: no such file or directory

  • In parallel runs, CLI also logs:

    Failed to save config with lock: Lock file is already being held

  • In some cases the process is OOM-killed (exit code -9) shortly after repeated lock and file write attempts.

Expected Behavior

  • CLI should ensure the full project log directory exists before opening/append.
  • File lock should either block or retry cleanly, not spam errors.
  • Concurrent runs shouldn’t corrupt .claude.json or thrash locks.

Minimal Repro

  1. Launch two concurrent CLI processes with unique HOME dirs.
  2. Set CWD to a path with slashes and hyphens (e.g. /tmp/myapp-agents/{agent-id}).
  3. Observe ENOENT on .claude/projects/{normalized_cwd}/{session}.jsonl.

Workaround

  • Pre-create $HOME/.claude/{projects}/{normalized_cwd} before launching CLI.
  • Or change CLI to write project logs under a single flat directory.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions