Nozzle Notes
Slicers & software

PrusaSlicer Start Gcode: What It Does and How to Edit It

What the Start G-code box in PrusaSlicer does, how the heating and homing commands work, which placeholders it accepts and how Klipper users hand off to a macro.

By Sepehr Sabbagh-pour · Published · 6 min read

Orange arrow lines flowing from the left into the nozzle of a generic desktop 3D printer above its bed on a workbench
AI-generated illustration

PrusaSlicer start G-code (start gcode) is the block of printer commands that runs before the first layer: heat the bed and nozzle, home the axes, then purge. It is a text box in the printer profile, and it can use placeholders so temperatures follow your filament preset.

What is start G-code in PrusaSlicer?

Start G-code is a custom G-code field that PrusaSlicer pastes at the top of every file it exports, before any layer is printed. It is part of the printer profile, so one printer keeps one start routine and every filament preset reuses it. Typical contents are heating, homing, an optional leveling step and a purge line.

Prusa's knowledge base describes PrusaSlicer's custom G-code fields as accepting a macro language, so the text is not sent to the printer verbatim. Anything in curly braces is evaluated when you slice. For the basics of the language itself, see what G-code is, and for how the file gets out of the slicer, see exporting G-code in PrusaSlicer.

For a hotend temperature test in PrusaSlicer, see the PrusaSlicer temp tower guide, which builds one with M104 custom G-code.

Where do you find and edit the start G-code?

Open the Printer settings tab and look for the Custom G-code page, which holds Start G-code and related boxes such as the end and layer-change fields. If you cannot see the page, switch the mode toggle to Expert. Our own guide to PrusaSlicer filament and printer profiles shows how the Expert mode adds pages to a tab.

Prusa's help page on tab features explains that a system preset shows a lock icon, that a changed value turns the label orange, and that the Save icon stores your edit as a user preset. In practice that means you save your edited start G-code under a new printer preset name rather than overwriting a built-in profile. This is described from Prusa's documentation; we have not run PrusaSlicer for this article.

What does a basic start G-code look like?

A basic Marlin-style routine heats first, homes, then waits for temperature. This is an illustration built from the command definitions in Marlin's documentation, not a profile for any specific printer:

M140 S{first_layer_bed_temperature[0]}
M104 S{first_layer_temperature[0]}
G28
M190 S{first_layer_bed_temperature[0]}
M109 S{first_layer_temperature[0]}

Each line does one job:

  • M140 sets the bed temperature and carries on without waiting.
  • M104 sets the hotend temperature and carries on without waiting.
  • G28 homes the axes so the firmware knows where the toolhead is.
  • M190 sets the bed target and waits until it is reached.
  • M109 sets the hotend target and waits until it is reached.

Starting both heaters first and waiting afterwards lets the bed and nozzle warm at the same time. Printer-specific steps such as a purge line, a probing routine or a firmware macro come after the waits, and the right commands differ per machine, so copy them from your maker's profile.

How do M190 and M109 differ from M140 and M104?

M140 and M104 set a target and return immediately, while M190 and M109 set a target and block until it is reached. Marlin's documentation says M190 "waits for the target temperature to be reached before proceeding", and that M140 sets the bed temperature and proceeds without waiting. M109 and M104 split the same way for the hotend.

The S parameter waits only while heating, and the R parameter waits whether heating or cooling, per Marlin's pages for both commands. Use S for a normal start, because the bed is usually below target. A start routine that never waits would begin extruding into a cold nozzle.

Which placeholders can you use in start G-code?

PlaceholderWhat it gives youSource
{first_layer_temperature[0]}First-layer nozzle temperature of the first extruderPrusa macros page
{first_layer_bed_temperature[0]}First-layer bed temperaturePrusa macros page
initial_extruder, initial_toolWhich extruder or tool is used firstPrusa placeholder list
first_layer_print_min, first_layer_print_maxBounding box of the first layerPrusa placeholder list
total_layer_countNumber of layers in the printPrusa placeholder list
num_objectsNumber of objects on the platePrusa placeholder list

Prusa's list also notes that every configuration option can be used in custom G-codes, so temperatures and other preset values are available by their option names. Curly braces mark the current macro syntax, and square brackets mark an older placeholder syntax whose contents are interpreted verbatim. Vector options such as temperature take an index, for example [0] for the first extruder. Prusa warns that its macro language is not compatible with the conditional expressions of Slic3r, so snippets copied from older Slic3r guides may fail.

Can start G-code change with the filament or extruder?

Yes, because the macro language supports conditions, which means one printer profile can serve several filaments. Prusa's macros page lists these building blocks:

  • Conditional blocks in if/elsif/else and if/else/endif form.
  • Operators: comparison, boolean logic, arithmetic, a ternary operator and regular expression matching with patterns between slashes.
  • Functions for minimum, maximum, integer casting, rounding, padding and a check for whether a configuration option is active.

Four rules cause most errors. Vector options such as temperature, first_layer_temperature and bed_temperature must be indexed, for example first_layer_temperature[0]. Multidimensional vectors such as extruder_offset and bed_shape can be printed as text but not used in arithmetic. A ternary expression has to sit inside parentheses. And layer_z and layer_num only exist in layer-change G-code, so they will not work in the start box. Prusa also says strings are not parsed recursively, so brackets inside a string show up literally in the output. Always slice and read the top of the exported file after editing.

