Start G-code and end G-code: heat, probe, purge and park in the right order

By Sina Esfahani, OmniTechs · Published 27 November 2026

Start G-code is the block your slicer puts before the first layer; end G-code is the block after the last. A good start code sets the coordinate modes, starts the heaters, homes, waits for the bed, probes with the nozzle below oozing temperature, then heats fully, purges and resets the extruder. A good end code lifts the nozzle, moves it clear, switches the heaters and fan off and releases the motors.

Two rules prevent most problems. Take temperatures from slicer placeholders, never typed numbers, so the code follows your filament. And give your slicer heating lines it recognises: if it finds none, it adds its own before your code and breaks your order.

Build your start and end code in this order:

  1. Start from your printer's own profile and copy it to a text editor first.

  2. Set the modes: G90, then M83 or M82.

  3. Start the bed with a placeholder: M140 S[first_layer_bed_temperature] in PrusaSlicer, M140 S{material_bed_temperature_layer_0} in Cura.

  4. Home with G28, then wait for the bed with M190 before you probe.

  5. Probe with a cooler nozzle: Prusa uses 170 °C for PLA, Bambu Lab 140 °C.

  6. Heat to the first-layer temperature, purge, wipe, then G92 E0.

  7. At the end: lift Z first, park, then M104 S0, M140 S0, M107 and M84 X Y E.

What you see, and what it means

Start and end G-code problems

From the slicer and firmware sources listed below, read 27 November 2026.
What you seeWhat it meansWhat to do
The printer heats, then waits a second timeThe slicer added its own heating because it did not recognise yoursUse the commands or placeholders your slicer checks for (table below)
The temperature is wrong for a new filamentA fixed number in the start codeReplace every number with a placeholder
The nozzle oozes onto the bed while probingProbing at full printing temperatureProbe at a lower temperature, heat afterwards
The first layer is uneven after you edited the startProbing before the bed reached temperaturePut M190 before the probing command
A strand is dragged into the first layerThe purge ended without a wipe or lift, or the line peeled offWipe and lift after the purge, or print a skirt
The nozzle scrapes the print at the endA sideways move before the lift, or homing ZLift first; never home Z at the end
Klipper ignores your saved meshIt no longer loads one at start-upAdd BED_MESH_PROFILE LOAD=default to START_PRINT

Where to edit it, and which placeholders each slicer reads

A placeholder is a slicer variable that becomes a value when you slice. Each slicer has its own names and brackets, so code copied between slicers needs converting.

Where start G-code lives and what stops the slicer adding its own heating

From PrusaSlicer 2.9.7, OrcaSlicer 2.5.2 and Bambu Studio 02.09.02.62 source code and profiles, Cura 5.14.0 source and release notes, read 27 November 2026.
SlicerWhere to editFirst-layer nozzleFirst-layer bedIt adds its own heating unless
PrusaSlicer 2.9Printer Settings > Custom G-code (expert mode)[first_layer_temperature][first_layer_bed_temperature]Your code contains M104, M109, M140, M190, M141 or M191
OrcaSlicer 2.5Printer settings > Machine G-code{first_layer_temperature[initial_extruder]}{bed_temperature_initial_layer_single}Bed: your code has M140 or M190. Nozzle: it has M104 or M109. With the Klipper flavour it adds none
Bambu Studio 2.9Printer settings > Machine gcode{nozzle_temperature_initial_layer[initial_extruder]}[bed_temperature_initial_layer_single]Same rule as OrcaSlicer
UltiMaker Cura 5.14Preferences > Configure Cura > Printers > Machine Settings{material_print_temperature_layer_0}{material_bed_temperature_layer_0}It finds one of its temperature placeholders; a typed M190 S60 does not count

Without temperature commands in your code, PrusaSlicer heats the bed and waits, starts the nozzle, runs your code, then waits for the nozzle; Emit temperature commands automatically, under the start G-code field, switches that off. PrusaSlicer's macros also do arithmetic and conditions, which Prusa's profile uses to pick the probing temperature per filament. Cura has accepted formulas since 5.6 and if/else conditions since 5.9, so older advice that it cannot calculate in start code is out of date.

