Writing Python code inside Jupyter Notebook cells in VS Code can be slow when you must type every function, loop, or data transformation manually. GitHub Copilot suggests entire code blocks, function definitions, and inline comments as you type. This article explains how to enable Copilot for Jupyter Notebooks, how to trigger suggestions inside cells, and how to accept or reject them.
Copilot integrates directly with VS Code’s notebook editor. It reads the context from previous cells, variable names, and markdown descriptions to generate relevant code. You do not need a separate plugin or extension beyond the standard GitHub Copilot extension for VS Code.
This article covers the setup, the keyboard shortcuts for inline suggestions, and common issues when Copilot does not respond inside a cell.
Key Takeaways: Using GitHub Copilot in Jupyter Notebooks
- VS Code Extension > GitHub Copilot > Install: Required before Copilot works in any file including notebook cells.
- Ctrl+Enter inside a code cell: Triggers the inline suggestion popup when Copilot does not show a ghost text.
- Tab or Enter to accept a suggestion: Tab inserts the full suggestion; Enter inserts only the first line of the suggestion.
How Copilot Works Inside Jupyter Notebook Cells
GitHub Copilot is a code completion tool that uses the OpenAI Codex model. When you install the GitHub Copilot extension in VS Code version 1.68 or later, Copilot activates automatically for all supported file types including Python files, JavaScript files, and Jupyter Notebook .ipynb files.
Inside a Jupyter Notebook cell, Copilot reads the context from three sources:
- Markdown cells directly above the current code cell.
- Code in previous cells that have already been executed.
- Comments and variable names typed in the current cell.
Copilot does not see data from cells that have not been run. If you want Copilot to consider the output of a previous cell, you must run that cell first. Copilot also ignores cells that contain syntax errors.
Prerequisites
- VS Code 1.68 or later.
- GitHub Copilot extension installed from the VS Code Marketplace.
- An active GitHub Copilot subscription (free trial, Copilot Pro, or Copilot for Business).
- Python extension by Microsoft installed for kernel support.
- Jupyter extension by Microsoft installed for notebook support.
Steps to Use GitHub Copilot Inside a Jupyter Notebook Cell
Follow these steps to start getting Copilot suggestions in your notebook cells.
- Open a Jupyter Notebook in VS Code
Open VS Code and create a new file with the .ipynb extension. Alternatively, open an existing notebook from the File menu. VS Code displays the notebook editor with code cells and markdown cells. - Select the Python kernel
Click the kernel picker in the top-right corner of the notebook editor. Choose a Python environment where the required packages are installed. Copilot uses the kernel only for execution, not for suggestions, but a running kernel is needed to see cell output. - Start typing in a code cell
Click inside an empty code cell. Type a comment that describes what you want to do. For example, type# load the iris dataset and display the first five rows. After typing the comment, press Enter to start a new line. Copilot shows a ghost text suggestion in gray. - Accept the full suggestion
Press Tab to accept the entire ghost text. Press Enter to accept only the first line of the suggestion. If you press Enter and the suggestion continues on multiple lines, press Tab again to accept the next part. - Cycle through alternative suggestions
If Copilot shows a suggestion you do not want, press Ctrl+Enter to open the suggestion popup. Use the arrow keys to scroll through alternatives. Press Tab to accept the highlighted alternative. - Reject a suggestion
Press Escape to dismiss the ghost text. The cell returns to its previous state. You can continue typing and Copilot will generate a new suggestion after a short pause.
Force a Suggestion When Copilot Is Not Responding
Sometimes Copilot does not show a ghost text immediately. This happens when the context is too short or ambiguous. To force a suggestion:
- Type a complete comment or function signature
Write a comment that includes the library name and the action. For example,# use pandas to group by column A and calculate the mean of column B. - Open the Copilot suggestion panel
Press Ctrl+Enter to open the inline suggestion panel. Copilot shows up to ten suggestions. Select one with the arrow keys and press Tab to insert it.
Common Issues When Copilot Does Not Work in Notebook Cells
Copilot Shows No Suggestions in Any Cell
The extension may not be activated. Open the Extensions view in VS Code and check that GitHub Copilot is installed and enabled. Look for the Copilot icon in the status bar at the bottom of the window. If the icon shows a circle with a line through it, click the icon and select Enable. You must also sign in to your GitHub account and authorize the Copilot subscription.
Copilot Only Suggests Single Lines Instead of Full Blocks
This occurs when Copilot has limited context. Write a more detailed comment above the code cell. Include the function name, the library, and the expected output. For example, instead of # load data, write # load the CSV file from the data folder using pandas and return a DataFrame.
Copilot Suggests Code That Does Not Run
Copilot generates code based on patterns it learned from public repositories. The suggested code may use a function or parameter that does not exist in your current environment. Always review the suggestion before accepting it. If the suggestion is incorrect, press Escape and type the correct code manually. Copilot learns from your manual corrections over time.
Copilot Does Not Work After a VS Code Update
A VS Code update can disable the Copilot extension. Restart VS Code after an update. If Copilot still does not appear, go to Extensions, search for GitHub Copilot, and click the Reload button. You may need to sign in again if the authentication token expired.
Copilot Suggestions vs Copilot Chat in Notebooks: Key Differences
| Item | Copilot Suggestions | Copilot Chat |
|---|---|---|
| Trigger | Typing code or comments in a cell | Ctrl+Shift+I or the chat icon |
| Output location | Inline ghost text in the current cell | Separate chat panel or new cell |
| Context scope | Previous cells and current cell content | Entire notebook, selected code, and conversation history |
| Best for | Quick completions of known patterns | Explaining code, debugging, or generating new functions |
Use both features together. Let Copilot Suggestions handle routine completions like imports and loops. Use Copilot Chat for complex logic, error explanations, or when you need to refactor a large block of code.
You can now use GitHub Copilot inside Jupyter Notebook cells to speed up your data analysis and machine learning workflows. Start by installing the GitHub Copilot extension if you have not done so. Next, open a notebook and type a descriptive comment in a code cell to see the first suggestion. For best results, always run previous cells so Copilot can use their output as context. If you work with large notebooks, consider using Copilot Chat to generate new cells from natural language descriptions instead of typing every line manually.