Carbon fiber (CF) composites are made up of sheets of carbon fiber filaments. The key motivation for the question is that they can sustain damage that isn't visible, but that can propagate and later fracture. That is, in the worst case, your bike might tip over at a coffee stop, and then 5 years later it breaks while you're sprinting. If you have visible damage (I have some picture examples), you can get the frame repaired and it may not be as costly as you fear.
If you encounter a situation where you fear for invisible damage, then I think you can keep using the bike but actively monitor the impact areas for signs of failure. In medicine, this is called watchful waiting or active surveillance. If you have a very hard crash or you take a very hard impact, then I'd be more cautious.
Background
To make CF structures, manufacturers usually buy big rolled up sheets of carbon fiber. They cut up the sheets into various shapes (usually designed beforehand in computer software), then lay them up onto a mandrel or other structure. The sheets are impregnated with resin. They will then bake them at high pressure and temperature to cure the resin. The image below is from a Youtube video showing how Mad Fiber wheels are made - that company is now defunct, this is just for illustrative purposes. The metal item is a mandrel, which is a bit like a mold except that you put sheets of carbon on to a mandrel, versus you would put things in a mold. There are alternative manufacturing techniques like resin transfer molding, but this explanation will suffice for this purpose.
Visible damage
Remember that your frame or whatever is made up of layers of carbon. If you see signs of torn fibers or imprints in the carbon without obvious tears, the structure is damaged. You're looking for some sort of penetration going through multiple layers. The image below is from Appleman Bicycles, who is a carbon framebuilder and repairer in my city. Disclosure, he's local to me and we are acquaintances, but I'm not a customer. On the left side of the frame, the fibers are clearly broken.
Or here is a question where chain drop has also caused damaged fibers.
Imprints (may be called witness marks) on the steerer can form from a loose headset. By the way, it's worthwhile to periodically take your fork out for inspection. One example is below, from this question. My understanding is that this is repairable, that it isn't a complex job, and that it's not very costly (source Raoul Luescher, Escape Collective Discord). If a local repairer can't fix it, consider asking around; the repair techniques should have spread through the industry, but not all repairers may know them. You can also get imprints on carbon handlebars around the shifter clamps, because our shifters often rotate in a crash. Luescher discussed that issue here. I don't have information that this can be repaired, but you could ask.
The bike below finished Unbound Gravel in 2023. There was a very high-attrition mud section on the course. See the concentric rings in the abraded section. The mud abraded through several layers of carbon. This is another visible failure. Again, this needs repair for sure. However, it is repairable.
What to do if you're uncertain: I think watchful waiting is acceptable
This section concerns what to do if you sustain an impact that doesn't leave obvious damage. This is a harder question.
Damage to carbon items is frequently not visible at the surface. However, an impact, even a fairly soft one, might lead to a delamination (term of art for a fracture) below the surface that later grows into a larger failure.
Ultrasound or other imaging is used to inspect CF parts in the aerospace industry. Ideally, we would have this capability widely available, but we do not and it requires specialized training. This is the only reliable way to detect a delamination under the surface. Your local bike store almost certainly cannot do this, at least as of 2024. Many people will propose a tap test, where you tap a coin lightly around the suspected fracture and listen for a change in pitch. Raoul Luescher says that this test can work on flat surfaces of constant thicknesses. However, bikes have a lot of curvature and varying thicknesses. Rob Granville of Carbon Bike Repair concurs, with a video demonstration. If you do try this, you are listening for a marked drop in pitch.
For lighter impacts where you can't see damage, I think watchful waiting is acceptable. That is, be familiar with how your bike sounds and how it flexes under your pedaling. If you notice a sudden change, stop riding and try to see if there are any cracks. They may be small. If you had a heavy impact, e.g. car vs. bike, I would lean more towards finding a repairer to inspect. Photograph the affected area and monitor for changes.
One example of a small fracture is below, picture from a video by Raoul Luescher, a carbon bike repairer based in Australia. Here, a metal part associated with the steering system hit the bike's head tube from inside due to arguably poor design. There was a small visible crack from the outside.
Alternatively, Carbon Bike Repair shows an aluminum bottom bracket shell coming unbonded from the frame, possibly due to repeated thermal expansion and contraction of the shell (whereas carbon exhibits much less thermal expansion). You might see a ring of cracked paint around the circumference of one side of the shell, and if you applied force through the cranks, you could probably see the crack flex (this may be aided by a smartphone camera + magnification).
I believe that paint chips around frequently handled parts can be ignored. These might include areas around the dropouts. Gravel bikes may frequently take paint chips from flying bits of gravel. Some examples of what I believe to be paint chips are below, taken from recent posts.
In contrast, the image below shows actual damage. If you look closely at the chip, I believe you can see some broken fibers. The owner had this inspected and repaired.
Carbon repairs may not be that that expensive compared to repairing metal frames. On metal frames, damage will frequently involve replacing the entire affected tube. In contrast, with carbon, the second photo from Appleman bicycles shows that repairs can be localized to just the damaged area. The repairs may not be cheap compared to purchasing a new frame; sometimes, companies may be willing to extend a crash discount to customers.
I believe that forks, wheels, stems, and handlebars are not cost effective or possible to repair (aside from the ring of death above). This was reported by some carbon repairers who have appeared on podcasts like the old Nerd Alert (Cyclingtips, now defunct) or the Marginal Gains podcasts. There's no harm asking a repairer near you, but you should prepare to replace these components if damage is suspected. Many premium wheelsets are starting to come with free crash replacement guarantees for the original owner. Otherwise, manufacturers typically reserve some rims and other spare parts for warranty and repair cases.
In addition, if a major frame tube gets broken all the way through, I'm not sure the frame could be trusted even if repaired. Josh Poertner and colleagues on this Marginal Gains podcast discussed this starting around 22:50. I believe they said that seat stays, which are lightly loaded, can be repaired even if broken through. I am not sure about chain stays.
A note on handlebars and forks
If you crash or drop a bike, by virtue of their position, the handlebars are likely to take an impact. In contrast, it is unlikely that you will hit a carbon crank but not the handlebars. In the case of head-on collisions, you can assume that the fork has taken a hard impact as well.
If a handlebar or fork fails under load, you are extremely likely to crash. It may be worth being more conservative with these parts if they're made of carbon, and leaning towards replacing them if damage is suspected. In fact, it may be good advice to replace these parts regularly. I realize that this is easier said than done, and I am not aware of empirically-backed replacement intervals for these parts.
For many frame tubes, if one tube fails under load, a skilled rider can often come to a controlled stop, and there is some degree of redundancy if the tube is a chainstay or seatstay.
Some notes on prevention
My understanding is that CF does especially poorly under point loads - i.e. getting hit by a small hard object. While this is easier to say than to do, users can consider all the scenarios where hard objects might hit the frame and try to mitigate them. In this question, the poster packed their bike in a bag, but the fork rotated and the rim brake caliper hit the frame. While the solution would again be watchful waiting, it's worth trying to avoid such things happening. For example, if packing a bike, one could try padding the rim brake calipers or otherwise not pack hard objects in the same case.
A side note: minor surface damage inside the frame
As I discuss on another answer, frame manufacturers designing for high-level competition obviously push frame design. There may be cases when a carbon tube is flexing against a metal item. For example, in late 2021, Specialized recalled their Tarmac SL7 frames and forks. The headset had a compression ring on the outside of the fork steerer. As the bike hit bumps, the compression ring had an relatively sharp edge that dug into the steerer tube's surface. This would eventually cause a failure. However, Raoul Luescher raised an issue with the fix, namely that now the compression plug, which was cut to length, could have a sharp edge as well. He showed a borescope shot of the inside of the fork where the edge of a compression plug marked the surface of the fork, and he argued that this is likely to fail eventually. For performance road bikes with hydraulic hoses routed inside the steerer, an unexplored issue is that over time, the hoses might abrade through the steerer tube's fibers as well.
The watchful waiting advice applies to damage from one-time events. The issue of damage from repeated events is a more serious one. However, this sort of damage is likely to happen outside your line of sight, and it might require specialized tools to even see.
Further viewing
Raoul Luescher (Australia) has a YouTube channel and an Instagram. He typically discusses engineering issues and shows cut-up frames and components. I don't remember him showing his repair process, though.
Carbon Bike Repair (UK) also has a YouTube channel and Instagram. They show damaged frames, and select shots of their repair and repainting processes. They're a good channel to see examples of what carbon damage looks like.
This Marginal Gains podcast features a Q&A with Shawn Smalls of Ruckus Composites (US).
This is a Nerd Alert (part of Cyclingtips, now defunct) podcast with Ruckus Composites and Raoul Luescher. The parent company has been restructured, and I'm not sure how persistent this link will be. However, this podcast was stored off-site (and may still be available on regular podcast apps).
This Ruckus Composites video shows a bike with damage to a section of the top tube. They showed the results of the tap test, and they also showed how they do and interpret an ultrasound scan of the area.
Moving on to forks, Mike Lopez, who says he worked on the Reynolds Ouzo Pro fork around the late 90s or 2000s, comments on the Paceline forum on how they decided on test protocols and tried to think about how they could simulate real-world use.
What's watchful waiting/active surveillance in medicine?
Medical issues may resolve themselves (not relevant to this example), or they may just remain dormant (entirely possible in this example). Benign prostate hyperplasia (prostate enlargement) is an example where watchful waiting is often the better choice than aggressive treatment.
The watchful/active part is key. In medicine, you would actively monitor for symptoms, and perhaps periodically do clinical tests (e.g. mammography, prostate specific antigen screening). Unfortunately, with bikes, screening is more expensive and not locally available everywhere. With bicycles, some potential delaminations won't lead to an immediate loss of control - you can ride home with a broken seatstay, and breaking a chainstay shouldn't cause a crash. Of course, breaking a fork steerer or a handlebar will almost certainly cause a crash.