Try free

Last updated 13 October 2026

How to stop Claude Code from installing new packages

The risk of automatic dependency changes

Claude Code uses the Bash tool to execute commands directly in your terminal. When the agent encounters a missing library or a failing import, it often tries to fix the problem by running npm install or pip install. This behavior can lead to unexpected changes in your package-lock.json or requirements.txt files. It can also introduce security risks by downloading unvetted code into your development environment without your explicit review. You need to know how to stop the agent from taking these actions on its own to maintain a stable project.

The agent is designed to solve problems quickly and sees a missing package as a simple hurdle to clear. If you are in a permissive mode, the agent will modify your project manifest and install new software to reach its goal. This can break your local build or create conflicts with the dependency policy of your team. You must set clear boundaries to ensure the agent only uses the tools and libraries already present in your repository. Keeping your environment clean requires a combination of project instructions and technical configuration.

CLAUDE.md defines the project boundaries

The CLAUDE.md file is the primary place to store instructions for the agent. This file sits in the root of your repository and is read at the start of every session. You should add a dedicated section for environment constraints in this file. Use direct language to tell the agent that it must not install new packages. State that if a task requires a new dependency, the agent must stop and ask for your permission first. This provides a clear rule for the agent to follow during its planning phase.

You can be even more specific by listing the allowed package managers and their restricted uses. For example, tell the agent it can run npm test or npm start but never npm install. Because the agent consults CLAUDE.md frequently, these instructions act as a constant reminder of your project's limits. If you have a subdirectory with different needs, you can place another CLAUDE.md there to apply more specific rules to that part of the file tree. This layered approach helps manage complex projects with multiple environments.

Configure tool permissions in settings.json

The .claude/settings.json file allows you to set technical barriers for the agent. This file contains a permissions key where you can define how the agent uses specific tools like Bash. You can configure the agent to require manual approval for every command it wants to run. This forces the agent to pause and show you the exact string it intends to execute. If you see an install command in the prompt, you can deny the request and tell the agent to find a solution using existing libraries.

For your own local overrides, use the .claude/settings.local.json file. This is useful if you want to enforce stricter rules on your machine than those shared with your team in the main settings file. These JSON files are the source of truth for tool behavior. When the agent attempts to use the Bash tool, it checks these settings to see if it has the right to proceed without your intervention. By keeping these files updated, you ensure that the agent always operates within the safety limits you have established for your workstation.

Control flow with permission modes

Claude Code has four distinct permission modes that change how it interacts with your system. These modes are default, acceptEdits, plan, and bypassPermissions. You can cycle through these modes at any time inside a session by pressing Shift+Tab. To prevent unauthorized installations, the plan mode is the most effective choice. In this mode, the agent describes what it intends to do and which tools it wants to use, but it does not actually execute them. This gives you a chance to audit every step before any changes happen to your files or environment.

The default mode also provides a level of safety by asking for permission for sensitive actions. However, the plan mode is better when you are working on a task where you suspect the agent might try to be too helpful with dependencies. If the agent proposes a command that includes a package manager, you can provide feedback in the chat. Tell the agent to avoid that command and suggest an alternative path. This interactive loop keeps you in total control of the terminal while still benefiting from the agent's ability to plan and write code.

Visual monitoring with adhdTerminal

Monitoring multiple Claude Code sessions is difficult when they are hidden in different terminal tabs. adhdTerminal is a native app for macOS and Windows that solves this by displaying your sessions as tiles on a wall. It is made by MINDBALANCER OU and is not affiliated with Anthropic. Each tile has a color, a number, and a name, making it easy to identify different projects. If an agent starts a process like a package installation, the tile shows the status and the last few exchanges of the conversation. This visual feedback helps you catch an unauthorized installation quickly.

The app also shows whether a session is working, waiting for you, or idle. If a tile shows that it is stuck on a Bash command or waiting for permission, you can see exactly what the agent is trying to do without switching windows. Tiles reopen in the same place after a restart and resume the same session, which helps you maintain a consistent workflow across many repositories. This level of visibility prevents the agent from performing long and unmonitored tasks in the background while you are focused on a different part of your project.

