See http://eprints.maths.ox.ac.uk/926/1/NA-10-03.pdf. MATLAB implementation in https://github.com/chebfun/chebfun/blob/34f92d12ca51003f5c0033bbeb4ff57ac9c84e78/%40chebfun/cf.m (BSD-licensed); I tried to port (I know MATLAB reasonably well) but I'm stuck in the mud trying to understand what it's doing in places, like the vscale method.
See also http://www.chebfun.org/examples/approx/CF30.html which contains an earlier, less complicated version.