US tax pitfalls for a non-US person moving to the US

 lists and describes the major difficulties that may be faced by non-US persons who move to the US and so enter the US 'tax net', where they were previously outside of it. Non-US persons are US nonresident aliens. That is, they are not US citizens and not US permanent residents (also known as green card holders).

The US has complicated tax laws that often apply unfavourably to non-US investment holdings and assets. These can create significant tax difficulties and expenses for new US residents who have investments or other assets in their non-US country and which they do not cash in before becoming US residents.

The information in this article describes the situation for new US residents, people who have moved to the US from other countries. It is also a list of considerations for anybody who is not yet a US resident but is contemplating becoming one in the future.

Introduction
In contrast to countries that allow an initial period of non-domicile residence before becoming a full taxable resident, the US taxes its residents on their worldwide income, and applies its full tax code, from the moment that an individual becomes a US tax resident. It has punitive tax laws for assets or investments held outside of the US by US residents.

This combination causes problems for new US residents who leave investments or assets behind in their previous country of residence when they move to the US. The sections below describe how new US residents can face unpleasant US tax surprises.

Definition of US residency for tax purposes
The US uses two separate tests to determine "residency for tax purposes". These are:
 * the green card test, and
 * the substantial presence test.

Under the green card test, you are a US taxable person if you have spent at least one day in the US as a permanent resident. Under this test, it is not a requirement that you possess a physical green card, just that your application is approved and activated. Also, you are not a US taxable person if you have received the card, but have yet to enter the US.

Under the substantial presence test, the US counts the number of days of presence in the country in a given year, including weighted periods of presence in prior years. If this exceeds 183, unless you can use the closer country exception, you are a US taxable person for that year.

For the year of arrival, it is generally possible to apply split year tax treatment, so that you do not suffer US tax on income that occurred before you moved to the US. However, electing this has some potential disadvantages. You cannot use the US standard deduction, and you cannot file a joint return with a spouse. Both of these disadvantages may increase your US tax liability relative to a similarly situated US citizen.

After the year of arrival, assuming you remain in the US, under the substantial presence test you will be a full US taxable person for the years that follow. For those years, you will be able to use the normal deductions and filing statuses available to US citizens.

Once you are a US taxable person — that is, you pass one of these two tests — your entire worldwide income is instantly subject to full annual US taxation and reporting.

J, F, M and Q visa holders
If you moved to the US for employment, and do not have a green card, it is likely that you have either an H or an L visa. For these visas, the substantial presence test applies. However, J, F, M and Q visa holders can exclude a few calendar years, so effectively delaying (or entirely avoiding) becoming US taxable persons.

However, the US has a special rule for any capital gains that you realise as a US nonresident alien living temporarily in the US on a J, F, M or Q visa. If you are present for 183 days or more, you become liable for a flat 30% tax rate on US source capital gains. This 183 days test is unrelated to the 183 days of the substantial presence test.

Also, except for students from India, US nonresident aliens cannot generally use any US tax exemptions or the standard deduction, and if married, can only file their US taxes as Married Filing Jointly if their spouse is a US resident or US citizen.

If you later transition to an H or L visa, or a green card, you immediately lose any benefits of staying outside the US tax system yet living in the US under a J or similar visa.

A and G visa holders
Foreign government related individuals can hold A and G visas. These operate for US tax purposes similarly to J, F, M and Q visas. Holders of these visas, apart from A-3 and G-5 holders, are also exempt from the substantial presence test, and so can exclude years of presence in the US from making them fully liable for US tax.

A-3 and G-5 visa holders are specifically not considered to be foreign related government individuals, and so are not exempt from the substantial presence test.

Also, again as with J, F, M and Q visa holders, there is a special rule for any US source capital gains that you realise as a US nonresident alien living temporarily in the US on an A or G visa; that is, a flat 30% tax if you are present for 183 days or more.

