# Conflicts: # docs/config-catalog.md # docs/config-catalog.zh.md # docs/event-producer-consumer.md # docs/event-producer-consumer.zh.md # docs/persistence-catalog.i18n.yaml # docs/persistence-catalog.md # docs/persistence-catalog.zh.md # docs/persistence-schema.json # packages/experimental/worktree/README.i18n.yaml # packages/extensions/tool-cordis/src/api-catalog.ts # packages/session/working-directory/README.i18n.yaml # packages/session/working-directory/README.md # packages/session/working-directory/README.zh.md # packages/session/working-directory/src/index.ts
description, kind
| description | kind |
|---|---|
| Change one Session’s working directory while existing processes retain theirs. The selected directory survives replay and appears in user context. A missing directory restores the original project when it remains available. | package-reference |
@deepseek-ai/dsh-working-directory
English | 中文
Summary
Change one Session’s working directory while existing processes retain theirs. The selected directory survives replay and appears in user context. A missing directory restores the original project when it remains available.
Table of Contents
- Use this package
- Understand the implementation
- Further Exploration
- Model Experience
- Known Limitations and Deferred Work
- Dev Note
Use this package
Mount alongside fs, sessionProjections, and systemPrompt. defaultDirectory selects an absolute fallback for Sessions without an original directory; omission uses the launch directory. See the configuration catalog.
- name: '@deepseek-ai/dsh-working-directory'
Directory validation and publication delegate through working-directory/access, so the owner of a directory being removed can hold ensure and set into that directory until its operation settles. A listener waits only for an operation on the requested or current path, honours the request's signal while waiting, and otherwise calls next() at once; a rejection fails that access and leaves the recorded directory unchanged, with no fallback. Existing subprocesses keep their own directories.
Understand the implementation
Implementation internals — click to expand
The Session projection owns the effective directory and exposes it in Session observations, so cold readers can use it without activating an Agent; the header continues to identify the original project. A second projection folds the workspace anchors and the root they select from the same event, and relocate validates the root and the directory inside it before committing one event that carries anchor; inherit starts a Session's directories from another Session's, registering the checkout the source works in when the starting directory lies inside it and setting only the directory otherwise. Changes serialize per Session, validate through the filesystem provider, check cancellation and Agent lifetime, commit an event, and queue a user-context notice. If notice queuing fails after commit, the operation returns the committed directory and logs a warning; the next request or resume still receives the required directory context. Prompt assembly validates the current directory before publishing its required context contribution. Existing processes and sandbox grants keep their independent ownership. The service implementation defines the API. Failures are WorkingDirectoryError instances: WORKING_DIRECTORY_INVALID for an empty or malformed path, including a relocate directory outside its root, WORKING_DIRECTORY_NOT_FOUND when a requested change names no existing directory, and WORKING_DIRECTORY_UNAVAILABLE when neither the current directory nor the original project exists or the service has been disposed.
No runtime invariant companion is published because the service reads its only directory state from the Session projection and checks filesystem validity at use.
Further Exploration
- Working directories — shared runtime behavior.
- Session group — durable Session services.
- Testing — composition and replay verification.
Model Experience
Working directory context
What the model sees
The current value is Current working directory: <JSON-quoted absolute path>., followed by Workspace root: <JSON-quoted absolute path>. on a second line while the two differ. Each committed change, including automatic recovery, attempts to queue a user-context notice through the ordinary Agent inbox; a change that selects another root ends its notice with <JSON-quoted root> is now the workspace root. Cancellation or disposal may discard unadmitted notices; the durable directory remains available to the next request. Directory context stays outside the system prompt and remains enabled when optional runtime context is disabled.
Token effect
The initial snapshot and changed values add user-context tokens; unchanged snapshots are not repeated.
KV Cache effect
Directory transitions append context without replacing the stable system-prompt prefix. A changed directory or recovery creates new context after retained history.
Known Limitations and Deferred Work
- Missing original project — when the current directory and the original project are both unavailable, prompt assembly rejects every model turn, including chat-only turns. The service does not choose or recreate a repository. Restore the original directory, or use SDK
setWorkingDirectory(set_working_directoryin Python) orctx.workingDirectory.setto select an existing absolute directory before retrying. Existing shells retain their process-local directories. - Headers recorded by another spelling — producers now record the original project by its canonical path, but a Session created earlier, or by a client that supplied a symlinked or differently cased path, keeps that spelling as its first anchor while
setandrelocaterecord canonical paths. After such a Session enters another checkout, acdback into the original project by the header's spelling keeps the previous root; recovery registers the canonical original as an anchor once the entered checkout disappears. - Root without consumers —
workspaceRoothas no consumer yet: the sandbox write boundary, the workspace file service, the change recorder, sidebar terminals,@file candidates, the skill catalog, project instructions, and the LSP workspace still read the header or the current directory. Connecting them is the deferred work the workspace-root note lists;rootOfalone changes none of their behavior.
Dev Note
Working context for maintainers — click to expand
None.