3D Printing (General)

How to clean up a bloated Klipper SAVE_CONFIG section without breaking anything

Open any well-used printer.cfg and the SAVE_CONFIG region at the bottom is probably a mess: multiple input_shapers, duplicate bed_mesh defaults, several auto_addr entries. Klipper handles it, but the file becomes unreadable. A safe step-by-step cleanup that took my K2 from 707 to 568 lines with zero behaviour change.

By Grant Harkness · published 2026-05-09

Open your printer.cfg, scroll to the bottom, look for the line that says # SAVE_CONFIG. If you've owned the printer for more than a few months and run SHAPER_CALIBRATE, BED_MESH_CALIBRATE, or Z_TILT_ADJUST at any kind of frequency, what you'll see is probably duplicated sections — multiple [input_shaper] blocks, multiple [bed_mesh default] entries, possibly several [heater_bed] PID sections from different PID_CALIBRATE runs, sometimes [auto_addr] or other manufacturer-specific blocks repeated.

Klipper itself handles this fine — the last occurrence of any given section wins at parse time, so your printer is using the most recent values. But the file is several hundred lines longer than it needs to be, the duplication makes diffing your config painful, and if you ever try to manually edit a value inside SAVE_CONFIG (don't, but people do) you'll edit the wrong copy.

This is how to clean it up safely.

What SAVE_CONFIG actually does

At the bottom of your printer.cfg, Klipper maintains a region delimited by a marker line that starts ## <---- and continues with SAVE_CONFIG and a "DO NOT EDIT" warning. Anything below that marker is owned by Klipper. The next time SAVE_CONFIG runs, Klipper should* update the existing sections in place. In practice, on some forks (Creality's K2 firmware is one), SAVE_CONFIG appends rather than updates when sections are recognised under slightly different names, and you end up with stacked duplicates over time.

Real example

On my K2, after about six months of weekly calibrations, the SAVE_CONFIG region had 11 # SAVE_CONFIG marker lines, 5 separate [input_shaper] blocks, 6 [auto_addr] blocks, and 3 [bed_mesh default] blocks. The file was 707 lines.

After cleanup it was 568 lines — a 20 percent reduction with zero functional change because Klipper was already using the latest version of each section.

The safe cleanup procedure

A step-by-step you can follow.

Step 1: stop the printer doing anything

Don't do this mid-print. Don't do this with a print queued. Wait until the printer is idle, then either pause Moonraker's print queue or just don't queue anything. The risk during cleanup is that Klipper restarts — which it will when you save the file — and that's only acceptable if nothing's relying on Klipper at the moment.

Step 2: back up the file

Always — cp printer_data/config/printer.cfg printer_data/config/printer.cfg.bak-$(date +%s). The $(date +%s) Unix-timestamp suffix means every run leaves a unique backup; you can always go back to any prior state, not just the most recent. (The same backup discipline applies to other K2 config files — see What actually needs backing up on a Creality K2.)

Step 3: identify the SAVE_CONFIG block boundaries

Open the file. Find the first #*# <---- SAVE_CONFIG ----> marker. Everything from that line to the end of the file is what you're about to rewrite. Above that line is your hand-written config and you don't touch it.

Step 4: collapse to "latest wins"

For each duplicated section type, keep only the last copy — the one closest to the bottom of the file. Klipper has been using the last copy all along, so you're not changing behaviour, just removing the older copies that were inert.

For my K2, the latest-wins order was: [auto_addr], then [heater_bed], then [box], then [input_shaper], then [bed_mesh default]. Order doesn't strictly matter to Klipper, but a stable order is readable.

Step 5: collapse the markers

Replace the multiple # SAVE_CONFIG marker lines with one. Put it immediately above the surviving block of sections, exactly as Klipper writes it on a fresh save — the #*# <---- line followed by the "DO NOT EDIT" warning, then the sections.

Step 6: validate before restart

Klipper has no offline syntax validator built in, but you can do a sanity check. The Python one-liner python3 -c "import configparser; configparser.RawConfigParser(strict=False).read('printer.cfg')" will catch a corrupt file. The strict=False matters — Klipper's config syntax allows duplicate sections that strict mode would reject; we're checking the file is at least parseable, not strictly conforming.

Step 7: save and restart Klipper

On the K2: /etc/init.d/klipper restart. On most other systems: sudo systemctl restart klipper.

Watch the logs (/tmp/klippy.log or ~/printer_data/logs/klippy.log). If Klipper comes up clean and your dashboard shows the same shaper, mesh, and PID values you had before, you're done. If it errors, restore from the backup and restart.

Don't do these things

  • Don't delete the SAVE_CONFIG region wholesale and re-run calibrations. You'll lose your meshes and PIDs and have to redo a multi-hour tuning session for cosmetic file cleanliness. The duplicates are inert, not actively harmful.
  • Don't rearrange section order across the boundary. Hand-written config above the marker, auto-generated below. Klipper relies on the convention.
  • Don't edit values inside SAVE_CONFIG by hand. If you want to override a calibrated value, do it from the gcode console and let SAVE_CONFIG re-run; that way the file stays self-consistent.

When this matters and when it doesn't

If you're on a vanilla Klipper install with a small printer you tune occasionally, you'll probably never see this. SAVE_CONFIG updates in place and the duplicates never accumulate.

If you're on a manufacturer fork (Creality, Anycubic, Sovol, FLSUN), or you regularly add new accelerometers, or you've been moving sections between printer.cfg and includes, the duplicates will accumulate. Cleaning them up once a year keeps the file readable and your future-self grateful.

Why I'm building tooling for this

Manual cleanup works but it's tedious and easy to miss a duplicate. I'm building a Klipper Config Doctor tool — drag in printer.cfg, get warnings about deprecated syntax, dangerous values like min_temp 0, common Discord copy-paste mistakes, and exactly this kind of duplicate-section bloat with the latest one highlighted. Pairs naturally with the K2 Backup tool. Coming to the Hark Tech tools page soon.

If you're sitting on a printer.cfg that's grown unwieldy and you'd rather pay someone to clean it up than do it yourself, send the file in — same workflow as the printer-repair postal service, just for config files.