Timing becoming a US taxable person
If you meet the substantial presence test for a year, your residency start date is generally the first day of presence in the US during that year. If you meet the green card test, your residency start date is the first day of presence in the US as a permanent resident. The IRS provides a number of examples of when your US tax residency begins.

If you have deferred income in a given year, it may be worthwhile to try and delay becoming a US taxable person, or if possible, making use of any window of time during which you can be physically present in the US but not yet a US tax resident. See Earnings and salary below for more. Pay particular attention to any pre-arrival trips you might make to the US. These have the potential to produce a surprising and unpleasant US tax outcome, by effectively backdating your arrival date to the date of the visit.

US tax treaties
If there is an income tax treaty between the US and the country where you retained non-US holdings, it may offer some limited protection against US tax problems on your non-US investments and assets.

And if there is a separate estate tax treaty between the US and the country where you retained non-US holdings, it may offer some protection against confiscatory US estate tax on your assets, should you die while a US resident.

Canada does not have a separate estate tax treaty with the US. Instead, the US maintains a single treaty with Canada that combines both income taxes and estate taxes. Under this combined treaty, Canadians receive protection up to the level of the US estate tax exemption allowed to US citizens, the same as generally provided by the separate US estate tax treaties for other countries.

It will be worth being familiar with any applicable treaty. However, reading treaties is not a simple exercise. Most are written in dense prose, and some exist only as an elderly basic treaty but with many clauses overridden by subsequent protocols. And US income tax treaties usually contain a saving clause that, for US residents (and US citizens), denies most treaty benefits that would mitigate US tax. For example:

"Notwithstanding any provision of this Convention except paragraph 5 of this Article, a Contracting State may tax its residents (as determined under Article 4 (Residence)), and by reason of citizenship may tax its citizens, as if this Convention had not come into effect."

Delayed or deferred earnings and salary
Employers often pay salary in arrears, so it is quite possible that you will receive your final non-US paycheck when a US taxable person. This can generate an unwanted and perhaps unnecessary US tax liability, because the US taxes income based on when you receive it.

If you have coverage from a US income tax treaty, this may (if not overridden by a treaty saving clause) offset that issue, because treaties usually reserve taxing rights on employment income to the country in which the work was performed. Otherwise, or to avoid this issue, it is usually best to accelerate income where possible so that you receive it before becoming a US taxable person. Receiving it afterwards may lead to double-tax.

Tax and reporting for non-US cash accounts
The US requires you to report any non-US financial accounts above a relatively low threshold amount on 'informational' forms. You have to file these reports annually, and while they are broadly duplicative, one or both of the following may be required:


 * Form 8938, Statement of Foreign Assets. Here you list the details, income and balances of all your non-US accounts.
 * FinCEN Form 114, Foreign Bank Account Reporting (FBAR). Filed annually with the Financial Crimes Enforcement Center. This form can only be filed electronically. The threshold for filing is very low, just $10,000 in non-US accounts.

It is easy to overlook these forms, but the penalties for non-filing are huge, starting at $10,000 even for non-wilful errors.

Since the Foreign Account Tax Compliance Act (FATCA) passed into law in 2010, a number of non-US financial institutions now regularly refuse accounts to US citizens and US residents, and some may unilaterally close the accounts of anyone who becomes a US citizen or US resident. You will want to be certain that any non-US bank or other financial institution you hold accounts with will allow you to maintain those accounts after you have become a US taxable person. Under FATCA, non-US banks must provide the IRS with details of the assets of, and interest and dividend payments made to, US residents and US citizens.

Non-US savings accounts and other interest-paying accounts
As well as reporting the existence of any non-US savings or interest bearing accounts annually on Form 8938 and FinCEN Form 114, you also need to report any interest income you receive from these accounts as US taxable income. US banks will send Form 1099 to investors to inform them of the taxable interest they have receive, but you will probably not receive these forms from non-US banks.