Teaching Tech's video on slicer variables has a chapter on start G-code temperatures, and the link starts there. Its chapter on Cura's limits predates Cura 5.6.

Get more from your slicer using variables and conditional gcode (Teaching Tech)

Heating order: why the bed comes first and the nozzle stays cooler

Heaters take longest, so start them early. M140 and M104 set a target and move on; M190 and M109 wait. Klipper's sample macro starts the bed with M140 before G28, so the bed warms while the printer homes.

Wait for the bed before you probe. A bed that is still heating changes shape, which is why Prusa's MK4S and Bambu Lab's P1S profiles both wait with M190 before they measure. Some start codes shared on the Bambu Lab forum skip this wait to save time; the bed then keeps changing after it has been measured. For stubborn first layers, Bambu Lab's H2D guide suggests holding the bed at temperature for 10 to 15 minutes.

Keep the nozzle cooler while probing, so it does not ooze onto the bed or the probe. Prusa's MK4S code holds the nozzle at 170 °C for PLA and 175 °C for PETG while it homes and probes, and 25 °C below the first-layer temperature for PC and nylon. Bambu Lab's P1S code cools it to 140 °C before levelling. Both heat up to printing temperature again only after probing, just before the purge line.

Four published start sequences compared

From Klipper's sample-macros.cfg, the PrusaSlicer profile bundle 2.5.16, Bambu Studio 02.09.02.62's P1S profile (dated 31 October 2025) and Cura 5.14.0's creality_base definition, read 27 November 2026.
StepKlipper sample START_PRINTPrusa MK4S (PrusaSlicer)Bambu Lab P1S (Bambu Studio)Cura profile for Creality
ModesG90G90, then M83G90; M83 before the purgeNone; Cura sets absolute mode
BedM140 first, M190 after homingM140 first, M190 before probingM140 and M190 first of allAdded by Cura
Nozzle while probingNo probing in the sample170 °C for PLA, 175 °C for PETG140 °CNo probing
Bed measuringNoneOnly the area the print usesOnly the area the print usesNone
PurgeNoneLine along the front at Y -4, then a wipeFlushes 105 mm at the back, then a line along the front edgeTwo lines along the left edge

Where to measure and when to re-run a mesh is covered in the bed levelling guide.

Worked example: Cura's Creality start code with heating you control

Cura's Creality profile has no heating lines, so Cura adds its own before it. To set the order yourself, add the four heating lines at the top. Because they use Cura's own placeholders, Cura drops its automatic heating.

A Creality start code with your own heating order

The purge lines are Cura 5.14.0's creality_base start code; the first four lines are an example built on Cura's placeholder rule, not a maker's profile.
LineWhat it does
M140 S{material_bed_temperature_layer_0}Starts the bed and carries on
G28Homes while the bed warms
M190 S{material_bed_temperature_layer_0}Waits for the bed
M109 S{material_print_temperature_layer_0}Heats the nozzle and waits
G92 E0Sets the extruder to zero
G1 Z2.0 F3000Lifts 2 mm
G1 X10.1 Y20 Z0.28 F5000.0Moves to the start of the purge
G1 X10.1 Y200.0 Z0.28 F1500.0 E15Draws a 180 mm line at 25 mm/s, feeding 15 mm of filament
G1 X10.4 Y200.0 Z0.28 F5000.0Steps 0.3 mm aside
G1 X10.4 Y20 Z0.28 F1500.0 E30Draws the line back; E30 means another 15 mm in absolute mode
G92 E0Sets the extruder to zero again
G1 Z2.0 F3000Lifts before the first travel

If your printer has a probe, add your probing command after M190 and heat the nozzle afterwards, as in the profiles above. Test any edit with a small print while you watch the start.

The purge line, and why it ends up in your print

