Uh oh!
There was an error while loading. Please reload this page.
refactor(opencode): lazily load cli commands - #36798
Conversation
Signed-off-by: Xiaobo Liu <cppcoffee@gmail.com>
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
sebishogun
commented
Aug 7, 2026
Seconding this. |
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Issue for this PR
Optimize process startup speed.
Type of change
What does this PR do?
This PR improves the opencode CLI startup path by lazily loading command modules instead of importing every command during process initialization.
Previously,
packages/opencode/src/index.tsimported all CLI commands eagerly, even when the user only ran one command, checked the version, or launched the default TUI. This made startup do unnecessary module loading work.The change replaces those static command imports with command-specific dynamic imports. The CLI now detects the requested command from argv and only registers the command needed for that invocation. It still loads all commands when required for help or shell completion generation, so command discovery behavior is preserved.
This also moves heap initialization behind a dynamic import so that it is only loaded when the command middleware actually starts the agent process.
How did you verify your code works?
I verified the change locally by checking the CLI still selects and registers the expected commands for normal command execution, default TUI startup, version/help paths, and completion/help cases where all commands need to be available.
Screenshots / recordings
Not applicable. This is not a UI change.
Checklist
How did you verify your code works?
I tested the affected CLI startup paths locally, including default startup, command-specific startup, help/completion behavior, and version handling.