Without a Form 1099, you have to account for the interest yourself on your US tax return, computing the USD equivalent to whatever you received, and using the exchange rate in effect on the date of payment. If your foreign bank pays you interest monthly, this can quickly become a huge workload. Also, non-US savings accounts that are tax-sheltered or tax-free in the country where the account is based are generally not sheltered from US tax. For example, a UK cash Individual Savings Account (ISA) is fully taxable to the US for a US resident.

In many cases, the best way to handle this problem is to simply cash in these accounts before becoming a US resident, convert the balance to USD and transfer it into your US accounts, and then re-invest the money in US savings accounts once you are a US resident.

Non-US investment accounts
As with non-US cash accounts above, these accounts need to be reported on Form 8938 and FinCEN Form 114 if you meet the asset limits for reporting. These 'informational' reports generally include non-US pensions as well as any and all other non-US investment accounts. Also similarly to non-US cash accounts, any investment accounts you hold in non-US financial institutions are at risk of closure, if these financial institutions have a policy of avoiding US FATCA reporting.

PFIC tax penalty for non-US taxable accounts
Directly holding shares or bonds poses no particular problems, but any ETFs, funds, investment trusts or other collective investment vehicles held before becoming a US taxable person are very likely to be non-US domiciled, making them passive foreign investment companies (PFICs).

The US tax rules on PFICs are harsh to the extent that they entirely discourage ownership. But because US tax laws for US domiciled ETFs held by nonresident aliens are also harsh, most nonresident aliens will prefer non-US domiciled funds and ETFs. This makes it probable that any existing investments you hold on moving to the US are PFICs. If you hold any non-US domiciled funds or ETFs, your main defence against PFIC issues is to sell these before you become a US taxable person.

No "step-up" in US basis on becoming resident
Beyond this, in all cases you should also consider selling (and then potentially repurchasing) any assets you own that have a built-in and as yet unrealised capital gain. The US taxes capital gains based on the difference between the USD value at purchase and the USD value at sale, and provides no step-up in basis for when you move to the US. Without washing away any capital gains before moving to the US, you could find yourself having to pay a large and unnecessary US capital gains tax on gains that occurred years or even decades before you set foot in the US.

Long-term bond and CD-like saving holdings that you took out before becoming a US resident may pay out their interest after you become a US taxable person. In this case, investigate if it is possible to allocate any part of the interest payment to periods before becoming a US resident.

Non-US tax-advantaged accounts lose their tax advantage
Unless any applicable US tax treaty specifically mentions them, any non-US accounts that are not pensions, but are tax-advantaged or tax-free to residents of the country in which they are based, lose their special status and become taxable to the US when you are a US resident. Examples include UK Individual Savings Accounts (ISA), Canadian Tax-Free Savings Accounts (TFSA), Japanese NISA accounts, and French Assurance-vie and Plan d'Épargne en Actions accounts.

For all such accounts, consider closing or collapsing them before becoming a US taxable person. If this is not possible, or not desirable, at the minimum you should ensure that they contain no PFICs. The most likely, but cleanest, US tax outcome is that the US will treat these as ordinary unwrapped taxable investment accounts. Less clean is if the US treats them as foreign trusts.

In all cases, as with taxable accounts above, you will want to wash away any capital gains in these accounts before becoming a US taxable person. The advantage with these accounts is that you will generally incur no non-US capital gains taxes by doing this while still a resident in the country where the accounts are located. Conversely, if any assets in the accounts have built-in capital losses, it may be worth deferring selling these until after you are a US resident, so that you can then use these losses to offset any future US capital gains taxes.

Non-US pensions may lose pension status
A few US tax treaties cover non-US and cross-border pensions well, but where one does not, this can leave you with a problematic and unpleasant situation where you hold a non-US pension. Whether or not they are exempt by treaty from annual US taxation, pensions are not exempt from Form 8938 and FinCEN Form 114 reporting.

