# Connect to default kernel from SessionContext

**URL:** <https://discourse.jupyter.org/t/connect-to-default-kernel-from-sessioncontext/15145>\
**Category:** JupyterLab\
**Tags:** how-to, help-wanted\
**Created:** [July 30, 2022, 11:09am UTC](https://discourse.jupyter.org/t/connect-to-default-kernel-from-sessioncontext/15145 "2022-07-30T11:09:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rakesh\_K](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/rakesh_k/32/7108_2.png) [@Rakesh\_K](https://discourse.jupyter.org/u/Rakesh_K)\
**Post date:** [July 30, 2022, 11:09am UTC](https://discourse.jupyter.org/t/connect-to-default-kernel-from-sessioncontext/15145/1 "2022-07-30T11:09:55Z")

</div>

I am trying to use SessionContext object in my extension to connect to a kernel so that I can run some Python code based on user actions in my extension’s widgets. I followed the example code in [extension-examples/kernel-messaging at master · jupyterlab/extension-examples · GitHub](https://github.com/jupyterlab/extension-examples/tree/master/kernel-messaging) but this shows up a pop-up to select the kernel everytime the extension is activated. How do I connect to the default kernel instead of showing the pop-up for kernel selection?

Thanks,  
Rakesh.

---

<div class="post-metadata">

**Author:** ![Rakesh\_K](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/rakesh_k/32/7108_2.png) [@Rakesh\_K](https://discourse.jupyter.org/u/Rakesh_K)\
**Post date:** [July 30, 2022, 11:35am UTC](https://discourse.jupyter.org/t/connect-to-default-kernel-from-sessioncontext/15145/2 "2022-07-30T11:35:10Z")

</div>

I actually figured it out - I had to pass ‘kernelPreference’ to the constructor of the SessionContext class with ‘autoStartDefault’ set to true like so:

```auto
this._sessionContext = new SessionContext({
            sessionManager: manager.sessions,
            specsManager: manager.kernelspecs,
            name: 'Example Extension',
            kernelPreference: {autoStartDefault:true}
          });

```
