Custom G-code lets you insert printer commands that Bambu Studio doesn't offer in its menus
G-code is the language your 3D printer reads. Bambu Studio generates most of it automatically when you slice a model, but sometimes you need to tell the printer to do something the software doesn't have a button for — pause at a specific layer, change nozzle temperature mid-print, or run a custom cleaning routine. Custom G-code is how you insert those commands directly into the print file.
Bambu Studio gives you three places to add custom G-code: before the print starts, between layers at a specific height, and after the print finishes. Each one runs at a different moment, so you choose based on when you need the printer to act.
Key Takeaways
- Custom G-code goes into Bambu Studio through the Printer Settings tab, under Machine G-code or Layer Change G-code, depending on when you want it to run.
- Start G-code runs before printing begins and is useful for bed leveling checks or nozzle priming that your default settings don't include.
- Layer Change G-code pauses or changes settings at a specific height, which is how you insert a different filament color or material mid-print.
- End G-code runs after the print finishes and typically parks the nozzle and cools the bed, but you can add extra commands like a beep or light signal.
- Test custom G-code on a short print first, because a syntax error will either fail silently or cause the printer to ignore the rest of the file.
Where to find the custom G-code fields in Bambu Studio
Open Bambu Studio and load your model. Click the Printer Settings tab on the right side of the screen — it's the icon that looks like a wrench. Scroll down until you see Machine G-code or Layer Change G-code depending on what you need to add.
Machine G-code has three subsections: Start G-code, End G-code, and Before Layer Change G-code. Each one is a text box where you paste or type commands. The software will insert whatever you write at the moment that section runs during the print.
If you want G-code to run at a specific layer rather than at the start or end, you'll use the Layer Change field instead. This is separate from the Machine G-code section and requires you to specify the exact layer number where the command should trigger.
Start G-code: commands that run before printing begins
Start G-code executes the moment you press print, before the nozzle moves to the bed. This is where you put commands that prepare the printer for a successful first layer. Common examples include a nozzle prime line (a test line the printer draws on the edge of the bed to make sure filament is flowing) or a bed leveling check that your default profile doesn't include.
If your printer's default start routine doesn't include a prime line and you find yourself getting poor adhesion on the first layer, adding a straightforward prime line command can fix it. The exact G-code varies by printer model, so check your printer's manual or the Bambu community forums for the correct syntax for your machine.
Start G-code also runs after the bed and nozzle reach their target temperatures, so you don't need to add heating commands — those happen automatically based on your material settings.
Layer Change G-code: pausing or changing settings mid-print
Layer Change G-code pauses the print or changes a setting at a specific layer height. This is the most common reason people use custom G-code in Bambu Studio. The most practical use is inserting a different filament color: you tell the printer to pause at layer 50, swap the filament spool, and resume.
To add a pause at a specific layer, go to the model preview, right-click on the layer number in the timeline on the left, and select Add Pause. Bambu Studio will insert a pause command automatically. If you need to add a custom command instead of just pausing — like changing the nozzle temperature or adjusting print speed — you can type it into the Layer Change G-code field and specify the layer number.
Layer changes are useful for embedding inserts (pausing to glue a metal nut into the print), changing colors, or switching materials if your printer has a multi-material setup. The printer will beep and wait for you to press resume on the touchscreen before continuing.
End G-code: commands that run after the print finishes
End G-code executes after the last layer prints. By default, it parks the nozzle away from the print, cools the bed, and turns off the hotend. You can add extra commands here if you want the printer to do something after it finishes — like turn on a light, play a sound, or move the bed all the way forward so the print is straightforward to remove.
Some users add a G4 P5000 command (which pauses for 5 seconds) before the nozzle parks, giving the plastic time to cool slightly so it doesn't stick to the nozzle as it moves away. Others add a custom beep sequence or a command to retract the filament further than the default, preventing oozing on the next print.
End G-code is also where you'd add commands if you have a multi-material printer and want to unload the current filament automatically after the print finishes.
How to write and test custom G-code safely
G-code syntax is strict — a typo will either cause the printer to ignore the command silently or stop responding entirely. Start by copying working G-code from your printer's manual or from the Bambu community forums rather than writing from scratch. Modify only the parts you understand.
Before running custom G-code on a real print, test it on a short model — something that takes 10 to 15 minutes. If the command fails, you'll know quickly and can fix it without wasting material. Watch the printer during the test to make sure it behaves the way you expected.
Common G-code commands you might add include G4 P[milliseconds] (pause for a set time), M104 S[temperature] (set nozzle temperature), and M109 S[temperature] (set nozzle temperature and wait). Each command does one thing, so if you need multiple actions, put each on its own line.
If the printer stops responding or the print fails, remove the custom G-code, reload the file, and try again. Bambu Studio will revert to the default commands if the custom ones are empty.
Common mistakes and how to avoid them
The most common mistake is forgetting that G-code is case-sensitive and requires exact spacing. G4 P5000 works, but g4 p5000 or G4P5000 (no space) may not. Copy commands exactly as they appear in your reference material.
Another mistake is adding commands that conflict with Bambu Studio's automatic settings. For example, if you add a nozzle temperature command in Start G-code but your material profile already sets the temperature, the printer may heat to one temperature, then when ready change to another, wasting time. Check what your material profile already does before adding redundant commands.
A third mistake is not testing on a short print first. Custom G-code that looks correct can still cause problems — a pause command in the wrong place, a temperature that's too high, or a movement that crashes the nozzle into the print. A 10-minute test saves you from ruining a 4-hour print.
Frequently Asked Questions
What happens if I add G-code with a syntax error?
The printer will either ignore the command and continue printing, or it will stop responding and require you to cancel the print and restart. There's no warning — you won't know until you run it. This is why testing on a short print first is important.
Can I add G-code that changes the print speed mid-print?
Yes. Use M220 S[percentage] to change speed — for example, M220 S80 sets speed to 80% of the profile setting. Add this to Layer Change G-code at the specific layer where you want the change to happen.
Do I need to know G-code to use Bambu Studio?
No. Bambu Studio generates all the G-code you need automatically. Custom G-code is only necessary if you want to do something the software doesn't have a menu option for, like pausing mid-print or running a custom cleaning routine.
Where do I find G-code commands for my specific printer?
Check your printer's manual first — it usually has a G-code reference. The Bambu community forums and Reddit's 3D printing subreddits also have working examples for common tasks. Copy from sources you trust rather than guessing at syntax.
Can I save custom G-code so I don't have to add it every time?
Yes. In Bambu Studio, create a custom material profile or printer profile with your G-code already filled in. Then every time you load that profile, your custom commands will be there automatically. This saves time if you use the same custom commands repeatedly.