VS Code Debugging and launch.json Cheat Sheet

Sidebar

Programming · VS Code Debugging and launch.json Cheat Sheet

Debugging controls, breakpoint types, the structure of launch.json, the Python (debugpy) attributes, and the debug.* settings. Exact ID, what it does, and its default. Sheet 9 in the VS Code series.

Running & Stepping

F5Start debugging (or continue when paused)
Ctrl+F5Run without debugging
Shift+F5 / Ctrl+Shift+F5Stop / restart the debug session
F10 / F11 / Shift+F11Step over / step into / step out
Ctrl+Shift+DOpen the Run and Debug view
Ctrl+Shift+YOpen the Debug Console
Run > Add Configuration…Add an entry to launch.json from a template

Breakpoints

F9Toggle a breakpoint on the current line (or click in the gutter)
Add Conditional Breakpoint…Right-click the gutter: stop only when an expression is true, or after a hit count
Add Logpoint…Right-click the gutter: print a message, with {variable} in braces, without stopping
Shift+F9Add an inline breakpoint at the cursor (several per line)
Breakpoints viewEnable, disable, edit or remove breakpoints; checkbox on each, and a button to toggle all
debug.gutterMiddleClickActionMiddle-click on the gutter: logpoint (default), conditionalBreakpoint, triggeredBreakpoint, none
debug.allowBreakpointsEverywhereAllow breakpoints in any file type (default false)
debug.showBreakpointsInOverviewRulerMark breakpoints in the scroll bar (default false)

launch.json Basics

.vscode/launch.jsonThe file in your project that stores debug configurations
"version": "0.2.0"The version field at the top of the file
configurationsThe array of debug setups that appear in the Run and Debug dropdown
typeRequired: which debugger to use, e.g. debugpy, node, msedge
requestRequired: launch (start the program) or attach (join one that is running)
nameRequired: the label shown in the dropdown
compoundsStart several configurations together: { "name": …, "configurations": […], "stopAll": true }

Common launch.json Attributes

programThe file or executable to run
argsArguments passed to the program (an array)
cwdWorking folder for the run
env / envFileEnvironment variables inline / loaded from a file
consoleinternalConsole, integratedTerminal, externalTerminal
stopOnEntryPause as soon as the program starts
preLaunchTask / postDebugTaskRun a task (from tasks.json) before / after the session
internalConsoleOptionsWhen the Debug Console opens: neverOpen, openOnSessionStart, openOnFirstSessionStart
presentationOrder, group and hidden state in the dropdown
serverReadyActionDo something (e.g. open a browser) when the app says its server is ready
windows / linux / osxPlatform blocks that override other attributes (but not type)

Variables You Can Use in launch.json

${workspaceFolder}The folder you opened in VS Code
${file}The file in the active editor
${relativeFile}That file, relative to the workspace folder
${fileBasename}File name with extension, e.g. app.py
${fileBasenameNoExtension}File name without extension, e.g. app
${fileDirname}Folder of the active file
${env:NAME}The value of an environment variable
${input:id}A value you are asked for when the session starts (defined in inputs)
${command:id}The result of a VS Code command

Python Debugger (type: debugpy)

programA Python file to run, e.g. ${file}
moduleRun a module instead, e.g. "uvicorn"
argsFor FastAPI: ["main:app", "--reload"] with module set to uvicorn
consoleintegratedTerminal (default), externalTerminal, internalConsole
justMyCodetrue (default): skip library code when stepping; set false to step into it
stopOnEntryPause on the first line (default false)
subProcessAlso debug child processes (default false)
showReturnValueShow a function's return value after stepping over it (default true)
redirectOutputSend program output to the Debug Console (default true)
django / jinja / pyramidSwitches that enable framework-specific debugging features
python / pythonArgsUse a specific interpreter / pass options to it

Debug Behaviour (debug.*)

debug.openDebugWhen to open the Debug view: openOnDebugBreak (default), openOnSessionStart, openOnFirstSessionStart, neverOpen
debug.saveBeforeStartSave before a session: allEditorsInActiveGroup (default), nonUntitledEditorsInActiveGroup, none
debug.focusEditorOnBreakBring the editor into focus when paused (default true)
debug.focusWindowOnBreakBring the window to the front when paused (default true)
debug.onTaskErrorsIf the pre-launch task fails: prompt (default), debugAnyway, showErrors, abort
debug.confirmOnExitAsk before closing VS Code during a session: never (default) or always
debug.inlineValuesShow variable values beside the code: auto (default), on, off
debug.showVariableTypesShow types in the Variables view (default false)
debug.toolBarLocationfloating (default), docked, commandCenter, hidden
debug.showInStatusBaronFirstSessionStart (default), always, never
debug.enableStatusBarColorChange the status bar colour while debugging (default true)
debug.terminal.clearBeforeReusingClear a reused debug terminal first (default false)

Debug Console (debug.console.*)

debug.console.fontSizeText size (default 14; 12 on macOS)
debug.console.fontFamilyFont (default: follows the editor)
debug.console.lineHeight0 (default) means automatic
debug.console.wordWrapWrap long lines (default true)
debug.console.maximumLinesLines kept before old ones drop off (default 10000)
debug.console.collapseIdenticalLinesFold repeated identical lines into one with a count (default true)
debug.console.historySuggestionsSuggest earlier input as you type (default true)
debug.console.acceptSuggestionOnEnterEnter accepts the suggestion: off (default) or on
debug.console.closeOnEndClose the console when the session ends (default false)

Other Common Debugger Types (examples)

"type": "node", "program": "${workspaceFolder}/app.js"Node.js: run a script; add skipFiles to avoid stepping into Node's own code
"type": "msedge", "url": "http://localhost:3000"Browser debugging in Edge, with webRoot pointing at your source
"type": "chrome", "url": "http://localhost:3000"The same idea for Chrome
request: attachJoin a program that is already running in debug mode, using port or processId
A starting point for debugging a FastAPI app
In .vscode/launch.json, inside configurations: { "name": "FastAPI", "type": "debugpy", "request": "launch", "module": "uvicorn", "args": ["main:app", "--reload"], "jinja": true }. Adjust main:app to your own file and app name. With --reload the server restarts on file changes; if breakpoints behave oddly, try removing it.
Breakpoints in library code are skipped? That's justMyCode
For Python, justMyCode defaults to true, so the debugger steps over code in installed packages. Set "justMyCode": false in the configuration when you want to step into a library.