If your pension is not covered by treaty but you can collapse or otherwise unwind it, it can be worth doing this before becoming a US taxable person. Otherwise, a number of US tax treatments are possible, but most if not all can often lead to double-tax on pensions; once annually to the US while assets grow, then again to the country where the pension is located on withdrawals.

For cases not covered by treaty, and where you cannot or do not wish to collapse or unwind your pension, you may have little, or even no, defence against this unpleasant and costly US tax treatment. Damage limitation may be your only option. As with other account types above, making sure that the accounts contain no PFICs and washing away any built-in gains before becoming a US taxable person are usually sensible moves. You might also consider holding only your lower growth assets in these pensions, to try to further reduce any double-tax outcomes.

Depending on the nature of your non-US pension, you may find yourself having to complete one or more of the following forms:
 * Form 8833, Treaty-Based Return Position Disclosure. Used to claim tax treaty benefits.
 * Form 8621, Information Return by a Shareholder of a Passive Foreign Investment Company (PFIC). Extremely time-consuming, but required if you hold any non-US domiciled funds or ETFs. The IRS's estimated time to complete this form is over 48 hours.
 * Form 3520, Annual Return to Report Transactions With Foreign Trusts and Receipt of Certain Foreign Gifts. For any activity involving non-US trusts, and also for gifts and bequests from non-US sources above $100,000.
 * Form 3520-A, Annual Information Return of Foreign Trust with a US Owner. Required if you own a non-US trust. Another extremely time-consuming and complex form.

Non-US real estate
Non-US real estate can produce several of the most vexing problems for new US residents. Moving to the US on a work visa, for example H or L, is an uncertain prospect. Your US residency status is entirely dependent on your employment, and if you lose or leave your job, you have just 60 days in which to either find another job with an employer willing to sponsor an H visa, or leave the US to avoid becoming 'out of status' for US immigration.

Retaining your non-US principal residence
Because of the visa uncertainties outlined above, it is common for people moving from other countries to the US to retain ownership of their previous home, perhaps renting it out, until they are certain that their residency in the US is secure. This period can extend for several years, perhaps while waiting for permanent residency (green card) processing. However, these actions do not intersect well with US tax laws.

Tax on rental income
If you keep your home in your previous country, and rent it out while a US resident, your rental income is fully taxable to the US. You will be able to claim some rental expenses, but these are limited.

You can also claim depreciation on your non-US home rental, but the depreciation benefit is lower for non-US properties than it is for US ones.

Capital gains tax on sale
In many countries, selling your principal home is entirely free of capital gains tax. However, the US limits tax-free gains. You can exclude up to $250,000 per individual if you have lived in this home for two of the past five years, otherwise there is no capital gains exclusion, and the entire gain on the property is US taxable. This rule applies to all property sales, and entirely ignores that you perhaps owned your home for years or even decades before becoming a US resident or US taxable person.

Moreover, the US measures the gain from purchase price in USD to sale price in USD, with no step-up on becoming a US resident. This can mean that, as with stocks and other investments mentioned above, you may end up with a US capital gains tax liability for gains that occurred years or decades before you set foot in the US.

Some countries may offer a way to enter into a transaction that results in you 'resetting' your basis in a property for US tax purposes, without the property changing actual ownership. If it does, it will be well worthwhile considering doing this before becoming a US resident.

Otherwise, the only way to mitigate this is to either be sure to sell the property before exceeding the 'two of the past five years' rule, or to continue to own it until you have left the US and escaped from its 'tax net'.

Tax on 'phantom' gains due to currency effects on sale
Because the gain is measured as the difference between the house price in USD at the rate in effect at the time of purchase and the house sale proceeds in USD at the rate in effect at the time of sale, there may be a gain (or loss) due purely to foreign exchange rate differences.

It is entirely possible to recognise a non-USD loss on selling a property that becomes a phantom USD gain solely because of exchange rate changes over the period of ownership. Unfortunately, you will have to pay the US tax on the phantom property gain with real money.

