anthropics / anthropics/claude-agent-sdk-typescript
Feature Request: Add `cwd` field to `AgentDefinition` to support per-agent working directories
- Lingua principale
- Shell
- Stelle
- 1.8k
- Fork
- 226
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
# Feature Request: Add `cwd` field to `AgentDefinition` to support per-agent working directories
## Summary
When building multi-agent systems where different agents are specialized for different project workspaces, there's currently no way to set a per-agent working directory (`cwd`) in `AgentDefinition`. All subagents inherit the parent `query()` call's `cwd`.
## Use Case
I'm building a multi-agent orchestration layer where each agent is a domain expert locked to its own project directory (e.g., a vehicle diagnosis agent → `/home/code/vehicle-diagnosis`, a frontend agent → `/home/code/frontend`). Each workspace has its own `CLAUDE.md`, memory files, and project context.
When the main orchestrator spawns these agents as teammates, they need to operate in their respective workspaces — not the orchestrator's working directory.
## Current Limitation
`AgentDefinition` has no `cwd` field:
```ts
type AgentDefinition = {
description: string
prompt: string
tools?: string[]
model?: string
mcpServers?: AgentMcpServerSpec[]
// no cwd ❌
}
```
So calling:
```ts
query({
agents: {
'diagnosis-agent': {
description: 'Vehicle diagnosis expert',
prompt: '...',
// no way to set cwd: '/home/code/vehicle-diagnosis'
}
}
})
```
means the subagent runs in the parent's `cwd`, reads the wrong `CLAUDE.md`, and loses its specialized context.
## Proposed Solution
Add an optional `cwd` field to `AgentDefinition`:
```ts
type AgentDefinition = {
description: string
prompt: string
tools?: string[]
model?: string
mcpServers?: AgentMcpServerSpec[]
cwd?: string // ← working directory for this subagent ✅
}
```
## Notes
I've reviewed the Claude Code source code and can see `runWithCwdOverride()` is used internally when spawning pane-based teammates — this suggests the infrastructure already exists. The gap is that the SDK's public `AgentDefinition` API doesn't expose it.
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Valutazione
Questa issue non è ancora stata valutata.