---
title: "Is your Claude Code session getting heavy? Let a subagent dig for you"
description: "A Claude Code subagent is a specialized assistant that runs in its own context window, with a prompt and tools you choose. It does the long search and hands back the result, so your main conversation stays clean."
url: https://ihsanalapsi.dev/articles/claude-code-subagents
lang: en
date: 2026-11-13
updated: 2026-11-13
tags: ["AI", "Developer tools"]
author: Ihsan Alapsi (إحسان العبسي)
---
# Is your Claude Code session getting heavy? Let a subagent dig for you

You asked Claude Code to find where the activation email is sent in your project. It read many files, searched, and came back with the answer. But all that reading became part of the conversation, and an hour later the question you wanted to work on is buried under it. In this article you build a small helper that does that search somewhere else and hands you only the answer.

## What is a subagent in Claude Code?

A subagent is an AI assistant specialized in one type of task, running in its own context window, with its own system prompt and separate tools and permissions. Claude hands it the task, and it returns the result.

That definition comes from the [Claude Code subagents documentation](https://code.claude.com/docs/en/sub-agents), which lists what it gives you: it preserves the main conversation's context because exploration and implementation happen outside it, it enforces limits when you choose which tools it can use, it can be reused across your projects, it specializes through a focused prompt, and it controls costs when you route it to a faster, lower-cost model like Haiku.

In business-owner terms: you send a clerk to the archive to fetch a file, instead of going down yourself and turning over every shelf in front of the customer. The clerk comes back with the file, and the customer never sees the mess.

## Why does the context fill up without a subagent?

The context fills up because every file Claude reads and every search result is added to the same conversation. A subagent solves this because it reads in its own window and returns only the summary to the main conversation.

The simple mistake we all make: we treat the main conversation as both the desk and the storeroom. Every "find me" leaves a pile of reading behind that is no longer needed.

## Where do subagent files live?

Subagent files live in two places depending on who needs them: `.claude/agents/` inside the project for helpers specific to that codebase, and `~/.claude/agents/` in your home folder for helpers you want in all your projects.


| Location            | For                 | Priority |
| ------------------- | ------------------- | -------- |
| `.claude/agents/`   | the current project | higher   |
| `~/.claude/agents/` | all your projects   | lower    |


If two files share a name, the docs say Claude Code uses the one from the higher-priority location, which is the project one.

## How do you write a subagent file?

A subagent file is a Markdown file that starts with YAML frontmatter holding the settings, with the system prompt below it. The two required fields are `name` and `description`.

Here is a helper that searches the code and never edits anything, in `.claude/agents/code-finder.md`:

```markdown
---
name: code-finder
description: Finds where something happens in this codebase and reports file paths and line numbers. Use proactively for "where is" questions.
tools: Read, Grep, Glob
model: haiku
---

You search this codebase and answer one question: where does it happen?
Reply with a short list of file paths and line numbers, and one line on each.
Do not edit any file.
```

What each field means, according to the docs:

1. `name`: a unique identifier for the helper, such as `code-reviewer`.
2. `description`: when Claude should hand it the work. This is the most important line in the file.
3. `tools`: the tools it can use. If you leave it out, it inherits every tool available to subagents.
4. `model`: sonnet, opus, haiku, fable, a full model ID, or inherit.

In this example, `tools` holds only reading and search tools, so the helper has no tool that can edit a file at all, whatever the prompt says.

## How does Claude decide to hand it the task?

Claude decides to hand a task to a subagent based on your request, the subagent's `description` field, and the current context. That is why a clear description makes the difference.

The docs give two ways:

1. Automatically: a phrase like "use proactively" in the `description` encourages Claude to delegate to it on its own.
2. By name: you name the helper in your request, or type `@` and pick it from the list, the same way you pick a file.

## Where do you start now?

The lesson for us as developers: a task that reads a lot and comes back with two lines belongs in its own helper, not in your main conversation.

1. Pick a task you repeat: "where does this happen in the code", or "review this change".
2. Create a file in `.claude/agents/`, and write a `description` that says exactly when to use it.
3. Limit `tools` to what it needs, and pick a `model` that fits the task.
4. Call it by name the first time, then watch whether Claude starts delegating to it on its own.

If the helper reads content from outside, like web pages or files that are not yours, read about [prompt injection through agent tools](/articles/prompt-injection-agent-tools) before you give it more tools. All our AI articles are in one place: [AI articles](/articles?tag=ai). And if you want ready-made skills for coding agents, there is the [AI skills section](/products/c/ai-skills).

What task do you ask Claude Code for every day that you wish did not fill up the conversation?

## FAQ

**What happens if I leave tools out of the subagent file?**

The subagent inherits every tool available to subagents. If you want to limit it, list only the tools you want, like Read, Grep and Glob.

**I have a subagent with the same name in the project and in my home folder. Which one runs?**

The project one. According to the docs, when several subagents share a name, Claude Code uses the one from the higher-priority location, and .claude/agents/ in the project ranks above ~/.claude/agents/.

**Can I run a subagent on a cheaper model?**

Yes. The model field accepts sonnet, opus, haiku, fable, a full model ID or inherit, and the docs mention routing tasks to faster, lower-cost models like Haiku as a way to control costs.
