Understanding the Klyx plugin lifecycle — load, start, stop, and unload
Klyx manages your extension through four lifecycle methods. Each method is a suspend function running on the plugin’s coroutine scope, so you can safely call other suspend APIs.
Called when Klyx loads your extension. At this point, your plugin’s services (screens, toolbar, etc.) are available, but other plugins may not have started yet.What to do here:
Register screens with ScreenRegistry
Register toolbar actions with ToolbarRegistry
Register file openers with FileOpenerRegistry
Subscribe to events on the event bus
Register language server providers
Register tree-sitter language grammars
Initialize lightweight state
override suspend fun onLoad() { val bus = currentPluginContext().eventBus screens.register(Screen(ScreenId("myext.main")) { MainScreen() }) toolbar.register(ToolbarAction( id = "myext.action", label = "My Action", category = ToolbarCategory("My Plugin"), priority = 100, onClick = { /* ... */ } ) {}) // Subscribe to events bus.subscribe<FileOpenedEvent> { event -> showToast("Opened: ${event.fileName}") }}
Called after all plugins have completed onLoad(). This is the right place to interact with other plugins, access shared resources, or start ongoing work.What to do here:
Start coroutines for background work (via pluginScope or currentLifecycleOwner().lifecycleScope)
Access other plugins’ registered resources
Start long-running operations that depend on the full environment
override suspend fun onStart() { pluginScope.launch { // Background work tied to the plugin's lifetime val result = command("git", "status").output() showToast(result.stdoutText) }}
Called after onStop() completes. This is your last chance to clean up before the plugin classloader is discarded.What to do here:
Unregister all screens
Unregister all toolbar actions
Unregister file openers
Unregister language server providers
Unregister language grammars
Cancel all coroutines
Unsubscribe from all event bus subscriptions
override suspend fun onUnload() { screens.unregister(ScreenId("myext.main")) toolbar.unregister("myext.action") busSubscription?.cancel() fileOpenerRegistration?.unregister()}
If you do not unregister screens and toolbar actions in onUnload(), they will leak. Klyx automatically cleans up registrations when a plugin crashes, but you should still unregister explicitly for a clean shutdown.
pluginScope — Created when the plugin loads and cancelled when it unloads. Use this for background tasks that should persist across start/stop cycles.
currentLifecycleOwner().lifecycleScope — Tied to the started/stopped lifecycle state. Coroutines are cancelled when the plugin stops.
Both scopes carry a PluginContextElement, so coroutines launched on them can access currentPluginContext() and currentLifecycleOwner().
override suspend fun onLoad() { // Tied to plugin load/unload lifecycle pluginScope.launch { // This runs even when the plugin is stopped } val owner = currentLifecycleOwner() // Tied to start/stop lifecycle owner.lifecycleScope.launch { // This is cancelled when onStop() is called }}
If a plugin throws an unhandled exception during any lifecycle method, Klyx marks the plugin as crashed. The plugin’s scope is cancelled, its lifecycle is destroyed, and all its screen and toolbar registrations are automatically removed. A crash file is persisted so the plugin can be disabled on next startup if needed.You can check if a plugin has crashed via the crash(t: Throwable) method on the internal PluginRuntime.
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"Klyx Extension Docs","colors":{"primary":"#6366F1","light":"#818CF8","dark":"#4F46E5"},"logo":{"light":"https://mintcdn.com/klyx/Dvo5WBmLzfq6tWgD/logo/light.svg?fit=max\u0026auto=format\u0026n=Dvo5WBmLzfq6tWgD\u0026q=85\u0026s=d5958c526a4a580a43ebadb78569d25d","dark":"https://mintcdn.com/klyx/Dvo5WBmLzfq6tWgD/logo/dark.svg?fit=max\u0026auto=format\u0026n=Dvo5WBmLzfq6tWgD\u0026q=85\u0026s=199b0c5f4060ff67d0c97094711d0b9a"},"favicon":"https://mintcdn.com/klyx/WB-n7hHAxBpEpol-/favicon.svg?fit=max\u0026auto=format\u0026n=WB-n7hHAxBpEpol-\u0026q=85\u0026s=e9f841c908fd1b184de1807c76fd290e","navbar":{"links":[]},"footer":{"socials":{"github":"https://github.com/klyx-dev"}},"contextual":{"options":["copy","view"],"display":"header"},"styling":{"latex":false},"navigation":{"global":{"anchors":[{"anchor":"Plugin Registry","icon":"box","color":{"light":"#09090B","dark":"#E5E7EB"},"href":"https://github.com/klyx-dev/plugins"},{"anchor":"Klyx GitHub","icon":"code","color":{"light":"#09090B","dark":"#FFFFFF"},"href":"https://github.com/klyx-dev"}]},"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"klyx","hasAudioNarration":false,"actualSubdomain":"klyx","customDomains":[],"gitSource":{"type":"github","owner":"klyx-dev","repo":"docs","deployBranch":"main","contentDirectory":"","isPrivate":false,"mountPath":"","label":""},"chroma":{"collectionId":"f626e69e-d0a1-4db3-8d72-ab2d7dd008b4","liveDeploymentHistoryId":"6a74656d39d20664a53809d6","schemaVersion":"v3","latestBuiltDeploymentHistoryId":"6a74656d39d20664a53809d6"},"entitlements":{},"buildId":"6a74656d39d20664a53809d6:success","clientVersion":"0.0.4021","searchFilterCounts":[{"language":"default","tag":"API Reference","count":15},{"language":"default","tag":"Extensions","count":5},{"language":"default","tag":"Getting Started","count":2}]},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":false,"enableContextualStarterQuestions":false,"enableAskAiSearchBar":true},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"byok-sep-25","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"vite-origin","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-updated-9-15","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"sso-setup-deadline-banner","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":false},"customCss":[],"page":{"pagePath":"extensions/lifecycle","slug":"/extensions/lifecycle","pageMetadata":{"title":"Plugin Lifecycle","description":"Understanding the Klyx plugin lifecycle — load, start, stop, and unload","href":"/extensions/lifecycle"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Understanding the Klyx plugin lifecycle — load, start, stop, and unload\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={code:`code`,li:`li`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,tbody:`tbody`,td:`td`,th:`th`,thead:`thead`,tr:`tr`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,Heading,Table,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Table)_missingMdxReference(`Table`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsx(_components.p,{children:`Klyx manages your extension through four lifecycle methods. Each method is a suspend function running on the plugin’s coroutine scope, so you can safely call other suspend APIs.`}),`\n`,_jsx(Heading,{level:`2`,id:`lifecycle-overview`,children:`Lifecycle overview`}),`\n`,_jsx(CodeBlock,{numberOfLines:`2`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`2`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`Load → onLoad() → onStart() → (running) → onStop() → onUnload() → Unloaded`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Phase`}),_jsx(_components.th,{children:`Method`}),_jsx(_components.th,{children:`Purpose`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{\"data-numeric\":`true`,children:`1`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`onLoad()`})}),_jsx(_components.td,{children:`Register resources, subscribe to events, set up infrastructure`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{\"data-numeric\":`true`,children:`2`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`onStart()`})}),_jsx(_components.td,{children:`Begin operations that depend on other plugins`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{\"data-numeric\":`true`,children:`3`}),_jsx(_components.td,{children:`onStop`}),_jsx(_components.td,{children:`(Triggerable by user or system)`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{\"data-numeric\":`true`,children:`4`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`onStop()`})}),_jsx(_components.td,{children:`Pause or release start-time resources`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{\"data-numeric\":`true`,children:`5`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`onUnload()`})}),_jsx(_components.td,{children:`Full cleanup — unregister everything`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{\"data-numeric\":`true`,children:`6`}),_jsx(_components.td,{children:`Unloaded`}),_jsx(_components.td,{children:`Plugin removed from memory`})]})]})]}),`\n`,_jsx(Heading,{level:`2`,id:`onload`,children:`onLoad()`}),`\n`,_jsx(_components.p,{children:`Called when Klyx loads your extension. At this point, your plugin’s services (screens, toolbar, etc.) are available, but other plugins may not have started yet.`}),`\n`,_jsx(_components.p,{children:_jsx(_components.strong,{children:`What to do here:`})}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`Register screens with `,_jsx(_components.code,{children:`ScreenRegistry`})]}),`\n`,_jsxs(_components.li,{children:[`Register toolbar actions with `,_jsx(_components.code,{children:`ToolbarRegistry`})]}),`\n`,_jsxs(_components.li,{children:[`Register file openers with `,_jsx(_components.code,{children:`FileOpenerRegistry`})]}),`\n`,_jsx(_components.li,{children:`Subscribe to events on the event bus`}),`\n`,_jsx(_components.li,{children:`Register language server providers`}),`\n`,_jsx(_components.li,{children:`Register tree-sitter language grammars`}),`\n`,_jsx(_components.li,{children:`Initialize lightweight state`}),`\n`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`18`,language:`kotlin`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`kotlin`,children:_jsxs(_components.code,{language:`kotlin`,numberOfLines:`18`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`override`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` suspend`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` fun`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` onLoad`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`() {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` val`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` bus `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` currentPluginContext`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`().eventBus`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` screens.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`register`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`Screen`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`ScreenId`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"myext.main\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)) { `}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`MainScreen`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`() })`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` toolbar.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`register`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`ToolbarAction`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` id `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"myext.action\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` label `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"My Action\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` category `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` ToolbarCategory`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"My Plugin\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`),`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` priority `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 100`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` onClick `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`/* ... */`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ) {})`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // Subscribe to events`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` bus.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`subscribe`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`\u003c`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#4EC9B0`},children:`FileOpenedEvent`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`> { event `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`->`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` showToast`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Opened: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:\"${\"}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#D4D4D4`},children:`event.fileName`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`onstart`,children:`onStart()`}),`\n`,_jsxs(_components.p,{children:[`Called after all plugins have completed `,_jsx(_components.code,{children:`onLoad()`}),`. This is the right place to interact with other plugins, access shared resources, or start ongoing work.`]}),`\n`,_jsx(_components.p,{children:_jsx(_components.strong,{children:`What to do here:`})}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`Start coroutines for background work (via `,_jsx(_components.code,{children:`pluginScope`}),` or `,_jsx(_components.code,{children:`currentLifecycleOwner().lifecycleScope`}),`)`]}),`\n`,_jsx(_components.li,{children:`Access other plugins’ registered resources`}),`\n`,_jsx(_components.li,{children:`Start long-running operations that depend on the full environment`}),`\n`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`7`,language:`kotlin`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`kotlin`,children:_jsxs(_components.code,{language:`kotlin`,numberOfLines:`7`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`override`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` suspend`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` fun`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` onStart`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`() {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` pluginScope.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`launch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // Background work tied to the plugin's lifetime`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` val`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` result `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` command`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"git\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"status\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`).`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`output`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`()`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` showToast`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(result.stdoutText)`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`onstop`,children:`onStop()`}),`\n`,_jsxs(_components.p,{children:[`Called when Klyx is about to unload your extension. You should release any resources acquired in `,_jsx(_components.code,{children:`onStart()`}),`.`]}),`\n`,_jsx(_components.p,{children:_jsx(_components.strong,{children:`What to do here:`})}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`Cancel ongoing operations started in `,_jsx(_components.code,{children:`onStart()`})]}),`\n`,_jsx(_components.li,{children:`Close file handles or network connections`}),`\n`,_jsx(_components.li,{children:`Save any state that needs persistence`}),`\n`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`3`,language:`kotlin`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`kotlin`,children:_jsxs(_components.code,{language:`kotlin`,numberOfLines:`3`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`override`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` suspend`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` fun`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` onStop`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`() {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` showToast`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Stopping...\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`onunload`,children:`onUnload()`}),`\n`,_jsxs(_components.p,{children:[`Called after `,_jsx(_components.code,{children:`onStop()`}),` completes. This is your last chance to clean up before the plugin classloader is discarded.`]}),`\n`,_jsx(_components.p,{children:_jsx(_components.strong,{children:`What to do here:`})}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:`Unregister all screens`}),`\n`,_jsx(_components.li,{children:`Unregister all toolbar actions`}),`\n`,_jsx(_components.li,{children:`Unregister file openers`}),`\n`,_jsx(_components.li,{children:`Unregister language server providers`}),`\n`,_jsx(_components.li,{children:`Unregister language grammars`}),`\n`,_jsx(_components.li,{children:`Cancel all coroutines`}),`\n`,_jsx(_components.li,{children:`Unsubscribe from all event bus subscriptions`}),`\n`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`6`,language:`kotlin`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`kotlin`,children:_jsxs(_components.code,{language:`kotlin`,numberOfLines:`6`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`override`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` suspend`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` fun`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` onUnload`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`() {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` screens.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`unregister`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`ScreenId`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"myext.main\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`))`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` toolbar.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`unregister`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"myext.action\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` busSubscription?.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`cancel`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`()`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` fileOpenerRegistration?.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`unregister`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`()`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[`If you do not unregister screens and toolbar actions in `,_jsx(_components.code,{children:`onUnload()`}),`, they will leak. Klyx automatically cleans up registrations when a plugin crashes, but you should still unregister explicitly for a clean shutdown.`]})}),`\n`,_jsx(Heading,{level:`2`,id:`coroutine-scopes`,children:`Coroutine scopes`}),`\n`,_jsx(_components.p,{children:`Your plugin has two coroutine scopes available:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`pluginScope`}),` — Created when the plugin loads and cancelled when it unloads. Use this for background tasks that should persist across start/stop cycles.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`currentLifecycleOwner().lifecycleScope`}),` — Tied to the started/stopped lifecycle state. Coroutines are cancelled when the plugin stops.`]}),`\n`]}),`\n`,_jsxs(_components.p,{children:[`Both scopes carry a `,_jsx(_components.code,{children:`PluginContextElement`}),`, so coroutines launched on them can access `,_jsx(_components.code,{children:`currentPluginContext()`}),` and `,_jsx(_components.code,{children:`currentLifecycleOwner()`}),`.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`12`,language:`kotlin`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`kotlin`,children:_jsxs(_components.code,{language:`kotlin`,numberOfLines:`12`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`override`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` suspend`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` fun`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` onLoad`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`() {`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // Tied to plugin load/unload lifecycle`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` pluginScope.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`launch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // This runs even when the plugin is stopped`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` val`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` owner `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` currentLifecycleOwner`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`()`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // Tied to start/stop lifecycle`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` owner.lifecycleScope.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`launch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // This is cancelled when onStop() is called`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`crash-handling`,children:`Crash handling`}),`\n`,_jsx(_components.p,{children:`If a plugin throws an unhandled exception during any lifecycle method, Klyx marks the plugin as crashed. The plugin’s scope is cancelled, its lifecycle is destroyed, and all its screen and toolbar registrations are automatically removed. A crash file is persisted so the plugin can be disabled on next startup if needed.`}),`\n`,_jsxs(_components.p,{children:[`You can check if a plugin has crashed via the `,_jsx(_components.code,{children:`crash(t: Throwable)`}),` method on the internal `,_jsx(_components.code,{children:`PluginRuntime`}),`.`]})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"Plugin Lifecycle","description":"Understanding the Klyx plugin lifecycle — load, start, stop, and unload","href":"/extensions/lifecycle"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"Lifecycle overview","slug":"lifecycle-overview","depth":2,"children":[]},{"title":"onLoad()","slug":"onload","depth":2,"children":[]},{"title":"onStart()","slug":"onstart","depth":2,"children":[]},{"title":"onStop()","slug":"onstop","depth":2,"children":[]},{"title":"onUnload()","slug":"onunload","depth":2,"children":[]},{"title":"Coroutine scopes","slug":"coroutine-scopes","depth":2,"children":[]},{"title":"Crash handling","slug":"crash-handling","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":[],"subdomain":"klyx","siteName":"Klyx Extension Docs","title":"Plugin Lifecycle - Klyx Extension Docs","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-08-01T22:24:07.649Z","originalFileLocation":"extensions/lifecycle.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Understanding the Klyx plugin lifecycle — load, start, stop, and unload\">\u003cmeta data-mint-head name=\"application-name\" content=\"Klyx Extension Docs\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/klyx/6xLIsAIfphR8D77h/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/klyx/6xLIsAIfphR8D77h/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/klyx/6xLIsAIfphR8D77h/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/klyx/6xLIsAIfphR8D77h/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/klyx/6xLIsAIfphR8D77h/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/klyx/6xLIsAIfphR8D77h/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/klyx/6xLIsAIfphR8D77h/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/klyx/6xLIsAIfphR8D77h/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/klyx/6xLIsAIfphR8D77h/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Plugin Lifecycle - Klyx Extension Docs\">\u003cmeta data-mint-head property=\"og:description\" content=\"Understanding the Klyx plugin lifecycle — load, start, stop, and unload\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Klyx Extension Docs\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://klyx.mintlify.app/extensions/lifecycle\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://klyx.mintlify.app/_mintlify/api/og/v2?division=Extensions\u0026amp;title=Plugin+Lifecycle\u0026amp;description=Understanding+the+Klyx+plugin+lifecycle+%E2%80%94+load%2C+start%2C+stop%2C+and+unload\u0026amp;theme=c0a1700147e5063d1fb34356\u0026amp;signature=55d806e5be82afe1766322d7ffff57aaee53d4d06a2ca4e7ef3a4cf945d00027\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Plugin Lifecycle - Klyx Extension Docs\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Understanding the Klyx plugin lifecycle — load, start, stop, and unload\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://klyx.mintlify.app/_mintlify/api/og/v2?division=Extensions\u0026amp;title=Plugin+Lifecycle\u0026amp;description=Understanding+the+Klyx+plugin+lifecycle+%E2%80%94+load%2C+start%2C+stop%2C+and+unload\u0026amp;theme=c0a1700147e5063d1fb34356\u0026amp;signature=55d806e5be82afe1766322d7ffff57aaee53d4d06a2ca4e7ef3a4cf945d00027\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/klyx/6xLIsAIfphR8D77h/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Klyx Extension Docs\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#6366F1\">\u003clink data-mint-head rel=\"canonical\" href=\"https://klyx.mintlify.app/extensions/lifecycle\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/extensions/lifecycle.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://klyx.mintlify.app/#organization\",\"name\":\"Klyx Extension Docs\",\"url\":\"https://klyx.mintlify.app\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/klyx/Dvo5WBmLzfq6tWgD/logo/light.svg?fit=max\u0026auto=format\u0026n=Dvo5WBmLzfq6tWgD\u0026q=85\u0026s=d5958c526a4a580a43ebadb78569d25d\"}},{\"@type\":\"WebSite\",\"@id\":\"https://klyx.mintlify.app#website\",\"name\":\"Klyx Extension Docs\",\"url\":\"https://klyx.mintlify.app\",\"publisher\":{\"@id\":\"https://klyx.mintlify.app/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://klyx.mintlify.app/extensions/lifecycle#webpage\",\"url\":\"https://klyx.mintlify.app/extensions/lifecycle\",\"name\":\"Plugin Lifecycle\",\"description\":\"Understanding the Klyx plugin lifecycle — load, start, stop, and unload\",\"dateModified\":\"2026-08-01T22:24:07.649Z\",\"isPartOf\":{\"@id\":\"https://klyx.mintlify.app#website\"},\"breadcrumb\":{\"@id\":\"https://klyx.mintlify.app/extensions/lifecycle#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://klyx.mintlify.app/extensions/lifecycle#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Extensions\",\"item\":\"https://klyx.mintlify.app/extensions/index\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Plugin Lifecycle\",\"item\":\"https://klyx.mintlify.app/extensions/lifecycle\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://klyx.mintlify.app/extensions/lifecycle#article\",\"headline\":\"Plugin Lifecycle\",\"name\":\"Plugin Lifecycle\",\"description\":\"Understanding the Klyx plugin lifecycle — load, start, stop, and unload\",\"url\":\"https://klyx.mintlify.app/extensions/lifecycle\",\"mainEntityOfPage\":{\"@id\":\"https://klyx.mintlify.app/extensions/lifecycle#webpage\"},\"dateModified\":\"2026-08-01T22:24:07.649Z\",\"publisher\":{\"@id\":\"https://klyx.mintlify.app/#organization\"},\"isPartOf\":{\"@id\":\"https://klyx.mintlify.app#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Klyx Extension Docs\",\"creator\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","siteName":"Klyx Extension Docs","nav":{"global":{"anchors":[{"anchor":"Plugin Registry","icon":"box","color":{"light":"#09090B","dark":"#E5E7EB"},"href":"https://github.com/klyx-dev/plugins"},{"anchor":"Klyx GitHub","icon":"code","color":{"light":"#09090B","dark":"#FFFFFF"},"href":"https://github.com/klyx-dev"}]},"pages":[{"group":"Getting Started","pages":[{"title":"Klyx Extension Development","href":"/index"},{"title":"Quickstart","href":"/quickstart"}]},{"group":"Extensions","pages":[{"title":"Extensions","href":"/extensions/index"},{"title":"Creating an Extension","href":"/extensions/creating"},{"title":"Plugin Manifest","description":"Reference for the @PluginManifest annotation","href":"/extensions/manifest"},{"title":"Plugin Lifecycle","href":"/extensions/lifecycle"},{"title":"Building \u0026 Bundling","description":"How to build, bundle, and distribute Klyx extensions","href":"/extensions/building"}]},{"group":"API Reference","pages":[{"title":"API Reference","href":"/extensions/api-reference/index"},{"title":"Services \u0026 Dependency Injection","href":"/extensions/api-reference/services"},{"title":"Screens \u0026 Navigation","href":"/extensions/api-reference/screens"},{"title":"Toolbar","href":"/extensions/api-reference/toolbar"},{"title":"File System","href":"/extensions/api-reference/file-system"},{"title":"Editor \u0026 Workspace Tabs","href":"/extensions/api-reference/editor"},{"title":"Terminal","href":"/extensions/api-reference/terminal"},{"title":"File Runners","href":"/extensions/api-reference/runners"},{"title":"Processes \u0026 Pipelines","href":"/extensions/api-reference/processes"},{"title":"Events","href":"/extensions/api-reference/events"},{"title":"Settings","href":"/extensions/api-reference/settings"},{"title":"Plugin Settings","href":"/extensions/api-reference/plugin-settings"},{"title":"Language Server","href":"/extensions/api-reference/language-server"},{"title":"Language Registry","href":"/extensions/api-reference/language-registry"},{"title":"Utilities","href":"/extensions/api-reference/utilities"}]}]},"title":"Plugin Lifecycle - Klyx Extension Docs","buildId":"dpl_EnxDqhjaNc9a8MVa833TGULPd9uJ","deploymentId":"dpl_EnxDqhjaNc9a8MVa833TGULPd9uJ","dynamics":[],"chunks":[]}