A purge line pushes out old filament and fills the nozzle before the first layer. The classic complaint is the strand the first travel drags onto the bed. The accepted answer on the 3D Printing Stack Exchange offers a skirt or brim, which primes without any G-code, or a priming line in the start code. Another answer adds two rules: swipe in one direction only, so you do not pick the purged plastic up again, and do not over-extrude, so no pressure is left in the nozzle.

Prusa ends its purge with a wipe: the nozzle dips to 0.05 mm and moves away fast. A P1S owner on the Bambu Lab forum stopped the return pass of the front prime line short, so the first pass keeps its grip; that is a user change, not Bambu advice.

Teaching Tech shows how slicer variables can place the purge next to the object instead of at a fixed edge, which keeps it short and close to where printing starts.

Adaptive purge for every 3D printer: A simple slicer tweak (Teaching Tech)

If the purge line does not stick, fix the first layer, not the G-code: see the first layer guide. For flush volumes in multicolour printing, see the purge waste guide.

Klipper: put the sequence in START_PRINT and END_PRINT

On Klipper, keep the real sequence in macros in the printer configuration, and pass only the temperatures from the slicer. Klipper's own examples are START_PRINT BED_TEMP={material_bed_temperature_layer_0} EXTRUDER_TEMP={material_print_temperature_layer_0} in Cura and START_PRINT EXTRUDER_TEMP=[first_layer_temperature] BED_TEMP=[first_layer_bed_temperature] in PrusaSlicer. Changing the macro then needs no re-slicing.

Klipper advises PrusaSlicer users to put M140 S0 and M104 S0 before the macro call, so the slicer adds no heating of its own; in OrcaSlicer and Bambu Studio, the Klipper G-code flavour does the same. Since 1 February 2023, Klipper no longer loads a saved bed mesh at start-up, so add BED_MESH_PROFILE LOAD=default to START_PRINT if you use one.

End G-code: lift, park and cool down

All four switch the heaters off and get the nozzle clear of the print. They differ in how far they lift, where they park and what stays powered.

Four published end sequences compared

From Klipper's sample-macros.cfg, the PrusaSlicer profile bundle 2.5.16, Bambu Studio 02.09.02.62's P1S end code and Cura 5.14.0's creality_base definition, read 27 November 2026. Prusa caps both lifts at the printer's maximum height.
StepKlipper sample END_PRINTPrusa MK4SBambu Lab P1SCura profile for Creality
Retract3 mm while moving 2 mm asideNone in the end code0.8 mm2 mm, then 2 mm more
First lift10 mmTo 1 mm above the top layerTo 0.5 mm above the top layer0.2 mm, then 10 mm
ParkNo parkX 241, Y 170Back of the printerBed to the front with G1 X0 Y{machine_depth}
Heaters and fan offFirst, before movingAfter the first liftBed and fans after the park, hotend lastAfter the park
Final liftNoneTo 23 mm above the top layer100 mm, up to Z 250None
MotorsM84M84 X Y E, Z stays onLowered currentM84 X Y E, Z stays on

Do not put a plain G28 in end code. On many printers it homes Z too and drives the nozzle into the print. Move away with G1 instead, as Cura's Creality code does.

Let the hotend cool before you cut the power. On Marlin, the hotend fan runs from the measured temperature, not the target, and keeps the heat sink cool until the hotend is below 50 °C. Cutting the power at once stops that fan; the heat creep guide explains what follows when the cold side gets warm.

When to stop

Switch the printer off at once if a move pushes the nozzle into the bed or an axis runs against its end; a wrong Z value in a purge move is the usual cause, and the nozzle height itself belongs to the z-offset guide. Forum code is written for one printer and one profile version, so compare the date line at the top of your own start code before you use someone else's.

What each command does, and where Marlin, Klipper and Prusa firmware differ, is in the G-code commands guide. If you are moving your sequence into Klipper macros, the Klipper guide explains what else changes on the printer.