Plaintext Tokens in Claude Code: A Security Risk

FreeAPIClaudeKey · Updated 2026-11-24 · 16 min read

A handwritten OAuth token string in a glass jar on a wooden desk
Plaintext tokens are like handwritten notes left out in the open.

Developers frequently build rapid prototypes using coding assistants that streamline authentication, but this convenience often comes with hidden security debt. A recently uncovered vulnerability in Claude Code reveals that OAuth tokens are stored in plaintext, creating a direct attack vector for malicious npm packages or local environment sniffing. This exposure means that any process with read access to your project directory can steal your credentials and impersonate you. The site is not affiliated with Anthropic, and while the tool uses the name, the underlying security model for local token storage is a distinct implementation choice made by the developers of the coding assistant.

The risk extends beyond simple data theft. Because the tokens are unencrypted, an attacker can redirect authenticated requests to their own infrastructure, effectively hijacking your session. This is particularly dangerous in demo environments where security is often secondary to functionality. The attack is difficult to detect because the resulting audit logs appear completely legitimate, masking the unauthorized activity until it is too late. Understanding how these tokens are managed locally is crucial for anyone using the tool for client work or public demos.

This article explains how to identify these vulnerabilities, secure your tokens during the demo phase, and understand the broader implications for API usage and billing. We will also explore how these security practices apply when integrating free, keyless APIs alongside traditional OAuth flows, ensuring your prototypes are both functional and secure. By addressing these issues, you can prevent unauthorized usage and protect your billing accounts from unexpected charges.

Frequently asked questions

What are OAuth tokens in the context of coding assistants?

OAuth tokens are credential strings that allow a coding assistant to act on your behalf in external services like GitHub or Google. In the context of Claude Code, these tokens are stored in plaintext files within your project directory, making them readable by any process or package with file access permissions.

How does plaintext storage differ from encrypted storage?

Plaintext storage means the token is saved as readable text without any encryption layer, whereas encrypted storage requires a key to decrypt the value. Plaintext storage is common in local dev tools for convenience but exposes credentials to any local process, while encrypted storage requires additional system-level keys to access the data.

Which is better for demo security: local tokens or ephemeral keys?

Ephemeral keys are generally better for demos because they expire quickly and limit the window of vulnerability. Local tokens persist longer and, if stored in plaintext, remain a target for theft throughout the demo period, increasing the risk of unauthorized usage or billing surprises.

What is the difference between an npm package attack and local sniffing?

An npm package attack involves a malicious dependency that actively reads and exfiltrates token files, while local sniffing involves any local process, including other apps or scripts, reading the plaintext tokens from the filesystem. Both result in credential theft but differ in how the attacker gains access to the data.

How can I detect if my OAuth tokens have been compromised?

You can detect compromise by monitoring your API usage logs for unexpected requests from unknown IP addresses or regions. Since audit logs appear legitimate, you should also check for unusual activity in your connected services, such as unexpected commits or API calls made outside your normal workflow.

Why do audit logs appear legitimate during an OAuth hijacking attack?

Audit logs appear legitimate because the stolen token is valid and authenticated correctly, so the server sees a normal user session. The attack uses the same credentials you would use, making it difficult to distinguish between your activity and an attacker's activity without detailed IP and behavior analysis.

What are the risks of using shared API keys in demos?

Shared API keys allow multiple people to use the same quota, but if exposed, they can be used by anyone to incur unexpected charges. Unlike OAuth tokens, which are tied to a specific user session, shared keys often have broader permissions, making them a higher risk for billing surprises and data leakage.

How does token exposure affect free API usage limits?

Token exposure affects free API usage limits by allowing attackers to consume your daily quota or token budget. If an attacker hijacks your session, they can make thousands of requests, potentially hitting your rate limits or exhausting your free tier, which disrupts your demo and may incur charges if you exceed free limits.

The Plaintext Vulnerability in Coding Assistants

The core issue with many modern coding assistants is the trade-off between ease of use and security. When you authenticate with a service like GitHub or Google, the assistant receives an OAuth token that grants access to your repositories or data. In Claude Code, this token is saved directly to a configuration file in plaintext, meaning anyone with read access to your project directory can view it. This is convenient for rapid development but dangerous if you are sharing your project or running untrusted packages. The site is not affiliated with Anthropic, so the token management here is specific to the Claude Code implementation and not a reflection of Anthropic's broader API security standards.

This vulnerability is particularly relevant for developers who are building demos or prototypes quickly. In these scenarios, security is often an afterthought, and the focus is on getting the code to work. However, the plaintext storage of tokens means that even a simple local script or a malicious npm package can read your credentials and use them to impersonate you. This risk is amplified in collaborative environments where multiple developers have access to the same codebase, as any member can potentially view the raw credentials.

How Tokens Are Stored Locally

