InitPostEntity is the correct hook to use when adding or removing entities on startup. Basically that hook is called when all of the map entities have already spawned, so by spawning more you won’t shift their EntIndex in that hook.
I’d recommend doing what Xaotic is recommending, that way you’re only looping through all entities once instead of twice. ents.Find* functions can be costly.
hook.Add( "InitPostEntity", "PH_RemoveWeaponsAndItems", function( )
for k, _ent in pairs( ents.GetAll( ) ) do
// Worldspawn is NULL, skip in that case..
if ( !IsValid( _ent ) ) then continue; end
// If the item classname starts with item_ then this var will be true
local _bItem = string.StartWith( _ent:GetClass( ), "item_" );
// If the entity is a weapon, this var will be true ( The vars don't need to be here, just showing alternative methods )
local _bWeapon = _ent:IsWeapon( );
// Now, if either var is true, remove the entity safely ( checks IsValid, etc... Things can change during a loop and errors can occur )
if ( _bWeapon || _bItem ) then
SafeRemoveEntity( _ent );