Can the start G-code call a Klipper macro?

Yes. Klipper's slicer documentation recommends a single line for slic3r-derived slicers such as PrusaSlicer, which hands the temperatures to a macro:

START_PRINT EXTRUDER_TEMP=[first_layer_temperature] BED_TEMP=[first_layer_bed_temperature]

Klipper's command templates page explains that values passed to a macro arrive through the params pseudo-variable, that parameter names are upper case, and that values are strings, so math needs a conversion. The macro itself lives in your Klipper config, and it does the heating, homing and purging. If you are new to that firmware, read what Klipper is first.

Klipper's documentation also warns that these slicers insert their own heating codes when certain conditions are not met, and suggests putting M140 S0 and M104 S0 before the macro call to prevent that. Check the exported file to confirm what your version does.

Klipper's slicer page adds a quality warning that applies to what you leave out of the start box: it advises against coasting, extra restart distance (Simplify3D), PreloadVE (KISSlicer) and advanced extruder pressure settings, because they can cause poor prints with Klipper, which has pressure advance instead. It also notes that large retractions may need max_extrude_only_velocity and max_extrude_only_accel tuned in the Klipper config. Klipper's example for Cura passes {material_print_temperature_layer_0} in braces, while PrusaSlicer and SuperSlicer use square brackets, so do not paste one slicer's line into the other.

Can you heat the bed faster with start G-code?

Prusa's macros page includes an example titled faster heat-up with weak bed heaters. It uses the start G-code to heat the bed to a target 5 degrees C below the first-layer value, then starts warming the hotend while the bed finishes. The idea is to avoid the hotend sitting hot and idle. Treat it as a technique for printers with slow bed heaters, and check your maker's guidance before changing temperature behavior.

What should you check if the first layer goes wrong?

If the first layer is poor after you edit the start G-code, undo the change before touching anything else. Common start-routine causes are a missing home, a purge line in the wrong place or a probing step that no longer runs. On printers with probing, see automatic bed leveling explained, and for symptoms use how to fix a bad first layer. Re-slice and read the top of the exported file to confirm the placeholders turned into numbers.

To see how filament choice shifts print time, try the print cost calculator.

Sources and method

This is a research page. The facts come from the Prusa Knowledge Base, Marlin's G-code pages and the Klipper documentation listed below. We did not print with any of these routines, and the sample start G-code is an illustration, not a tested profile.

Frequently asked questions

What is start G-code in PrusaSlicer?

Start G-code in PrusaSlicer is a custom G-code box in the printer profile whose text is placed at the top of every exported file, before the first layer. It usually heats the bed and nozzle, homes the axes and may purge a line of filament. Prusa's documentation says custom G-codes accept a macro language, so placeholders in curly braces are replaced with real values when you slice. Because it belongs to the printer profile, the same routine applies to every filament preset used on that printer.

What is the difference between M190 and M140?

Both set the bed temperature, but M190 waits and M140 does not. Marlin's documentation says M140 sets the bed temperature and proceeds without waiting, while M190 waits for the target temperature to be reached before proceeding. The S parameter waits only while heating, and R waits whether heating or cooling. A common start routine sends M140 early so the bed heats in the background, then M190 before printing so the first layer does not begin on a cold bed.

How do I use the first-layer temperature in start G-code?

Use a placeholder instead of a fixed number. Prusa's macros page lists first_layer_temperature and first_layer_bed_temperature as vector variables, which you read with an index, so {first_layer_temperature[0]} gives the first extruder's value. Put it in a command such as M109 S{first_layer_temperature[0]}. The number then follows whichever filament preset is selected when you slice. Check the exported G-code afterward to see the placeholder replaced with an actual temperature.

Can PrusaSlicer start G-code call a Klipper macro?

Yes. Klipper's slicer documentation recommends a single line for slic3r-derived slicers: START_PRINT EXTRUDER_TEMP=[first_layer_temperature] BED_TEMP=[first_layer_bed_temperature]. The macro defined in your Klipper config then reads those values through the params pseudo-variable, which holds upper-case names and string values, and performs the heating, homing and purging. Klipper also warns that these slicers insert their own heating codes in some conditions and suggests adding M140 S0 and M104 S0 before the call.

Why does PrusaSlicer add heating commands I did not write?

Klipper's documentation warns that slic3r-derived slicers insert their own heating codes when certain conditions are not met, and suggests adding M140 S0 and M104 S0 before a macro call to prevent it. Prusa's pages we read do not describe the exact rule, so do not assume it. Slice a small test file and read the top of the exported G-code to see which temperature commands appear and in what order, then adjust your start G-code to match your firmware.

Sources

Sepehr Sabbagh-pour

Founder and editor

Sepehr Sabbagh-pour

Software engineer since 2009 and Head of Engineering by day, a maker who has owned several 3D printers, writing practical guides to 3D printers, filament and running costs, with every article saying what was and was not tested.

Drafted with AI assistance, then edited and reviewed by Sepehr before it goes live. How we use AI.