Tax on 'phantom' gains when repaying a foreign mortgage
If you pay off — or even make normal repayments on — a non-US mortgage, whether or not these repayments are related to selling a non-US property, you may have to pay further US tax due to foreign exchange rate changes. The US views repayments on a non-US mortgage as a potential currency gain, making it a taxable event. This is a second way in which the US can tax a phantom property gain.

Depreciation recapture tax
If you rented out your house, then on selling it the gain attributable to depreciation is taxable at US income tax rates, rather than at capital gains tax rates. This is true whether or not you actually claimed this depreciation against your US tax during the rental period. These tax rules yet again have the effect of further increasing your US tax liability on selling a property.

Retaining your non-US investment real estate
If you own investment real estate that is not your principal residence, then all of the tax rules for principal residence above apply. That is, tax on rental income, capital gains tax on sale, tax due to currency effects, tax due to foreign mortgage repayments, and depreciation recapture tax.

The only difference is that you no longer have a two-year selling window for a $250,000 'principal residence' exemption for US capital gains tax, but may instead be liable for US capital gains tax on the entire gain in the property since buying it, even if you sell the very next day after becoming a US resident.

To avoid this harsh tax result, you should strongly consider selling — or otherwise 'resetting' the US basis in — any investment real estate that you own, and that has a built-in capital gain, before becoming a US resident. Conversely, if it happens to have a built-in capital loss, consider deferring the sale until after becoming a US resident; this will allow you to use the loss to offset future US capital gains taxes.

US estate tax
The US has a large estate tax exemption for citizens and domiciled or permanent residents, but for individuals who are not domiciled in the US, the estate tax exemption is just $60,000. There is no unlimited marital exemption, unless your spouse is a US citizen. US estate tax rates for individuals not domiciled in the US are 26-40% of US assets above the $60,000 exemption.

As a new or temporary US resident, it is quite possible that you are subject to US income tax, but your domicile does not allow you to use the large US estate tax exemption for people domiciled in the US. This produces a difficult dilemma. You would only be subject to US estate tax on your 'US situs' assets (not your worldwide assets), but you cannot hold non-US domiciled funds or ETFs without falling afoul of draconian US PFIC tax rules, and US domiciled funds and ETFs are 'US situs' assets. In this case, you risk significant US estate tax liabilities if you hold more than $60,000 in any US based investments or assets.

Nationals of one of the handful of countries with a US estate tax treaty may be able to mitigate the US estate tax. Otherwise, the only way to mitigate this is to either become fully domiciled in the US, or keep 'US situs' assets to below $60,000 in total.

US gift tax
Alongside its estate tax, the US also has a gift tax that may affect you if you become a US resident. It applies to gifts above an annual limit (exclusion), and shares its exemption with that of the estate tax.

In general, gifts to a spouse may be unlimited, and do not trigger US gift taxes. However, a gift to a non-US citizen spouse (even if they are themselves a US resident or green card holder) is subject to an annual limit.

To avoid tangling with US gift taxes, consider making any planned sizeable gifts before becoming a US taxable person.

US state income taxes
State income tax is too complex and disparate to fully cover here, but as a general rule, if you live in a state with an income tax, everything listed above that is federally taxable will have a state tax that is payable on top.

In addition, several states do not honour US income tax treaties. This can mean that gains in a non-US pension that are not taxable federally may nevertheless still be taxable annually to your state of residence. And it can create ridiculously complex scenarios, and also often leads directly to double-tax — once when the gains accrue, and then again when you make withdrawals. This is a particular issue if you move state or country for retirement.

Becoming a green card holder or US citizen
One common way to alleviate visa uncertainties caused by your US visa being tied to your job is to apply for US permanent residency (a green card). However, while this will make your position as a US resident more secure, it comes with a series of drawbacks that may prove unpalatable, particularly for high net worth individuals.

