The following is from the 2009 International Residential Code which is the basis for most State Building Codes, your code requirements may differ:
Pay attention to the exceptions .... Joe gave you good advise
R1001.11 Fireplace clearance.
All wood beams, joists, studs and other combustible material shall have a clearance of not less than 2 inches (51 mm) from the front faces and sides of masonry fireplaces and not less than 4 inches (102 mm) from the back faces of masonry fireplaces. The air space shall not be filled, except to provide fire blocking in accordance with Section R1001.12.
1. Masonry fireplaces listed
for use in contact with combustibles in accordance with UL 127 and installed in accordance with the manufacturer's installation instructions are permitted to have combustible material in contact with their exterior surfaces. 2. When masonry fireplaces are part of masonry or concrete walls, combustible materials shall not be in contact with the masonry or concrete walls less than 12 inches (306 mm) from the inside surface of the nearest firebox lining. 3. Exposed combustible trim and the edges of sheathing materials such as wood siding, flooring and drywall shall be permitted to abut the masonry fireplace side walls and hearth extension in accordance with Figure R1001.11, provided such combustible trim or sheathing is a minimum of 12 inches (305 mm) from the inside surface of the nearest firebox lining. 4. Exposed combustible mantels or trim may be placed directly on the masonry fireplace front surrounding the fireplace opening providing such combustible materials are not placed within 6 inches (152 mm) of a fireplace opening. Combustible material within 12 inches (306 mm) of the fireplace opening shall not project more than 1/8
This is the link so you can view for yourself all the requirements of Fireplaces and Chimneys http://publicecodes.cyberregs.com/ic..._10_par001.htm
Hope this helps!