Claude Code gives you two practical ways to understand what is filling your context window and to gather codebase context before a big change:
- The built-in
/context command, for inspecting Claude Code's context window.
- A custom
/analyze-context command you create yourself, for repeatable codebase analysis before a refactor or feature.
The built-in /context command
/context shows a live breakdown of what is currently filling your context window, grouped by category, along with optimization suggestions. It takes no arguments or flags.
/context
It accounts for the things that consume the window, including:
- System prompt — the always-loaded core instructions (you never see these directly).
- CLAUDE.md / memory — project and user memory files loaded at startup. Use
/memory to see exactly which files loaded.
- MCP tools — tool names (and, depending on
ENABLE_TOOL_SEARCH, schemas) from connected MCP servers.
- Skill / command listings — one-line descriptions of skills Claude can invoke.
- Conversation messages and file reads — your prompts, Claude's responses, and the contents of files Claude has read (file reads typically dominate usage).
Use it when responses start to feel sluggish, when you are deciding whether to run /compact or /clear, or when you want to understand why a session is approaching its limit. For the underlying model of how the window fills and compacts, see the context window documentation.
Related built-ins
/compact — summarizes the conversation to free space while preserving startup content (CLAUDE.md, memory, MCP tools reload automatically; the skill listing is the one exception). Claude Code also compacts automatically as you approach the limit.
/clear — resets the conversation.
/memory — shows which CLAUDE.md and auto-memory files loaded at startup.
Building a custom codebase-analysis command
Claude Code does not ship a command that auto-generates architecture reports, dependency graphs, or quality metrics. You can, however, create your own custom slash command that asks Claude to analyze a codebase the same way every time. Custom commands are user-created Markdown files — they are not built-in, and the quality of the output depends entirely on the prompt you write and what Claude can read in your repo.
Create a file at .claude/commands/analyze-context.md (project-scoped) or ~/.claude/commands/analyze-context.md (personal). The file name becomes the command name, so this file creates /analyze-context. Custom commands have merged into skills; a file under .claude/commands/ still works and supports the same frontmatter, while skills add optional features like supporting files and automatic invocation.
---
description: Analyze the architecture, patterns, and dependencies of a codebase area
argument-hint: [path]
---
Analyze the code under `$ARGUMENTS` (default to the repo root if empty).
Read the relevant files and report:
1. Tech stack and frameworks actually present (cite package manifests).
2. The architecture / layering you observe, with key directories.
3. Recurring patterns and conventions, with file references.
4. Internal coupling and any obvious refactor risks.
5. Where tests exist and where coverage looks thin.
Cite real files and line ranges. Do not invent metrics or numbers
you cannot derive from the code you actually read.
Invoke it with an optional path:
/analyze-context src/auth
The $ARGUMENTS placeholder is replaced with everything you type after the command name. You can also target a single argument with $0/$ARGUMENTS[0], or declare named arguments in frontmatter. See the arguments reference for the full substitution rules.
When to use which
- Reach for
/context to understand and manage token usage in the current session.
- Reach for a custom
/analyze-context command when you want a consistent, repeatable codebase walk-through before a refactor, when onboarding to an unfamiliar area, or before scoping a large change.
Because the custom command is just a prompt, its findings are Claude's reading of your code in that session — not a deterministic static-analysis tool. Treat metrics and recommendations it produces as Claude's assessment, and verify anything load-bearing against the actual source.