Spread spectrum (SS) is being considered as an access technology for mobile ad hoc networks (MANETs). However, code assignment, collision avoidance, and efficient bandwidth usage become difficult to resolve due to the distributed nature of MANETs. We propose an SS medium-access-control protocol with dynamic rate and collision avoidance. Unlike previously proposed protocols, it allocates the rate dynamically according to the neighboring terminals' activity status. If the total number of usable spreading codes with this spreading factor is less than the total number of mobile terminals in the network, to avoid a collision, the ID of a spreading code assigned to a packet is broadcast such that other terminals can avoid using it when the packet is being transmitted. We analyze its throughput in a slotted single-hop multiuser environment theoretically and multihop environment by simulation results indicate that it outperforms static code allocation protocols significantly.