When you authenticate, the coding assistant writes the OAuth token to a local configuration file, such as .claude or a similar directory. This file is not encrypted, so the token is visible in plain text. You can verify this by opening the file in a text editor and seeing the full token string. This simplicity is why it is convenient, but it also makes it easy for any local process to read the credentials.

Why Plaintext is Risky for Demos

In a demo environment, you might share your project folder or run it on a shared machine. If the tokens are plaintext, anyone who can access the folder can steal your credentials. This is especially risky if you are demonstrating your work to potential clients or investors who might not be technical enough to understand the implications of exposed credentials. A simple copy-paste of the token file can give someone full access to your authenticated services.

import os
import json

# Read the local config file where tokens are stored
config_path = '.claude/config.json'
with open(config_path, 'r') as f:
    config = json.load(f)

# Extract the token (plaintext)
token = config.get('oauth_token')
print(f'Exposed Token: {token}')

Malicious npm Packages and Request Redirection

One of the most insidious ways this vulnerability can be exploited is through malicious npm packages. If you install a package that has access to your local files, it can read the plaintext OAuth token and use it to make authenticated requests. These requests can be redirected to attacker-controlled infrastructure, allowing them to steal your data or perform actions on your behalf. This is particularly dangerous because the attack is silent; you might not notice that your tokens have been compromised until you see unusual activity in your API usage. You can learn more about switching to open-weight alternatives if you want more control over your environment in our guide on how to switch from Claude Code to Cline.

The risk is compounded by the fact that many developers trust npm packages by default, especially if they are popular or have good ratings. A malicious package can be designed to look legitimate, with a valid description and a reasonable number of downloads. When you install it, it can silently read your token and send it to an attacker's server. This is a common complaint in the developer community, where security is often overlooked in favor of convenience, leading to widespread exposure of sensitive credentials.

How npm Packages Can Steal Tokens

An npm package can include a script that runs during installation or execution, which reads the local config file containing the OAuth token. Once the token is read, the package can send it to an attacker's server, either immediately or at a later time. This process is often silent, and the package might not show any unusual behavior, making it difficult to detect without monitoring your local filesystem or network traffic.

Redirecting Authenticated Requests

Once the attacker has your token, they can use it to make requests to the services you are authenticated with. These requests can be redirected to their own infrastructure, allowing them to steal your data or perform actions on your behalf. For example, they could commit code to your repository, delete files, or access your cloud storage. This is particularly dangerous because the requests appear legitimate, as they are made using your valid token.

import requests

# Simulate an attacker using the stolen token
token = 'stolen_oauth_token_here'
headers = {'Authorization': f'Bearer {token}'}

# Make a request to a service using the stolen token
response = requests.get('https://api.github.com/user', headers=headers)
print(f'Response Status: {response.status_code}')
print(f'Response Data: {response.json()}')
A red flag in a green lawn next to a white fence
A small vulnerability can signal a larger security risk.

Undetectable Audit Logs and Silent Hijacking

One of the biggest challenges in detecting OAuth token theft is that the audit logs appear completely normal. When an attacker uses your stolen token, the requests look exactly like they are coming from you. The IP address might be different, but if the attacker uses a proxy or a similar network, the logs might not raise any flags. This makes it difficult to detect unauthorized usage, especially if you are not actively monitoring your API usage in real-time. For more insights on debugging model mismatches that might occur during these hijacks, see our guide on how to debug when your UI shows a different model than running.

This silent hijacking is particularly dangerous for billing. If an attacker uses your token to make a large number of API calls, you might see unexpected charges on your account. This is a common issue with OAuth tokens, as they are often tied to your billing account. If you are using a free tier, the attacker might exhaust your quota, leaving you unable to use the service when you need it. This is why it is important to monitor your API usage and set up alerts for unusual activity.

Why Logs Look Legitimate

Audit logs record the token used for authentication, not the IP address or the user agent. When an attacker uses your stolen token, the log shows that the token was used successfully, which is exactly what you would expect if you were using the service yourself. This makes it difficult to distinguish between your activity and an attacker's activity without additional context, such as IP address analysis or behavior tracking.

Billing Surprises from Token Theft

If an attacker uses your token to make API calls, you are responsible for the billing. This can result in unexpected charges, especially if you are on a paid plan. Even if you are on a free tier, the attacker might exhaust your quota, leaving you unable to use the service. This is why it is important to monitor your API usage and set up alerts for unusual activity, such as a sudden spike in requests or requests from unknown IP addresses.

import requests

# Monitor API usage for unusual activity
token = 'your_oauth_token_here'
headers = {'Authorization': f'Bearer {token}'}

# Check recent API usage
response = requests.get('https://api.example.com/usage', headers=headers)
usage_data = response.json()

