CLI Shims
Every application appending its own private install folder to PATH is an O(N) design failure.
On Windows, it is an active reliability cliff: once combined Machine + User PATH crosses legacy shell limits, Windows silently drops the entire User PATH block and breaks every user-installed CLI at once—including winget itself.
This standard defines a single canonical shim directory, a signed static dispatch shim format that preserves sibling-DLL loading and enterprise code-signing requirements, ownership rules that prevent silent clobbering, and a safe reconciliation pattern for legacy installers.
The key words MUST, MUST NOT, SHOULD, SHOULD NOT and MAY are to be interpreted as described in BCP 14unchecked (RFC 2119, RFC 8174) when, and only when, they appear in all capitals.
In this page, a conforming publisher is an application installer, installer builder (such as DevCentr Ibex), or package manager that exposes CLI commands and claims conformance with this standard.
Requirement ids (SH-n) are stable so tools, reviews, and certification can cite them.
An id is never reused or renumbered; a withdrawn rule keeps its id and is marked withdrawn.
Why PATH per application breaks (especially on Windows)
While POSIX shells tolerate long PATH strings with only lookup overhead and namespace clutter, Windows enforces multiple legacy ceilings across its shell stack:
-
shell32!BuildEnvironmentPath(4,094-character cliff): WhenRegenerateUserEnvironmentmergesMachine(HKLM) andUser(HKCU)PATHand the combined string reaches 4,095 characters,shell32.dllsilently skips appending theUserPATHaltogether. Every user-scoped CLI—including%LOCALAPPDATA%\Microsoft\WindowsApps\winget.exe—vanishes from new shells with zero error dialog or Event Log entry. -
Legacy 2,047-character shell/UI buffers: System Properties UI and older process launchers truncate
PATHat 2,047 characters. -
setx1,024-character truncation: Installers or scripts callingsetxpermanently destroy trailing RegistryPATHentries past 1,024 characters. -
Why raw symlinks are not enough on Windows: Creating file symlinks requires elevation or Developer Mode, and launching a PE binary through a symlink breaks applications that resolve sibling DLLs or data files relative to
GetModuleFileNameW. -
Why unsigned generated
.exeshims fail enterprise security: Generating a unique unsigned PE executable per package triggers Defender/SmartScreen heuristics and fails AppLocker / WDAC code-integrity policies.
For deep Windows shell internals, detection scripts, and AI harness auto-repair guidance, see the DevCentr technical reference: Windows PATH truncation in AI harnessesunchecked.
Canonical shim directories (O(1) PATH)
- SH-1
-
A conforming publisher MUST NOT append an application’s private installation directory to
PATHsolely to expose public CLI executables. Instead, it MUST register each public command in the canonical shim directory for its install scope and ensure BOTH the canonical shim directory and itsautosubfolder (<shim-dir>\autoon Windows,<shim-dir>/autoon Unix) are present on that scope’sPATHat the highest priority (positions 0 and 1, with the base shim directory strictly beforeauto, and each appearing at most once).
Placing the canonical shim directory and its auto subfolder at the front of PATH protects them from tail truncation (Windows' 2,047-character legacy shell/UI limit and `setx’s 1,024-character cut) and ensures explicit shims always take precedence over auto-imported overflow shims.
| Scope | Windows canonical shim directories (top of PATH) |
Unix (Linux / macOS) canonical shim directories (top of PATH) |
|---|---|---|
User (default, no elevation) |
|
|
Machine (elevated / system-wide) |
|
|
- SH-2
-
On Windows, the User canonical directory
%USERPROFILE%\.local\bin(~25 characters expanded) and its auto-imported subfolder%USERPROFILE%\.local\bin\auto(~30 characters expanded) are chosen intentionally for cross-platform alignment with XDG/POSIX tooling and minimalPATHbudget. A conforming publisher MUST NOT invent a new per-vendor or per-package-manager shim directory when registering under this standard.
Shim implementation and sibling-DLL safety
- SH-3
-
On Windows (Strict level), a conforming shim MUST be a native PE executable that spawns the real target binary directly via
CreateProcessWon the target’s real absolute path, paired with a declarative KDL manifest<command>.shim.kdlin the same shim directory.-
Single immutable signed stub: Publishers SHOULD deploy the exact same immutable, reproducible, Authenticode-signed static dispatcher binary (
osh-shim.exe)—hardlinked (or copied across volumes) as<command>.exe. Because every registered command shares an identical signed PE hash and reads its target from<command>.shim.kdl, Windows Defender, SmartScreen, AppLocker, and WDAC evaluate one trusted binary rather than thousands of unsigned per-app executables. -
Sibling DLLs work natively: Because
osh-shim.exeinvokesCreateProcessW(targetExe, …)on the target’s real installation directory, the Windows loader automatically resolves DLLs next totargetExewithout adding the private directory toPATH.
-
- SH-4
-
On Unix (Linux / macOS), a conforming shim SHOULD be an atomic symbolic link
<shim-dir>/<command> → <real-target>paired with a sidecar metadata file<shim-dir>/.osh-shims/<command>.shim.kdl. If a command requires fixed wrapper arguments or environment setup, an executable POSIX wrapper (exec "<target>" … "$@") MAY be used instead. - SH-5
-
On Windows,
.cmdor.batbatch wrappers MUST NOT be used for Strict conformance. Batch wrappers breakCreateProcessWcallers expecting an executable, corrupt quoted/special arguments, lose exit codes, and trigger interactiveTerminate batch job (Y/N)?prompts on Ctrl+C. Batch wrappers are permitted only at the time-boxed Migrating level.
Declarative shim manifest (.shim.kdl)
- SH-6
-
Every registered shim MUST have a companion KDL manifest (
<command>.shim.kdlon Windows;.osh-shims/<command>.shim.kdlon Unix) declaring target, ownership, and runtime semantics:
shim version=1 {
command "perfalyzer"
target "C:\\Program Files\\Perfalyzer\\perfalyzer.exe"
owner "ibex"
package "Desktop-Tooling.perfalyzer"
package-version "0.1.0"
working-dir "inherit"
// Optional integrity pin and default prefix arguments:
// sha256 "e3b0c44298fc1c149afbf4c8996fb924..."
// args "--color=auto"
}
- SH-7
-
A conforming shim MUST register the canonical human command name (for example
synapseq, neversynapseq-v4.43.1-windows-amd64), following Command Namespace principles. Version, architecture, and platform tags belong in the private target path, not in the exposed command name.
Execution fidelity
- SH-8
-
A shim MUST preserve the caller’s working directory (
working-dir "inherit"by default), inheritedstdin/stdout/stderrhandles, TTY/console attachment, environment variables, and raw command-line arguments (including spaces, quotes, and Unicode) verbatim. - SH-9
-
A shim MUST propagate the target process’s exact exit code (
0,1,2, etc.) to the caller. - SH-10
-
On Windows, a shim MUST attach the child process to a Win32 Job Object (
JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE) and forward console control signals (CTRL_C_EVENT,CTRL_BREAK_EVENT) cleanly without printing any prompt or leaving orphaned children when the shim terminates.
Ownership, conflicts, and lifecycle
- SH-11
-
Before creating or replacing a shim, a conforming publisher MUST inspect any existing
<command>.shim.kdl(or existing binary at that path):-
If the path is owned by the same
owner+package, an upgrade MUST update the manifest and binary atomically. -
If the path is owned by a different
ownerorpackage, or is an untracked foreign binary, the publisher MUST NOT silently overwrite it. It MUST fail with an actionable conflict message naming both owners (matching CO-4) unless the user explicitly passes an override flag (such as-forceor confirms interactively).
-
- SH-12
-
On uninstall, a conforming publisher MUST verify ownership in
<command>.shim.kdlbefore removing<command>.exe/<command>and its manifest, and MUST leave zero orphaned shims or stalePATHentries behind.
Intercepting and reconciling legacy PATH installers
Legacy installers and package managers will continue appending per-application directories to Registry PATH for years.
A conforming reconciler (such as DevCentr pathman or osh-shim watch) bridges legacy ecosystems safely without modifying third-party installer binaries or injecting DLLs:
- SH-13
-
A legacy
PATHreconciler on Windows SHOULD monitorHKCU\Environment(and optionallyHKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment) via Win32RegNotifyChangeKeyValuerather than polling or hooking installer processes. - SH-14
-
When a newly appended
PATHdirectory is classified as a single-purpose portable/application directory (for example…\WinGet\Packages\<id>...or a standalone appbin\folder, and NOT an allow-listed toolchain/system root such asSystem32,WindowsApps,.cargo\bin, ornvm), the reconciler MAY (with user policy consent):-
Enumerate public CLI executables in that directory and register conforming
SH-3/SH-6shims in<shim-dir>/autowithowner "reconciler"(or"pathman-auto") and the originating directory recorded assource-path. -
Remove the bloated directory from Registry
PATH(or leave it in place when running in non-destructive overflow-discovery mode). -
Record a reconciliation rule in the user’s ledger so that if an application updater re-appends the same directory later, the watcher silently re-verifies the shim targets and removes the duplicate
PATHentry again.
-
- SH-17
-
Overflow discovery and
autosubfolder isolation (pathman extend): APATHextender/reconciler that auto-imports binaries from existing or overflowedPATHdirectories MUST place those auto-imported shims inside<shim-dir>/autorather than the base<shim-dir>, keeping human/installer-owned shims cleanly separated from machine-discovered shims.-
Overflow-first default: To minimize duplicate noise in legacy
where.exeandwhich.exelookups, an extender SHOULD default to importing binaries only from overflowedPATHdirectories (directories whose cumulative expanded offset exceeds Windows' 2,047-character legacy ceiling or that are omitted from the live processPATH) plus any explicitly configured extended directories, while offering an opt-in full-discovery mode (--mode=all). -
Precedence-preserving duplicate handling: Before creating an auto-imported shim for
<command>, the extender MUST skip<command>if: (1) an explicit shim already exists in the base<shim-dir>, (2) in overflow mode,<command>already resolves in an earlier non-overflowedPATHdirectory (preventing priority inversion), or (3)<command>was already claimed by an earlier directory inPATHorder (first-seen wins; shadowed candidates SHOULD be recorded in the.shim.kdlmanifest or conflict report). System roots (System32,SysWOW64,Windows,WindowsApps) and common installer/uninstaller helpers (unins000.exe,uninstall.exe,setup.exe) MUST be excluded by default. -
Shim-aware resolution: Because
System32\where.exeand third-partywhich.exebinaries do not read.shim.kdlmanifests (and MUST NOT be DLL-hooked), a conformingPATHtool SHOULD provide a shim-aware resolver (such aspathman which/pathman where/pathman — <cmd>) that dereferences.shim.kdlmanifests to show the real target, truncation state, and shadowed duplicates, plus an optional TTY-aware shell hook for interactive shells.
-
Adoption scaffolding and installer builders
- SH-15
-
Conforming installer builders (including DevCentr Ibex,
msi-generator, Inno Setup templates, and NSIS headers) MUST default toSH-1shim registration for CLI executables rather than rawPATHappends, placing both<shim-dir>and<shim-dir>/autoat the highest priority inPATHand exposing rawPATHmutation only as an explicit legacy escape hatch. - SH-16
-
To claim conformance with this standard, a publisher MUST pass the automated self-test suite in CLI Shims Conformance.