Skip to main content
This lesson demonstrates GitHub Copilot’s Inline Chat feature, which lets developers interact with Copilot directly in their code editor to explain code, refactor, generate new snippets, scaffold tests, and produce documentation.
A minimalist presentation slide showing a dark blue curved shape on the right and the text "Inline Chat" (center) and "Demo" (on the dark shape). A small "© Copyright KodeKloud" appears in the bottom-left.
Quick access:
  • macOS: Command+I
  • Windows / Linux: Ctrl+I
  • Or: right-click the editor → “Copilot Editor → Inline Chat”
Invoke inline chat by selecting code and typing a prompt (for example, explain or /explain). Use “View in Chat” to open the same content in the sidebar chat if you prefer a larger workspace.
Why use Inline Chat
  • Get immediate explanations for selected code.
  • Request refactors or configuration changes in-place.
  • Generate helper functions, unit-test scaffolding, or documentation.
  • Keep context inside the editor — no context switching to a browser.
Short keyboard reference: Explaining code with Inline Chat Select a code block and ask Copilot to explain it. The tool will break down intent, variables, and control flow, and provide a short summary. Example: logic that determines whether a car moving north should stop at a stop line, obey a traffic light, and maintain a safe gap.
Inline Chat typically explains what front represents, why the light state is checked, and how SAFE_GAP prevents collisions. Use /explain or a natural-language prompt like “Explain this logic” to get a line-by-line explanation plus a short summary. Inspecting a method or class Run inline chat against a method or an entire class to get more context. Example Car class with initialization and an update method that contains the above logic:
Refactoring and configuration suggestions Inline Chat can recommend moving hard-coded values to configuration files (JSON, YAML), creating constants, or extracting helper functions. Example: moving colors and constants to a JSON config and loading them at runtime:
Generating helper functions Inline Chat can propose and write helper functions. Example: compute the current traffic light state for a direction given a cycle timer.
Test generation and scaffolding Ask Copilot to produce unit tests for functions such as get_light_state. It can scaffold tests using pytest or unittest, including example assertions you can refine. Example terminal output when installing pytest:
Summary of Inline Chat capabilities
Be mindful of sensitive data. Do not paste secrets, private keys, or proprietary code into inline chat prompts. Review generated code for correctness, edge cases, and security implications before merging.
Best practices
  • Provide focused prompts (e.g., “simplify this loop” or “add edge-case tests for red light behavior”).
  • Use “View in Chat” to move longer interactions into the sidebar for a larger workspace and persistent context.
  • Review and run generated tests locally; treat suggestions as starting points, not final production code.
Links and references This lesson showed how to use Copilot’s Inline Chat to inspect, refactor, and augment code directly inside your editor for faster iteration and clearer code understanding.

Watch Video