Once approved for US Lawful Permanent Resident (LPR, green card) status, your entire worldwide income is fully taxable to the US, no matter where in the world you live. Unlike all other developed nations, the US taxes not only on residency, but also on citizenship, and US LPRs are 'deemed' to be fully US taxable under citizenship-based taxation, even though not actually US citizens.

To free yourself from US tax as an LPR, you must generally affirmatively surrender your green card using USCIS Form I-407. If you do not do this, you remain a US taxable person even if your physical green card (and very probably also your US immigration status) has expired.

If you become a US citizen, and wish to free yourself from US tax, your only option is to renounce US citizenship.

In both cases, this may subject you to the US expatriation tax. This is an unpleasant tax that includes US capital gains tax on a 'deemed' disposition of assets with built-in gains, full and immediate US income tax on 'deemed' withdrawal of the value of any pensions and retirement savings (even when not actually withdrawn, and perhaps not even withdrawable, if non-US), and a harsh 40% transfer tax on any subsequent gifts or bequests to US persons.

Given the above, it is worth thinking very carefully indeed about whether or not becoming a green card holder or US citizen is a sensible move. If you are a temporary US resident, or if you do not plan to spend the rest of your life in the US, it may be better to stick to employment-based visas exclusively. Many US immigration professionals now recommend this, in preference to obtaining a green card.

Temporarily leaving the US
If you hold a green card, and intend to spend a period of several months outside the US, you may need to apply for a reentry permit. From USCIS:

"A lawful permanent resident (LPR) normally may travel outside the United States and return; however, there are some limitations. A reentry permit can help prevent two types of problems: A reentry permit establishes that you did not intend to abandon status, and it allows you to apply for admission to the United States after traveling abroad for up to 2 years without having to obtain a returning resident visa. Reentry permits are normally valid for 2 years from the date of issuance." As noted above, your entire worldwide earnings and assets remain both taxable and reportable to the US. You may be able to claim tax treaty benefits to reduce any US tax, but doing so runs the risk of involuntary expatriation.
 * Your Permanent Resident Card becomes technically invalid for reentry into the United States if you are absent from the United States for 1 year or more.
 * Your U.S. permanent residence may be considered as abandoned for absences shorter than 1 year if you take up residence in another country.

Reentry permits are intended for temporary absence from the US, although there is no definition of temporary in the law or regulations surrounding them. They cannot be extended. You can apply for more than one, and must be physically present in the US to apply. There is no regulation that limits how many you can have, but issuance is at the discretion of the USCIS processing officer. Processing officers are required to assess the circumstances of an application, including any history of past applications.

Departing alien clearance
Non-US citizens who leave the US are technically required to obtain a departure permit (also called a sailing permit).

Obtaining this certificate requires filing one of the following forms:
 * Form 2063, U.S. Departing Alien Income Tax Statement. Requests IRS certification that all U.S. income tax obligations have been satisfied.
 * Form 1040-C, U.S. Departing Alien Income Tax Return. Reports income received or expected to be received for the entire tax year, with payment if required.

You cannot file these forms by mail or online, but only in person at selected IRS offices. Filing may require you to supply copious documents supporting all of your received and expected income for the year. Again technically, these forms apply not only to green card holders, but also to holders of a work visa such as H or L. Also, technically they apparently apply to any departure from the US, even temporary ones, for example a short vacation.

This is all technically. In practice, neither the IRS nor USCIS has enforced this requirement in decades, and compliance is virtually nonexistent. Nevertheless, a cautious green card holder (or even work visa holder) wishing to make a clean and entirely indisputable exit from the US might want to jump through this almost entirely pointless bureaucratic hoop.

Disconnecting from the IRS
If you surrender your green card, or renounce US citizenship, after leaving the US, you may be subject to the expatriation tax, discussed above. Otherwise, if you are in the US on a work visa such as H or L, the process is simpler and less costly.

For your final year in the US, you generally can (and often should) choose split year treatment, so that any income or other financial moves you make after leaving the US are not taxed by the US. The only time you might consider not using this is if you leave the US very close to or exactly at the end of the calendar year.

