Extension lifecycle hooks receive empty workingDirectory since CLI ~1.0.51
Describe the bug
Starting around CLI version 1.0.51, extension lifecycle hooks (onSessionStart, onPreToolUse, onUserPromptSubmitted) receive an empty string "" for workingDirectory in the hook input.
Previously (CLI 1.0.49 and earlier), the hook input contained the actual working directory path where the CLI session was started.
Affected version
1.0.51, 1.0.52, 1.0.53, 1.0.54
Steps to reproduce the behavior
- Create an extension that uses the working directory in any lifecycle hook:
export function joinSession(session) {
return {
hooks: {
onSessionStart: (input) => {
// input.workingDirectory is "" instead of the actual path
if (!input.workingDirectory) {
throw new Error("workingDirectory is empty");
}
}
}
};
}
- Start a Copilot CLI session (v1.0.51+) in any directory
input.workingDirectoryis""(empty string)
Expected behavior
input.workingDirectory should contain the actual working directory path (e.g., C:\Users\me\my-project or /home/me/my-project), matching the BaseHookInput type definition in the SDK.
Additional context
- Operating system: Windows 11, x86_64
- Terminal emulator: Windows Terminal
- Shell: PowerShell
Investigated this and confirmed root cause:
TL;DR: The bug is real in CLI 1.0.51 only — the bundled @github/copilot-sdk was at version 1.0.0-beta.3, which declares BaseHookInput with cwd: string and contains no deserialization step. Newer SDK versions renamed the field to workingDirectory: string and added a deserializeHookInput() translation that maps the wire-format cwd to workingDirectory for hook handlers. CLI 1.0.51 shipped before that translation existed, so input.workingDirectory is undefined (which is falsy and indistinguishable from "" in your if (!input.workingDirectory) check).
What changed across versions
| CLI version | Bundled SDK | Has cwd → workingDirectory rename? |
|---|---|---|
| 1.0.48, 1.0.49, 1.0.51 | 1.0.0-beta.3 |
No — type was cwd: string |
| 1.0.52, 1.0.53 | 1.0.0-beta.6 |
Yes |
| 1.0.54+ | 1.0.0-beta.7 |
Yes |
I confirmed this by adding the assertion JSON.stringify(input).includes("workingDirectory":"${workDir}") to our extension-hooks E2E test and running it against each tagged release:
cli-1.0.51: fails — the input string contains"cwd":"<path>"instead ofworkingDirectory.cli-1.0.52,cli-1.0.54, currentmain: passes —workingDirectoryis the actual session cwd.
Why 1.0.49 appeared to work
1.0.49 also ships beta.3, so input.workingDirectory was also undefined there. If 1.0.49 genuinely worked for you, you were likely reading input.cwd at the time (or a separate code path was supplying the value). It's also possible you were on a newer release than you remember; either way the behavior of beta.3 is identical between 1.0.48, 1.0.49, and 1.0.51.
What this means for your reports of 1.0.52/1.0.53/1.0.54 also being broken
Those versions bundle SDK beta.6/beta.7 which both perform the rename, and the existing extension-hooks E2E test (extended with the new assertion) passes on them in CI and locally. If you're still seeing workingDirectory come through empty on 1.0.52+, please double-check:
copilot --versionto confirm the running CLI binary- Make sure auto-update completed (
/restartor relaunch after an update) - If you
npm installed a stale CLI tarball alongside an updated@github/copilot-sdkin your extension'snode_modules, the SDK in your extension'snode_modulesis ignored at runtime — the CLI's bundled SDK is used. So upgrading the dev-time SDK alone doesn't help if the CLI binary is still 1.0.51.
If you can reproduce on a 1.0.52+ binary, attach the output of copilot --version plus a minimal repro extension and we'll dig further.
Recommended fix on your end (if you need to support 1.0.51 specifically)
Read both fields with a fallback until 1.0.51 ages out:
const cwd = input.workingDirectory || input.cwd;
We'll also add coverage to the existing extension-hooks E2E test to assert workingDirectory so this can't regress silently.
[!NOTE] Response generated by Copilot.
This was taken care of in v1.0.52. The CLI now ships an SDK that correctly populates input.workingDirectory for extension lifecycle hooks. If you're still seeing this on v1.0.52 or later, please share your copilot --version output and a minimal repro and we'll take another look.