claude-code - 💡(How to fix) Fix [DOCS] Subagent docs omit working-directory isolation and `cwd:` override behavior [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#45473Fetched 2026-04-09 08:04:37
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Author
Participants
Timeline (top)
labeled ×3closed ×1
RAW_BUFFERClick to expand / collapse

Documentation Type

Missing documentation (feature not documented)

Documentation Location

https://code.claude.com/docs/en/sub-agents

Section/Topic

Supported frontmatter fields and the interaction between subagent isolation and the parent session's Bash working directory

Current Documentation

The docs currently say:

The frontmatter defines the subagent's metadata and configuration. The body becomes the system prompt that guides the subagent's behavior. Subagents receive only this system prompt (plus basic environment details like working directory), not the full Claude Code system prompt.

| isolation | No | Set to worktree to run the subagent in a temporary git worktree, giving it an isolated copy of the repository. The worktree is automatically cleaned up if the subagent makes no changes |

And the worktree guide says:

Subagents can also use worktree isolation to work in parallel without conflicts. Ask Claude to "use worktrees for your agents" or configure it in a custom subagent by adding isolation: worktree to the agent's frontmatter. Each subagent gets its own worktree that is automatically cleaned up when the subagent finishes without changes.

And the Bash tool reference says:

The Bash tool runs each command in a separate process with the following persistence behavior:

  • Working directory persists across commands. Set CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR=1 to reset to the project directory after each command.

No documentation currently explains whether a subagent's worktree or working-directory override is scoped only to that subagent, and the subagent docs do not document a cwd: override at all.

What's Wrong or Missing?

Changelog v2.1.97 includes this fix:

Fixed subagents with worktree isolation or cwd: override leaking their working directory back to the parent session's Bash tool

The current docs describe subagent worktree isolation and Bash working-directory persistence separately, but they never document the expected boundary between them.

A. Missing scoping contract

Users need an explicit statement that a subagent's working directory is local to that subagent. Running a subagent in a worktree should not change the parent session's Bash working directory after the subagent finishes.

B. Missing cwd: override documentation

The changelog references a subagent cwd: override, but the sub-agents page does not explain where that override can be set, what values it accepts, or how it interacts with isolation: worktree and the parent session.

Suggested Improvement

Add a short "Working directory behavior" subsection to sub-agents and cross-link it from common-workflows and tools-reference.

That subsection should document:

  1. isolation: worktree changes the working directory only inside the subagent.
  2. Any subagent cwd: override is also scoped to the subagent and does not modify the parent session's Bash working directory.
  3. After a subagent exits, the parent session's Bash tool continues from its own prior working directory unless CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR=1 resets it.
  4. If cwd: override is only available in specific contexts (for example SDK or programmatic agent definitions), say that explicitly and link to the relevant reference.

Impact

Medium - Makes feature difficult to understand

Additional Context

Affected Pages:

PageContext
https://code.claude.com/docs/en/sub-agentsCustom subagent frontmatter and inheritance behavior
https://code.claude.com/docs/en/common-workflows#subagent-worktreesisolation: worktree behavior
https://code.claude.com/docs/en/tools-reference#bash-tool-behaviorBash working-directory persistence
https://code.claude.com/docs/en/statuslinecwd, workspace.current_dir, and worktree.original_cwd fields that expose current runtime directory state
https://platform.claude.com/docs/en/agent-sdk/subagentsAgent SDK subagent behavior cross-reference
https://platform.claude.com/docs/en/agent-sdk/typescriptcwd option and Agent tool input reference cross-reference
https://platform.claude.com/docs/en/agent-sdk/pythoncwd option cross-reference

Total scope: 7 pages affected

Source: Changelog v2.1.97

Exact changelog entry: Fixed subagents with worktree isolation or \cwd:` override leaking their working directory back to the parent session's Bash tool`

extent analysis

TL;DR

Add a "Working directory behavior" subsection to the sub-agents documentation to clarify the scoping of subagent working directories and cwd: overrides.

Guidance

  • Document that isolation: worktree changes the working directory only inside the subagent and does not affect the parent session's Bash working directory.
  • Explain that any subagent cwd: override is scoped to the subagent and does not modify the parent session's Bash working directory.
  • Describe the behavior of the parent session's Bash tool after a subagent exits, including the effect of CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR=1.
  • Cross-link the new subsection from relevant pages, such as common-workflows and tools-reference, to ensure consistent documentation.

Example

A possible implementation of the new subsection could include:

### Working directory behavior

When a subagent is run with `isolation: worktree`, its working directory is changed only within the subagent. The parent session's Bash working directory remains unchanged.

Subagents can also specify a `cwd:` override, which is scoped to the subagent and does not affect the parent session's Bash working directory.

After a subagent exits, the parent session's Bash tool continues from its own prior working directory, unless `CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR=1` is set, in which case it resets to the project directory.

Notes

The exact wording and structure of the new subsection may vary depending on the specific documentation style and conventions used by the project.

Recommendation

Apply the suggested improvement by adding the "Working directory behavior" subsection to the sub-agents documentation, as it provides clarity on the scoping of subagent working directories and cwd: overrides, making the feature easier to understand and use.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING