Now I have read all the relevant code. Let me trace the issue:
- In
main.ts, buildSessionOptions() at lines 206-208:
The condition extensionsResult.extensions.length > 0 means when --no-extensions is passed, the empty array result is not passed through.
- In
sdk.ts, at the createAgentSession() function, around lines 274-289:
If options.preloadedExtensions is undefined, it falls through to the discovery branch and calls discoverAndLoadExtensions().
The root cause is clear: when --no-extensions is used, the empty result gets filtered out in main.ts, so preloadedExtensions stays undefined. This causes createAgentSession() to skip the preloaded check and instead trigger the discovery logic, which loads extensions anyway. The fix is straightforward—remove the length check so the empty array gets passed through as intended.
Looking at the actual code location, the problematic condition is:
This needs to become:
Since extensionsResult is always assigned earlier in the flow, we could technically remove the condition entirely, but keeping the safety check aligns with the proposed solution and maintains defensive coding practices.