  The detection of the 100 GeV-TeV emission by a gamma-ray burst (GRB) will
provide an unprecedented opportunity to study the nature of the central engine
and the interaction between the relativistic flow and the environment of the
burst's progenitor. In this paper we show that there are exciting prospects of
detecting from the burst by MAGIC high-energy (HE) emission during the early
X-ray flaring activity and, later, during the normal afterglow phase. We also
identify the best observational strategy, trigger conditions and time period of
observation. We determine the expected HE emission from the flaring and
afterglow phases of GRBs in the context of the external shock scenario and
compare them with the MAGIC threshold. We find that an X-ray flare with the
average properties of the class can be detected in the 100 GeV range by MAGIC,
provided that z<0.7. The requested observational window with MAGIC should then
start from 10-20 s after the burst and cover about 1000-2000 s. Furthermore, we
demonstrate that there are solid prospects of detecting the late afterglow
emission in the same energy range for most of the bursts with z<0.5 if the
density of the external medium is n> a few cm^-3. In this case, the MAGIC
observation shall extend to about 10-20 ks. We provide recipes for tailoring
this prediction to the observational properties of each burst,in particular the
fluence in the prompt emission and the redshift, thus allowing an almost real
time decision procedure to decide whether to continue the follow-up observation
of a burst at late times.