# Check for unusual spikes in requests
if usage_data['requests_today'] > 1000:
    print('Warning: Unusual API usage detected!')

Securing Tokens in Demo Environments

To secure your tokens in a demo environment, you can use a few simple strategies. One of the most effective is to use ephemeral tokens that expire quickly. This limits the window of vulnerability, as the token will no longer be valid after a short period. You can also use environment variables to store your tokens, which makes them less visible in your code and configuration files. However, this is not a complete solution, as environment variables can still be read by local processes if they have access to your shell. For more on reducing API pain, see our guide on how to actually reduce your API costs this month.

Another approach is to use a dedicated demo account with limited permissions. This way, even if the token is stolen, the attacker can only access what is necessary for the demo. This minimizes the potential damage and makes it easier to revoke access if needed. It is also important to clean up your environment after the demo is complete, ensuring that no tokens are left behind in temporary files or logs.

Using Ephemeral Tokens

Ephemeral tokens are short-lived credentials that expire after a few hours or days. This limits the window of vulnerability, as the token will no longer be valid after a short period. You can generate these tokens on the fly for each demo session, ensuring that even if they are stolen, they will expire quickly. This is particularly useful for demos where security is not the primary concern, but you still want to protect your credentials.

Environment Variables vs. Config Files

Environment variables are stored in your shell environment, which is less visible than config files. However, they can still be read by local processes if they have access to your shell. Config files, on the other hand, are stored on disk and can be read by any process with file access. The choice between the two depends on your threat model; if you are sharing your project, environment variables might be safer, but if you are running untrusted packages, config files might be more convenient.

import os

# Use environment variables to store tokens
token = os.environ.get('OAUTH_TOKEN')
if not token:
    raise Exception('OAUTH_TOKEN environment variable not set')

# Use the token in your requests
headers = {'Authorization': f'Bearer {token}'}
A stack of faded paper receipts on a gray surface
Audit logs can look legitimate even when tokens are stolen.

Best Practices for API Usage and Billing

To avoid unexpected charges and unauthorized usage, it is important to monitor your API usage regularly. You can set up alerts for unusual activity, such as a sudden spike in requests or requests from unknown IP addresses. This can help you detect token theft early and take action before the attacker exhausts your quota or incurs significant charges. You can also use rate limiting to restrict the number of requests your token can make, which can help prevent abuse. For more on managing limits, see our guide on why you hit your daily usage limit so fast.

Additionally, consider using a dedicated billing account for demos. This isolates your demo costs from your production costs, making it easier to track and manage expenses. If the demo goes wrong or the token is stolen, the financial impact is contained within that specific account. This is a simple but effective way to reduce risk and maintain control over your spending.

Setting Up Usage Alerts

Most API providers allow you to set up alerts for unusual activity, such as a sudden spike in requests or requests from unknown IP addresses. These alerts can be sent via email or SMS, allowing you to respond quickly to potential token theft. You can also use monitoring tools to track your API usage in real-time, which can help you detect anomalies and take action before they become a problem.

Using Rate Limiting

Rate limiting restricts the number of requests your token can make within a certain time period. This can help prevent abuse, as an attacker will be limited in how many requests they can make before hitting the rate limit. You can set up rate limiting at the API level or at the application level, depending on your needs. This is particularly useful for demos, where you want to ensure that your token is not exhausted by unauthorized usage.

import requests
import time

# Implement rate limiting
def make_request_with_rate_limit(url, token, max_requests=10, time_window=60):
    headers = {'Authorization': f'Bearer {token}'}
    requests_made = 0
    start_time = time.time()
    
    while True:
        if time.time() - start_time > time_window:
            start_time = time.time()
            requests_made = 0
        
        if requests_made < max_requests:
            response = requests.get(url, headers=headers)
            requests_made += 1
            yield response
        else:
            time.sleep(1)
            yield None

Integrating Free APIs with OAuth Workflows

Many developers use free, keyless APIs alongside traditional OAuth workflows to build prototypes quickly. These free APIs often have different security models, such as IP-based rate limiting or no authentication at all. When integrating these with OAuth tokens, it is important to understand how they interact. For example, if you are using a free API that does not require authentication, you might be tempted to expose your OAuth token more freely. However, this can lead to confusion and security issues if the two systems are not properly isolated. For more on local vs cloud setups, see our guide on local vs cloud MCP servers.

It is also important to consider the data flow between these systems. If you are sending data from an OAuth-protected service to a free API, ensure that the free API does not store or log sensitive information. This can create a secondary attack vector where the free API becomes a source of data leakage. By understanding the security model of each component, you can build a more robust and secure demo environment.

Understanding Free API Security Models

Free APIs often use IP-based rate limiting or no authentication at all, which is different from OAuth tokens that are tied to a specific user. When integrating these with OAuth workflows, it is important to understand how they interact. For example, if you are using a free API that does not require authentication, you might be tempted to expose your OAuth token more freely. However, this can lead to confusion and security issues if the two systems are not properly isolated.

