It depends on a few things. If you can show the loan company that you will have a positive budget after bankruptcy, you can sign a reaffirmation agreement with most loan companies in order to keep your car. This is an agreement with the loan company stating that you want to reaffirm the loan after bankruptcy – that you want to keep the car and keep making payments on it. The benefit to this agreement is that you keep your car, and each payment you make on the car after bankruptcy is reported on your credit score to help improve your credit. The downside is that if you fail to make payments after bankruptcy, the loan company can still take the car back and you will still be responsible for any debt remaining on the loan.
Some loan companies may allow you to keep the car without signing a reaffirmation agreement. In this case, you could keep the car as long as you kept making loan payments, but if you stopped making payments the loan company could always take the car back. Your payments would not be reported on your credit score, but if you stopped making payments, you would not have to pay the money remaining on the loan either. However, some loan companies will require you to sign a reaffirmation agreement, and will not let you keep the car without signing the agreement.
You also need to be sure you can protect the car in your bankruptcy, but that is a separate matter. You should consult an attorney if you are considering bankruptcy and wondering whether you will be able to keep your car, and/or whether your loan company will let you keep your car after the bankruptcy.