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 debuggingShift+F5 / Ctrl+Shift+F5Stop / restart the debug sessionF10 / F11 / Shift+F11Step over / step into / step outCtrl+Shift+DOpen the Run and Debug viewCtrl+Shift+YOpen the Debug ConsoleRun > Add Configuration…Add an entry to launch.json from a templateBreakpoints
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 countAdd Logpoint…Right-click the gutter: print a message, with {variable} in braces, without stoppingShift+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 alldebug.gutterMiddleClickActionMiddle-click on the gutter: logpoint (default), conditionalBreakpoint, triggeredBreakpoint, nonedebug.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 fileconfigurationsThe array of debug setups that appear in the Run and Debug dropdowntypeRequired: which debugger to use, e.g. debugpy, node, msedgerequestRequired: launch (start the program) or attach (join one that is running)nameRequired: the label shown in the dropdowncompoundsStart several configurations together: { "name": …, "configurations": […], "stopAll": true }Common launch.json Attributes
programThe file or executable to runargsArguments passed to the program (an array)cwdWorking folder for the runenv / envFileEnvironment variables inline / loaded from a fileconsoleinternalConsole, integratedTerminal, externalTerminalstopOnEntryPause as soon as the program startspreLaunchTask / postDebugTaskRun a task (from tasks.json) before / after the sessioninternalConsoleOptionsWhen the Debug Console opens: neverOpen, openOnSessionStart, openOnFirstSessionStartpresentationOrder, group and hidden state in the dropdownserverReadyActionDo something (e.g. open a browser) when the app says its server is readywindows / 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 commandPython 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 uvicornconsoleintegratedTerminal (default), externalTerminal, internalConsolejustMyCodetrue (default): skip library code when stepping; set false to step into itstopOnEntryPause 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 featurespython / pythonArgsUse a specific interpreter / pass options to itDebug Behaviour (debug.*)
debug.openDebugWhen to open the Debug view: openOnDebugBreak (default), openOnSessionStart, openOnFirstSessionStart, neverOpendebug.saveBeforeStartSave before a session: allEditorsInActiveGroup (default), nonUntitledEditorsInActiveGroup, nonedebug.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, abortdebug.confirmOnExitAsk before closing VS Code during a session: never (default) or alwaysdebug.inlineValuesShow variable values beside the code: auto (default), on, offdebug.showVariableTypesShow types in the Variables view (default false)debug.toolBarLocationfloating (default), docked, commandCenter, hiddendebug.showInStatusBaronFirstSessionStart (default), always, neverdebug.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 automaticdebug.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 ondebug.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 Chromerequest: attachJoin a program that is already running in debug mode, using port or processIdA 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.