@gotgenes/pi-nocd
Pi extension that injects the resolved working directory into the system prompt so the agent never cd-prefixes the current working directory
Package details
Install @gotgenes/pi-nocd from npm and Pi will load the resources declared by the package manifest.
$ pi install npm:@gotgenes/pi-nocd- Package
@gotgenes/pi-nocd- Version
1.0.0- Published
- Jun 15, 2026
- Downloads
- not available
- Author
- gotgenes
- License
- MIT
- Types
- extension
- Size
- 10.8 KB
- Dependencies
- 0 dependencies · 1 peer
Pi manifest JSON
{
"extensions": [
"./src/index.ts"
]
}Security note
Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.
README
@gotgenes/pi-nocd
Pi extension that appends an instruction to the system prompt forbidding the agent from cd-prefixing the current working directory.
Why
Pi already tells the agent the resolved CWD: its system prompt ends with a Current working directory: <path> footer, and that line survives downstream shaping (for example pi-anthropic-auth, which only rewrites the preamble span and preserves the footer).
What Pi ships nowhere — default or shaped — is any instruction against cd-prefixing the CWD.
The footer is a bare statement of fact, not a rule, so the habit of prefixing commands with cd $(pwd) && survives.
This extension hooks before_agent_start and appends a block that adds the missing prohibition — forbidding both the literal cd <path> && form and the generic cd $(pwd) && form.
It repeats the literal resolved path (from ctx.cwd) only to make the forbidden cd <path> && example concrete, not because the path is otherwise unavailable to the agent.
Install
pi install npm:@gotgenes/pi-nocd
Or add it to your Pi settings (~/.pi/agent/settings.json):
{
"packages": ["npm:@gotgenes/pi-nocd"]
}
What it injects
For a session whose working directory resolves to /Users/you/project, the following block is appended to the system prompt:
# Working Directory
Shell commands already execute in `/Users/you/project`.
Never prefix a command with `cd` into the current working directory — neither `cd /Users/you/project &&` nor `cd $(pwd) &&`.
Just run the command directly.
The append is idempotent: if a # Working Directory block is already present (e.g. another before_agent_start handler added one), the prompt is returned unchanged.
How it works
| Hook | Behavior |
|---|---|
before_agent_start |
Appends the working-directory block, naming the resolved ctx.cwd, to the prompt |
License
MIT