Automagics are a feature of a running kernel, not the syntax. For example, cd by itself is a valid automagic unless it's shadowed by a Python name, or for that matter if %automagic is disabled.
In [1]: cd
/home/wja
In [2]: cd = 'CD'
In [3]: cd
Out[3]: 'CD'
In [4]: del cd
In [5]: cd
/home/wja
In [6]: %automagic 0
Automagic is OFF, % prefix IS needed for line magics.
In [7]: cd
Traceback (most recent call last):
File "<ipython-input-7-9c6465b4471e>", line 1, in <module>
cd
NameError: name 'cd' is not defined
Under the hood, from what I understand, when a cell throws certain errors like SyntaxError or NameError, it's sent to the prefilters, and if it could be transformed into a magic, it's caught by the prefilter AutoMagicChecker and transformed. My understanding is mostly based on this comment on an IPython GitHub issue:
Input transformers are applied line-by-line, but prefilters are only applied when the code is run. So 'invalid' [an invalid line] triggers an attempt to execute, and then prefilters step in and may transform it into valid code.
-- Thomas Kluyver, 11 Jul 2015
Now, if you do have a running kernel, you could use the prefilters, something like this:
In [1]: ip = get_ipython() # The running kernel
In [3]: source = ip.prefilter('cd') # Transform
In [4]: source
Out[4]: "get_ipython().run_line_magic('cd', '')"
In [5]: exec(source) # Run, just to prove it works
/home/wja
Or, the long way:
In [2]: from IPython.core.splitinput import LineInfo
In [3]: line_info = LineInfo('cd') # Parse
In [4]: ip = get_ipython()
In [5]: ip.prefilter_manager.checkers # List of prefilters
Out[5]:
[<EmacsChecker(priority=100, enabled=False)>,
<MacroChecker(priority=250, enabled=True)>,
<IPyAutocallChecker(priority=300, enabled=True)>,
<AssignmentChecker(priority=600, enabled=True)>,
<AutoMagicChecker(priority=700, enabled=True)>,
<PythonOpsChecker(priority=900, enabled=True)>,
<AutocallChecker(priority=1000, enabled=True)>]
In [6]: for checker in ip.prefilter_manager.checkers:
...: handler = checker.check(line_info)
...: if handler: # Find the first one that matches
...: break
...:
In [7]: handler
Out[7]: <IPython.core.prefilter.MagicHandler at 0x7f01e8ccc7f0>
In [10]: handler.handle(line_info) # Transform
Out[10]: "get_ipython().run_line_magic('cd', '')"