Klipper is printer firmware whose command reading runs on a host computer. It accepts
a small set of standard G and M codes, so that files from common slicers work, and for
everything else prefers “extended” commands written as words, such as
SET_PRESSURE_ADVANCE. This page covers how Klipper reads a line, the
standard codes, and the extended commands of the modules from adxl345 to
generic_cartesian, as its documentation and parser source give them. The modules
from H onwards are on Klipper commands,
H to Z.
How a line is read
- Leading and trailing spaces are removed, and everything from the first
;on is ignored. - The line is turned into upper case and split before each letter. The first
letter with the text after it is the command (
G1); every later letter with its following text is a parameter. A run of letters and underscores counts as one name, which is how word commands are recognised. - A line number,
Nn, at the start is skipped. A trailing*checksum is split off as if it were one more parameter; the parser does not check it.M110(set line number) is accepted and does nothing. - A traditional command is a letter followed by a number. Every other
command is an extended command, and its parameters are read again as
KEY=VALUEwords. - Extended parameters follow shell-style quoting, so a value holding spaces is put
in quotes (
MSG="Heating up"). Here both#and;start a comment. Command names and keys are not case sensitive; values keep their case. - For
M117,M118andM23the rest of the line is text, even when it holds digits or other characters. - Replies begin
ok, information lines begin//and errors begin!!. An unknown command is reported (Unknown command:), except when it only switches off a heater or fan that the printer does not have.
G1 X20 Y20 E1.5 F1800
SET_PRESSURE_ADVANCE ADVANCE=0.045 SMOOTH_TIME=0.04
EXCLUDE_OBJECT_START NAME=part_0
SET_DISPLAY_TEXT MSG="Layer 2"
Names of macros defined in the printer’s configuration
(gcode_macro) become further commands, so a file made for one printer
may use words that no list contains.
Standard G and M codes
| Command and parameters | Effect and conditions |
|---|---|
G0 or G1 [X] [Y] [Z] [E] [F] | Move; F is the speed |
G2, G3 [X] [Y] [Z] [E] [F] with two of I J K | Clockwise or anticlockwise arc, using I J, I K or J K by plane. Needs gcode_arcs |
G4 Pms | Dwell for the given milliseconds |
G10, G11 | Retract and unretract with the configured settings. Needs firmware_retraction |
G17, G18, G19 | Arc plane XY, XZ or YZ. Needs gcode_arcs |
G28 [X] [Y] [Z] | Home |
G90, G91 | Absolute or relative coordinates |
G92 [X] [Y] [Z] [E] | Set the position |
M18 or M84 | Turn the motors off |
M20, M21 | List and initialise the SD card. Needs virtual_sdcard |
M23 filename | Select an SD file |
M24, M25 | Start or resume, and pause, the SD print |
M26 Soffset | Set the SD read position |
M27 | Report SD print status |
M73 Ppercent | Set the build percentage. Needs a display configuration (display_status) |
M82, M83 | M83 forces relative extrusion even while G90 is in force; M82 removes the forcing and does not itself force absolute extrusion |
M104 [Tindex] [Stemp] | Set the extruder temperature |
M105 | Report temperatures |
M106 Svalue, M107 | Set the fan speed; fan off |
M109 [Tindex] Stemp | Set the extruder temperature and always wait for it to settle |
M110 | Accepted, no effect |
M112 | Emergency stop; Klipper shuts down |
M114 | Report the position |
M115 | Reply with FIRMWARE_NAME:Klipper FIRMWARE_VERSION:version |
M117 message | Show a message. Needs a display configuration |
M118 message | Echo the message with the configured prefix, or echo: . Needs respond |
M119 | Report endstops; QUERY_ENDSTOPS is preferred |
M140 [Stemp] | Set the bed temperature |
M190 Stemp | Set the bed temperature and wait for it to settle |
M204 Sa or M204 Pa Tb | Set acceleration. Without S, the smaller of P and T is used; P or T alone does nothing |
M220 Spercent, M221 Spercent | Speed factor and extrude factor override |
M400 | Wait for current moves to finish |
O1–O32 | Omega codes embedded in files for the Palette 2 filament splicer, passed to the device. Needs palette2 |
Codes outside this list, for example G12, G29,
G30, G31, M42, M80,
M81 or T1, can be provided by a
gcode_macro in the configuration.
Accelerometers, angle sensors and calibration (adxl345 to bltouch)
Each group of extended commands exists only when the configuration section named in the heading or note is present. Brackets mark optional parameters.
| Command and parameters | Effect |
|---|---|
ACCELEROMETER_MEASURE [CHIP=] [NAME=] | adxl345. The first call starts measuring, the next stops and writes /tmp/adxl345-chip-name.csv. CHIP defaults to adxl345, NAME to the time as YYYYMMDD_HHMMSS |
ACCELEROMETER_QUERY [CHIP=] [RATE=] | Read the current acceleration |
ACCELEROMETER_DEBUG_READ [CHIP=] REG= | Read a chip register (decimal or hexadecimal) |
ACCELEROMETER_DEBUG_WRITE [CHIP=] REG= VAL= | Write a raw value to a register |
ANGLE_CALIBRATE CHIP= | angle. Calibrate the sensor, moving its stepper about two turns each way without limit checks; save with SAVE_CONFIG |
ANGLE_CHIP_CALIBRATE CHIP= | The sensor’s own internal calibration (MT6826S and MT6835) |
ANGLE_DEBUG_READ CHIP= REG= | Read a sensor register (TLE5012B only) |
ANGLE_DEBUG_WRITE CHIP= REG= VAL= | Write a sensor register (TLE5012B only) |
AXIS_TWIST_COMPENSATION_CALIBRATE [AXIS=X|Y] [SAMPLE_COUNT=] [MANUAL_METHOD=manual] | Calibrate axis twist compensation; AXIS defaults to X |
BED_MESH_CALIBRATE [PROFILE=] [METHOD=manual] [HORIZONTAL_MOVE_Z=] [probe parameters] [mesh parameters] [ADAPTIVE=1] [ADAPTIVE_MARGIN=] | Probe the bed, build a height mesh and use it at once, saved as PROFILE or default. ADAPTIVE=1 probes only the area of the objects the file defines, in a profile named adaptive-… |
BED_MESH_OUTPUT PGP=0|1 | Print probed and mesh values; PGP=1 adds the generated points |
BED_MESH_MAP | Print the mesh as JSON |
BED_MESH_CLEAR | Remove the mesh adjustment |
BED_MESH_PROFILE LOAD= | SAVE= | REMOVE= | Load, save or delete a named mesh; saving or removing needs SAVE_CONFIG to persist |
BED_MESH_OFFSET [X=] [Y=] [ZFADE=] | Offsets for the mesh lookup, for independent extruders |
BED_SCREWS_ADJUST | bed_screws. Interactive screw levelling |
BED_TILT_CALIBRATE [METHOD=manual] [HORIZONTAL_MOVE_Z=] [probe parameters] | bed_tilt. Probe and recommend tilt values |
BLTOUCH_DEBUG COMMAND= | bltouch. pin_down, touch_mode, pin_up, self_test, reset; V3.0 and V3.1 also set_5V_output_mode, set_OD_output_mode, output_mode_store |
BLTOUCH_STORE MODE=5V|OD | Store the output mode in a BLTouch V3.1 |
Configuration, display and objects (configfile to exclude_object)
| Command and parameters | Effect |
|---|---|
SAVE_CONFIG | Write calibration results into the configuration file and restart |
UPDATE_DELAYED_GCODE [ID=] [DURATION=seconds] | delayed_gcode. Set a delay and start its timer; 0 cancels |
DELTA_CALIBRATE [METHOD=manual] [HORIZONTAL_MOVE_Z=] [probe parameters] | Probe seven points on a delta printer and recommend endstops, angles and radius |
DELTA_ANALYZE | Used during enhanced delta calibration |
SET_DISPLAY_GROUP [DISPLAY=] GROUP= | Choose the LCD’s data group; DISPLAY defaults to display |
SET_DISPLAY_TEXT [MSG=] | As M117; without MSG the message is cleared |
SET_DUAL_CARRIAGE CARRIAGE= [MODE=PRIMARY|COPY|MIRROR|INACTIVE] | dual_carriage. CARRIAGE is a defined carriage name (generic Cartesian) or 0 or 1. MODE defaults to PRIMARY; COPY and MIRROR need another carriage of the axis to be primary first |
SAVE_DUAL_CARRIAGE_STATE [NAME=] | Save carriage positions and modes (default name default) |
RESTORE_DUAL_CARRIAGE_STATE [NAME=] [MOVE=0|1] [MOVE_SPEED=] | Restore them, moving back unless MOVE=0 |
ENDSTOP_PHASE_CALIBRATE [STEPPER=] | Without STEPPER report endstop phase statistics; with it, prepare the setting for SAVE_CONFIG |
EXCLUDE_OBJECT [NAME=] [CURRENT=1] [RESET=1] | Without parameters list the excluded objects; exclude the named or current object; RESET clears the list, or only NAME |
EXCLUDE_OBJECT_DEFINE [NAME= [CENTER=X,Y] [POLYGON=[[x,y],…]]] [RESET=1] [JSON=1] | Declare an object of the file, with its centre and outline. Without parameters list the objects (JSON=1 for details); RESET clears them |
EXCLUDE_OBJECT_START NAME= | The following moves belong to this object on this layer |
EXCLUDE_OBJECT_END [NAME=] | End of the object’s moves; a wrong name only warns |
Extruders, fans, filament and movement (extruder to generic_cartesian)
| Command and parameters | Effect |
|---|---|
ACTIVATE_EXTRUDER EXTRUDER= | Change the active hot end |
SET_PRESSURE_ADVANCE [EXTRUDER=] [ADVANCE=] [SMOOTH_TIME=] | Set pressure advance; EXTRUDER defaults to the active one |
SET_EXTRUDER_ROTATION_DISTANCE EXTRUDER= [DISTANCE=] | Set the extruder’s rotation distance until restart (negative reverses); without DISTANCE report it |
SYNC_EXTRUDER_MOTION EXTRUDER= MOTION_QUEUE= | Make one extruder stepper follow another extruder; an empty MOTION_QUEUE unlinks it |
SET_FAN_SPEED FAN= SPEED= | fan_generic. Speed from 0.0 to 1.0 |
SET_FAN_SPEED FAN= TEMPLATE= [param=literal] | Drive the fan from a display template; an empty TEMPLATE removes it |
QUERY_FILAMENT_SENSOR SENSOR= | Report a filament switch or motion sensor |
SET_FILAMENT_SENSOR SENSOR= ENABLE=0|1 | Turn the sensor off or on |
SET_RETRACTION [RETRACT_LENGTH=] [RETRACT_SPEED=] [UNRETRACT_EXTRA_LENGTH=] [UNRETRACT_SPEED=] | Settings used by G10 and G11 (mm and mm/s); slicers often write it per filament |
GET_RETRACTION | Show those settings |
STEPPER_BUZZ STEPPER= | Move a stepper 1 mm and back, ten times |
FORCE_MOVE STEPPER= DISTANCE= VELOCITY= [ACCEL=] | Move one stepper (mm, mm/s, mm/s²) with no limit checks; needs enable_force_move |
SET_KINEMATIC_POSITION [X=] [Y=] [Z=] [SET_HOMED=axes] [CLEAR_HOMED=axes] | Declare the toolhead position without moving. SET_HOMED defaults to XYZ, even when CLEAR_HOMED is given; CLEAR_HOMED wins for an axis in both; CLEAR is an alias of it that is to be removed. Needs enable_force_move where the configuration requires it |
RESTART | Reload the configuration and reset the host software |
FIRMWARE_RESTART | As RESTART, also clearing the microcontroller’s error state |
STATUS | Report the host software state |
HELP | List the extended commands available |
ECHO … | Repeat the line back as information (in the parser source) |
SET_GCODE_VARIABLE MACRO= VARIABLE= VALUE= | Change a macro variable; the value is read as a Python literal |
GET_POSITION | Report the toolhead position in each coordinate system |
SET_GCODE_OFFSET [X=|X_ADJUST=] [Y=|Y_ADJUST=] [Z=|Z_ADJUST=] [MOVE=1 [MOVE_SPEED=]] | Offset applied to later moves; the _ADJUST forms add to the present offset; MOVE=1 moves at once |
SAVE_GCODE_STATE [NAME=] | Save G90/G91, M82/M83, G92 origin, offset, M220, M221, speed, XYZ position and relative E |
RESTORE_GCODE_STATE [NAME=] [MOVE=1 [MOVE_SPEED=]] | Restore it; MOVE=1 also returns to the saved position |
SET_STEPPER_CARRIAGES STEPPER= CARRIAGES= [DISABLE_CHECKS=0|1] | generic_cartesian kinematics only. Change which carriages a stepper drives, and their signs, not which exist |
Sources
- G-Codes – Klipper’s list of supported commands, read from
docs/G-Codes.mdin the source tree on 3 December 2026 - klippy/gcode.py – Klipper’s command parser (Python)