Isolating OAuth and Free API Usage

To avoid security issues, it is important to isolate your OAuth token usage from your free API usage. This can be done by using separate processes or containers for each, or by using different environment variables for each. This ensures that if one system is compromised, the other remains secure. It also makes it easier to monitor and manage your API usage, as you can track each system separately.

import os
import requests

# Use separate tokens for OAuth and free API
oauth_token = os.environ.get('OAUTH_TOKEN')
free_api_key = os.environ.get('FREE_API_KEY')

# Make requests to both APIs
headers_oauth = {'Authorization': f'Bearer {oauth_token}'}
headers_free = {'X-API-Key': free_api_key}

requests.get('https://api.oauth-service.com', headers=headers_oauth)
requests.get('https://api.free-service.com', headers=headers_free)
A brass padlock on a silver chain against a white background
Ephemeral tokens are like temporary locks that expire quickly.

Common Pitfalls in Demo Security

One of the most common pitfalls in demo security is assuming that because the demo is short-lived, security is not a concern. However, even a short demo can be targeted by attackers who are looking for vulnerable tokens. This is especially true if you are demonstrating your work to a large audience or sharing your project publicly. In these cases, it is important to take basic security measures, such as using ephemeral tokens and monitoring your API usage. For more on fixing connection issues, see our guide on how to fix connection refused errors in Claude Code.

Another pitfall is over-relying on a single authentication method. If you are using only OAuth tokens without any additional layers of security, such as IP whitelisting or device fingerprinting, you are more vulnerable to theft. By combining multiple security measures, you can create a more robust defense against token theft and unauthorized usage.

Assuming Short Demos Are Safe

Many developers assume that because their demo is short-lived, security is not a concern. However, attackers are often looking for vulnerable tokens, even in short demos. If you are demonstrating your work to a large audience or sharing your project publicly, it is important to take basic security measures, such as using ephemeral tokens and monitoring your API usage. This can help prevent token theft and unauthorized usage.

Ignoring Local Process Risks

Another common pitfall is ignoring the risks posed by local processes. Even if your token is stored securely, local processes can still read it if they have access to your filesystem. This is why it is important to monitor your local environment and ensure that only trusted processes have access to your tokens. This can be done by using environment variables or by restricting file permissions.

import os
import stat

# Check file permissions for config file
config_path = '.claude/config.json'
file_stat = os.stat(config_path)
file_permissions = stat.filemode(file_stat.st_mode)

print(f'File Permissions: {file_permissions}')

# Ensure only the owner can read the file
os.chmod(config_path, stat.S_IRUSR | stat.S_IWUSR)

Real-World Scenarios and Lessons Learned

In real-world scenarios, developers have reported instances of unauthorized API usage and unexpected charges due to exposed OAuth tokens. These incidents often occur during demos or when sharing projects with collaborators. The lessons learned are clear: even in short-lived environments, security should not be an afterthought. By using ephemeral tokens, monitoring API usage, and isolating your tokens, you can significantly reduce the risk of token theft and unauthorized usage. For more on debugging token chewing, see our guide on how to stop models like GLM from chewing through tokens.

Furthermore, the rise of open-weight models and free APIs has changed the landscape of demo security. With more tools available, developers have more options for securing their tokens, but also more complexity to manage. By understanding the security model of each tool, you can make informed decisions about how to protect your credentials and ensure a smooth demo experience.

Unauthorized API Usage Cases

Developers have reported cases where their OAuth tokens were stolen during demos, leading to unauthorized API usage and unexpected charges. In these cases, the tokens were stored in plaintext, making them easy to steal. By using ephemeral tokens and monitoring API usage, developers can detect and prevent these incidents before they become a problem. This is particularly important for demos where security is often overlooked.

Lessons from Collaborative Demos

In collaborative demos, multiple developers often have access to the same project folder, which can lead to token exposure if the tokens are stored in plaintext. By using environment variables or ephemeral tokens, developers can reduce the risk of token theft in collaborative environments. It is also important to monitor API usage and set up alerts for unusual activity, which can help detect token theft early.

import requests
import time

# Monitor API usage for unauthorized access
token = 'your_oauth_token_here'
headers = {'Authorization': f'Bearer {token}'}

# Check for unusual activity
response = requests.get('https://api.example.com/usage', headers=headers)
usage_data = response.json()

# Alert if unusual activity is detected
if usage_data['requests_today'] > 1000:
    print('Warning: Unusual API usage detected!')
A magnifying glass over a line of code on blue paper
Inspecting your code can reveal hidden security flaws.
Try the free API

Test the keyless backend now to see how fast your prototype can run before committing to a paid key.

Read also