Global safety via the user home directory

If you manage many different repositories, configuring each one individually is time consuming. You can set a global policy by creating a CLAUDE.md file in your ~/.claude/ directory. Instructions placed in this file apply to every session you start with the claude command on your computer. This is an excellent place to enforce a general rule against package installations. The agent combines these global instructions with any project-specific rules it finds in the local folder, ensuring that your preferences are always respected.

You can also place a global settings.json file in the same ~/.claude/ directory. This file can be used to set the default permissions for the Bash tool across all your projects. By setting a global requirement for manual approval of terminal commands, you create a safety net that protects you even when you are working in a new or unconfigured repository. This centralized configuration reduces the risk of human error and ensures that every agent session follows your security standards from the moment it starts.

Reviewing and cleaning the session state

If you suspect the agent has ignored your instructions and attempted an installation, you can use the /review and /status commands to investigate. The /status command shows the current state of the session and the environment. The /review command provides a summary of the actions the agent has taken so far. If you find that the agent has been repeatedly trying and failing to install a package, it may be consuming a large number of tokens. You can check the exact spend by using the /cost and /usage commands at any point during the session.

When a session becomes cluttered with error messages from failed installation attempts, the context window can fill up with irrelevant information. Use the /compact command to summarize the conversation and free up space. This removes the noise of the failed commands while keeping the important progress the agent has made on your code. If the environment has become too messy, you can use the /clear command to start over in the same folder with a fresh context. This is often faster than trying to undo multiple small changes to your dependency manifest.

Custom agents for restricted tasks

You can define custom subagents in the .claude/agents directory to handle specific parts of your development process. These subagents are markdown files that describe a specific persona and a set of constraints. By creating a subagent that is explicitly forbidden from using the Bash tool for package management, you add another layer of protection. When you invoke a subagent using the /agents command, it operates under the specific rules you have defined for it, which can be much stricter than your main session rules.

Subagents are particularly useful for tasks like code review or documentation where terminal access is rarely needed. You can give a subagent access to the Read and Glob tools but restrict its use of the Bash tool entirely. This ensures that the agent can see your code and understand the project structure without having the power to modify your environment. This isolation of concerns makes it safer to delegate work to the agent, as you know exactly what tools it has at its disposal for a given task.

Custom commands for controlled execution

The .claude/commands directory allows you to create custom slash commands that the agent can use. These are markdown files that define a specific action or workflow. Instead of letting the agent invent its own Bash commands to run your project, you can provide it with a pre-defined command that runs a safe version of your build script. This guides the agent toward the tools you trust and away from the raw terminal commands that might trigger an unwanted installation process.

By providing a structured interface through custom commands, you reduce the likelihood of the agent making mistakes in the terminal. You can also use the /terminal-setup command to verify that the agent understands your shell configuration and the boundaries of its current session. Combining these tools with the /permissions command allows you to audit and adjust the agent's capabilities on the fly. This level of granular control is the best way to ensure that Claude Code remains a helpful assistant rather than a source of environment instability.

Questions people ask

How do I stop the agent from running a specific command like npm install?

Use the .claude/settings.json file to configure the permissions for the Bash tool. Set the permissions to require manual approval so you can see every command before it runs. If the agent proposes an install command, you can deny it directly in the terminal.

What should I do if the agent keeps trying to install dependencies despite my rules?

Add a very strict instruction at the top of your CLAUDE.md file stating that package installation is forbidden. If the behavior continues, use the /compact command to clear the agent's memory of its previous attempts. This prevents the agent from getting stuck in a loop of trying to fix the same dependency error.

Can I lock the agent into plan mode for every session?

There is no permanent setting to lock the mode, but you can switch to it instantly by pressing Shift+Tab at the start of any session. This ensures the agent always explains its intended actions and tool uses before it executes them. This is the safest way to audit the agent's plans for your project environment.

Read next

More on claude code basics·All posts