No history yet

Configuring Advanced Agent Behaviors

Fine-Tuning Your Agent

Once you've installed Claude Code, you can move beyond the defaults to configure how the agent behaves. This is done through a hierarchical settings system. Think of it like a set of cascading rules: global settings apply everywhere, project settings override the global ones for a specific repository, and local settings can override project settings for your personal machine without being checked into version control.

Configuration LevelFile PathScope
Global~/.claude/settings.jsonApplies to all projects on your machine.
Project.claude/settings.jsonApplies to a specific project. Overrides global settings.
Local Override.claude/settings.local.jsonOverrides project settings for your machine. Should be in .gitignore.

This structure lets you establish sane defaults globally while tailoring the agent's behavior for the unique needs of each project. Your local override is perfect for personal API keys or preferences you don't want to share with the team.

The Agent's Memory Bank

By default, a new Claude Code session has no memory of your project's architecture, style guides, or important files. You can fix this by creating a CLAUDE.md file in your project's root directory. This file acts as a persistent memory bank, automatically loaded into the agent's context at the start of every session.

Since Claude doesn't know anything about your codebase at the beginning of each session, you should use CLAUDE.md to onboard Claude into your codebase.

Use this file to provide high-level instructions, outline the project structure, define coding conventions, and list key commands. A well-crafted CLAUDE.md dramatically improves the agent's effectiveness, making it feel like a teammate who's already up to speed. This is the foundation for achieving consistent, high-quality results and enabling true agentic autonomy while the AI works on complex tasks.

# CLAUDE.md for our Python API

## Project Overview
This is a FastAPI-based web service for managing user profiles. The main application logic is in `app/main.py`. The database models are defined in `app/models.py`.

## Coding Style
- Follow PEP 8 guidelines.
- Use type hints for all function signatures.
- Keep functions under 50 lines.

## Key Commands
- To run tests: `pytest`
- To start the server: `uvicorn app.main:app --reload`

Tools and Permissions

Claude Code can execute shell commands, which gives it powerful capabilities but also introduces security considerations. To manage this, you can define a tool allowlist in your settings files. This specifies exactly which commands the agent is permitted to run, preventing it from executing potentially harmful operations.

Setting an allowlist is crucial for long-running tasks. It reduces permission friction by pre-approving safe commands like git, npm, or pytest, so the agent doesn't have to stop and ask for permission for every single action. You can set a strict global allowlist and then expand it with project-specific tools in the project's .claude/settings.json.

// In .claude/settings.json
{
  "tools": {
    "allowlist": [
      "git",
      "npm",
      "node",
      "pytest",
      "ls",
      "cat"
    ]
  }
}

Beyond the allowlist, you can also manage environment variables for the agent. This is useful for providing context-specific information that the agent might need, such as a development server's URL or a specific configuration flag. These variables are set within a shell object in your settings file and are scoped to the agent's execution environment.

Managing Secrets Safely

Never commit API keys, passwords, or other secrets directly into your configuration files. The secure way to provide these to Claude Code is through your shell's profile. By exporting them as environment variables in files like ~/.bash_profile, ~/.zshrc, or ~/.profile, you make them available to processes running in your terminal, including the Claude Code CLI, without hardcoding them.

# Example for ~/.zshrc or ~/.bash_profile

# Set your Anthropic API key
export ANTHROPIC_API_KEY="your-api-key-here"

# Set a key for another service the agent might use
export GITHUB_TOKEN="your-github-token-here"

After adding these lines, you'll need to restart your terminal or source the file (e.g., source ~/.zshrc) for the changes to take effect. The agent can then use these environment variables in its operations, keeping your sensitive credentials secure and off of any shared repositories.

Time to check your understanding of these advanced configuration concepts.

Quiz Questions 1/5

If a setting is defined in the global, project, and local configuration files for Claude Code, which one will take precedence?

Quiz Questions 2/5

What is the primary purpose of the CLAUDE.md file in a project's root directory?

By mastering these configuration layers, you can create a secure, efficient, and highly customized development environment for your AI agent.