Leaving US accounts behind when you go
Once you are no longer a US taxable person, file a form W-8BEN with the provider for any US accounts that you leave behind when you depart the US. This will override the form W-9 you may have used to open the account, and will allow you to claim any applicable US tax treaty benefits relating to that account. You file these forms with the account providers, not with the IRS.

US taxable accounts
For any US based taxable accounts you hold, your likely best action is to close them and transfer the proceeds to your new country. If you do not do this, you risk substantial US estate taxes if your new country does not have a US estate tax treaty. And if your new country lacks a US income tax treaty, you will overpay US tax on dividends relative to holding non-US accounts.

Even for cases where there are good treaties in place, it will usually be much cleaner and easier to manage a local taxable portfolio than one now held in a foreign (to you) country.

US retirement accounts
If you have saved into a US based retirement plan, such as a 401k or IRA, you may face challenges managing it once no longer a US resident. For example, some or all of the following:
 * US provider restricting your trading, or restricting other account activity
 * US provider unilaterally closing your account entirely,
 * US provider failing to correctly apply US tax treaty withholding rates,
 * US provider withholding US tax on fully tax-free Roth withdrawals,
 * US provider incorrectly reporting US tax withholding amounts,
 * Perpetual risk of US estate taxes (except if covered by a US estate tax treaty ),
 * Potential higher US tax rates on withdrawals than those of US residents,
 * Potential home country tax annually on gains inside the pension, and
 * Political risk of future US tax laws that are hostile to US nonresident aliens.

Similar difficulties apply to any other US tax-advantaged accounts you might have acquired during your stay in the US, for example a Health savings account (HSA). While it may be possible to withdraw early from these accounts, there is generally a tax penalty for doing so.

If you do not plan on retiring in the US, you should consider very carefully whether it is sensible to participate at all in a 401k, IRA, HSA or any other US tax-advantaged account. It is however usually worthwhile to participate in an employer 401k at least up to the maximum employer match, provided this match more than offsets any early withdrawal penalty you might have to pay.

US social security
If you have paid US payroll tax (also known as FICA tax), you may be eligible for social security payments when you reach retirement age. Eligibility depends on having at least 40 credits. Typically, you gain this from 40 quarters of salaried work in the US. If you have fewer than 40 credits, it may be possible to have these credits applied to your non-US country's pension system, using a 'totalization agreement'.

US social security is payable to non-US residents and nonresident aliens, but there are restrictions for residents and citizens of some countries. In some limited circumstances, to remain eligible requires you to spend 30 days in the US every six months. US social security payments to all non-US residents are also subject to somewhat more onerous restrictions than payments made to US residents.

The 'Windfall Elimination Provision' (WEP) reduces US social security payments for individuals also eligible for pensions based on income that was not subject to US payroll tax. This is a particular problem if you are also eligible for any non-US pension payments, something that is quite likely if you earned locally pensionable income either before or after your time spent as a US taxable person.

Social security payments made by the US to nonresident aliens are subject to 30% US withholding tax on 85% of the amount paid, so 25.5%. A treaty may reduce this withholding rate, perhaps to 0%.

FIRPTA and selling your US home
If you own a home in the US, you should generally sell it before leaving the US, and while you are still a US taxable person. Otherwise, you face a potential large tax penalty from the US Foreign Investment in Real Property Tax Act (FIRPTA). This tax requires US nonresident aliens to pay US income tax rates on any gains in the value of US real estate, and so leaving you in a worse tax position that a similarly situated US citizen. Once you stop being a US taxable person, you become a US nonresident alien.

FIRPTA also applies a sizeable US tax withholding against the full proceeds of any sale of US real estate by a nonresident alien. The rate is generally 15% of the full property sale price, although some exceptions to this may apply. You will have to file a US 1040-NR nonresident alien tax return to recover any over-withheld amount.