Valve Developer Union

Config Files, and How to Make One

(October 7, 2017)

Console commands can be used to change anything from the amount of ammo a gun has by default to debugging AI nodegraphs and the PVS to changing the texture filtering mode in a GoldSrc game. Very powerful indeed, but remembering them or typing them out over and over can be a slog.

If you find yourself running a set of commands over and over, forgetting some and typing more than you should, perhaps it's worth a look at writing a config file. A config file, or a .cfg, is a list of commands executed either by the game on startup or by the player in the console when run with the exec command.

Before we begin, it's worth noting that custom config files cannot get you VAC-banned. This is a common misconception. Config files actually serve an important purpose in the engine, and Valve includes many with their games to store keybinds and other settings.

Where are these config files?

For GoldSrc games, config files are located in the top level of the mod directory. For example, Team Fortress Classic has them in /Half-Life/tfc. Source config files are kept neatly in a separate /cfg directory; Half-Life 2 keeps its config files in /Half-Life 2/hl2/cfg.

Common config files


A config for every situation

Many of the config files listed here are actually run by the game in specific circumstances. Half-Life 2's chapters are all separate config files. If you're using an Xbox 360 gamepad, its settings are stored in another config called 360controller.cfg that's only used when an Xinput gamepad is detected.

A list of Garry's Mod config files
A list of Garry's Mod config files

Most games have a lot of config files lying around. Two of the more common ones are autoexec.cfg and config.cfg.


autoexec.cfg gets run automatically at the start of the game. Often, this contains commands that affect the entire game, such as sv_lan 0. If you were to put the command echo "This was run by autoexec!" into your autoexec.cfg, you would see this in the console when you run the game.

Text being echoed by autoexec.cfg
Text being echoed by autoexec.cfg

Not all games have a autoexec.cfg by default; you can create it if it doesn't exist.


Config files on shuffle?

Counter-Strike: Global Offensive has been known to sometimes run config files out of order, causing autoexec commands and settings to be overwritten by other config files. To avoid this, you can add host_writeconfig at the end of your autoexec.


config.cfg contains commands that are more related to in-game behavior. If you make changes to your keyboard layout, mouse sensitivity, or sound settings, or have custom keybinds, they'll get saved in here.

The following is an example of what types of commands are usually found in a config file, from Counter-Strike: Global Offensive's config_default.cfg.


bind "ESCAPE" "cancelselect"
bind "`" "toggleconsole"

bind "TAB" "+showscores"
bind "SPACE" "+jump"
bind "," "buyammo1"
bind "." "buyammo2"
bind "0" "slot10"
bind "1" "slot1"
bind "2" "slot2"

config_default.cfg is executed when config.cfg is not present.

Making your own config files

You can make your own config files quickly and easily. We'll be making one for Garry's Mod called MyConfigFile.cfg. All you need to make one is a text editor; Notepad will work fine.

  1. Open your text editor and make a new file.
  2. Add the commands you want to it. As a basic example, we'll add two commands to ours; sv_cheats 1, which activates cheats, and sbox_godmode 1, which makes the player invulnerable. Make sure they're on separate lines.
  3. Save the file and navigate to the config directory of the game you're making the config for. Since our config is for Garry's Mod, we will navigate to GarrysMod\garrysmod\cfg.
  4. Save the file with a .cfg extension. Notepad will save files with a .txt extension if you're not careful. You can confirm this by wrapping the file name in quotes and by changing the "save as type" to "All Files".
Saving a config file with Notepad
Saving a config file with Notepad

Running config files

Config files can be run regardless of cheats or elevated server admin status, though the commands themselves are still bound to those limits. Configs are run with the exec command. You can run a config file in the console by typing exec <config file name>. Remember to leave off the .cfg extension when you go to run it.

Since our above example was called MyConfigFile.cfg, we would run exec MyConfigFile to run it in-game. Note that exec autocompletes with the config files available to the game.

Running a config file from the console
Running a config file from the console

exec itself can be run from a config, to chain config files together.

You can bind configs to a key and run them whenever that key is pressed. If you wanted to run MyConfigFile.cfg whenever you pressed your P key, you would run bind p "exec MyConfigFile" in the console.

Config files are a powerful tool that can save you a lot of time when you're doing work in the console.