fix: pre-create project log dir before launching CLI#737
Open
anthony-maio wants to merge 2 commits intoanthropics:mainfrom
Open
fix: pre-create project log dir before launching CLI#737anthony-maio wants to merge 2 commits intoanthropics:mainfrom
anthony-maio wants to merge 2 commits intoanthropics:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses Claude Code CLI startup failures in multi-agent setups by ensuring the per-project log directory is created before the CLI subprocess is launched, using the child process’s resolved config root.
Changes:
- Add child-environment-aware resolution of the Claude config directory (
CLAUDE_CONFIG_DIR,HOME,USERPROFILE) and pre-create the CLI project log directory before spawning the subprocess. - Add regression tests covering directory creation for both
HOMEandCLAUDE_CONFIG_DIRoverrides.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/claude_agent_sdk/_internal/transport/subprocess_cli.py |
Resolves config directory from child env and ensures projects/<sanitized-cwd> exists before launching the CLI. |
tests/test_transport.py |
Adds tests asserting the project log directory is created under overridden HOME and CLAUDE_CONFIG_DIR. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CLAUDE_CONFIG_DIR,HOME, orUSERPROFILEin the child environmentHOMEandCLAUDE_CONFIG_DIRoverridesProblem
When callers override
HOMEorCLAUDE_CONFIG_DIRper agent, the CLI can try to write~/.claude/projects/<sanitized-cwd>/<session>.jsonlbefore that per-project directory exists. In multi-agent environments this shows up asENOENTon startup.Test Plan
python -m pytest tests/test_transport.py -k "not concurrent_writes"python -m pytest tests/test_transport.py -k "project_log_dir or CLAUDE_CONFIG_DIR"python -m ruff check src/claude_agent_sdk/_internal/transport/subprocess_cli.py tests/test_transport.pypython -m mypy src/Notes
Two existing
tests/test_transport.pycases still require the optionaltriobackend in this environment, so I excluded-k concurrent_writesfrom the broader pytest run.Fixes #513