The Didache clearly teaches that anyone who wishes to receive communion must first go to confession.
The celebration of Mass began with the Last Supper and was continued by the early disciples of Jesus. This “breaking of the bread” is found in various New Testament letters, but also an ancient document called the Didache.
The Didache is an early collection of writings that most scholars date to the 1st century. Some have even claimed that it can be dated to 48 AD, based on evidence that it may have been written before the Council of Jerusalem.
The Didache details various aspects of the early celebration of Mass, such as the requirement to receive holy communion.
But every Lord’s day gather yourselves together, and break bread, and give thanksgiving after having confessed your transgressions, that your sacrifice may be pure. But let no one that is at variance with his fellow come together with you, until they be reconciled, that your sacrifice may not be profaned. For this is that which was spoken by the Lord: In every place and time offer to me a pure sacrifice; for I am a great King, says the Lord, and my name is wonderful among the nations.
It is clear from this passage that the confession of sins was an essential part of participating in Mass and receiving holy communion.
Confession of grave sins
The Catholic Church has maintained this position, explaining that it is only grave sin that prohibits us from reception of communion.
A person who is conscious of grave sin is not to … receive the body of the Lord without previous sacramental confession unless there is a grave reason and there is no opportunity to confess; in this case the person is to remember the obligation to make an act of perfect contrition which includes the resolution of confessing as soon as possible.CIC 916
Venial sins do not need to be confessed before communion.
The early Christians knew that before we can be united to God in holy communion, we must first reconcile ourselves to him.