# Klipper G-Code Shell Command Extension

Learn how the Klipper gcode_shell_command extension runs shell commands from a macro, where it fits in a print workflow, and how to call it safely.

The Klipper g-code shell command extension is a small module named gcode_shell_command that lets a Klipper macro run an operating system shell command as if it were a g-code command. Klipper reads the macro, hands the command line to the host computer's shell, and returns a result the macro can check. It is a tool for the Klipper host, not for the motion board, and it belongs in macros where a script or utility has to run alongside a print job. 

## What the extension actually does 

The extension registers a named command in Klipper and runs a shell command on the host when that name appears in a macro. The printer's control board never sees the shell command, because the host issues it outside the motion firmware. Klipper passes the working directory and any arguments you define in the section, and the macro receives a return value from the shell process. That return value is what lets a macro stop or continue based on whether the command succeeded. 

## Declaring a command in printer.cfg 

A gcode_shell_command section in printer.cfg declares the command name, the executable, and its arguments or environment details. You choose the section name, and that name becomes the g-code word you call from a macro. Keep the executable path absolute so the host finds it regardless of the working directory. Declare only what the macro needs, since each section is a command the host can run at any time. 

## Calling it from a macro and checking the result 

A macro calls the declared command like any other g-code line, then reads the returned status before it moves on. Shell commands that change files or control hardware should report a clear pass or fail so the macro can respond. Because the command runs on the host, a failing script can block a print if the macro waits on it without a check. Test a new shell command on its own before you place it inside a print macro. 

## Questions about Klipper shell commands 

### Is the Klipper g-code shell command extension the same as a normal g-code command? 

No, the Klipper g-code shell command extension runs a host shell command and only looks like g-code inside Klipper. The printer firmware does not interpret it, so the shell process runs on the computer that hosts Klipper. A macro calls the declared name, and the host executes the underlying program or script. 

### Do I need the extension installed for gcode_shell_command to work? 

Yes, gcode_shell_command must be present in the Klipper installation before a section with that name is understood. Without the module, printer.cfg fails on the unknown section and Klipper reports a configuration error. Check the installed modules first, then add the section to printer.cfg and restart the host service. 

### Can a shell command from a Klipper macro damage the printer? 

Yes, a shell command from a Klipper macro can damage hardware or files if it is written carelessly. The host runs it with the permissions of the Klipper user, so it can reach any file or device that user can. Ask a trained specialist to review commands that touch motion limits, heaters, or system files before use. 

### What can I use a Klipper shell command for in a print workflow? 

A Klipper shell command can run a script that copies logs, sets a light through a host utility, or backs up a configuration file. It suits host-side tasks that sit beside the print rather than motion control. Keep motion, heating, and safety decisions in the printer firmware, and use the shell command for host chores that a macro coordinates.
