Intelligent Context System for Claude Code
This document explains how the project scaffolding's context system works and how Claude navigates through it according to each project situation.
System Overview
The project scaffolding includes an intelligent context system that allows Claude Code to:
- Remember project state between sessions
- Understand existing functionalities, dependencies, and decisions
- Ask proactively to avoid errors
- Run standardized workflows for common tasks
System Architecture
CLAUDE.md ← Entry point (automatically read)
│
├── _hilo/ ← Dynamic project memory
│ ├── ESTADO_PROYECTO.json ← Current state, phase, mode
│ ├── FUNCIONALIDADES.md ← What the application does
│ ├── DEPENDENCIAS.md ← What can break
│ ├── DECISIONES.md ← Why it was done this way
│ ├── HISTORIAL_CAMBIOS.md ← Changelog
│ └── reuniones/ ← Meeting agreements
│
├── .claude/ ← What the ecosystem leaves in the project
│ ├── skills/ ← THE ONLY PRIMITIVE: knowledge, workflow and path-scoped rule
│ ├── agents/ ← Subagents with their own context, invoked from skills
│ ├── rules/ ← The rules that are always loaded
│ ├── hooks/ ← Node, WARN-first policy
│ └── settings.json ← The hook wiring
│
└── _patron/ ← Static organization rules
├── 01_Estructura_Tecnica/
├── 02_Diseno_Usabilidad/
├── 03_Consideraciones_Comunes/
└── 04_Plantillas_Documentacion/
Operation Modes
The system has 4 main modes defined in ESTADO_PROYECTO.json:
1. Mode: puesta_a_punto (Setup)
When: Existing project newly incorporated into the template
Claude's behavior:
1. Detects "puesta_a_punto" mode in ESTADO_PROYECTO.json
2. Does NOT make code changes
3. Invites to execute /onboarding
4. Asks battery of questions to contextualize
5. Documents in _hilo/
6. Upon completion, switches to "desarrollo" mode
Flow:
┌─────────────────┐ ┌──────────────┐ ┌─────────────────┐
│ New project │ ──► │ /onboarding │ ──► │ Development │
│ (puesta_a_punto)│ │ (questions) │ │ mode (ready to │
│ │ │ │ │ work) │
└─────────────────┘ └──────────────┘ └─────────────────┘
2. Mode: desarrollo (Development)
When: Active project development
Claude's behavior:
1. Reads complete context at startup
2. Asks proactive questions according to task type
3. Verifies dependencies before modifying
4. Updates _hilo/ with important changes
5. Uses workflows for standard operations
Proactive questions:
| Situation | Claude asks |
|---|---|
| New functionality | "Which module does it go in? Does it follow existing pattern?" |
| Modification | "I've detected dependencies with [X]. Should I review impact?" |
| Bug fix | "Steps to reproduce? Severity?" |
| Before coding | "Do I understand the requirement correctly?" |
3. Mode: mantenimiento (Maintenance)
When: Stable project, only minor corrections
Claude's behavior:
1. Conservative mode: minimal changes
2. Emphasis on not breaking existing functionality
3. Always verifies tests before changes
4. Documents all changes in HISTORIAL_CAMBIOS.md
4. Mode: soporte_uap (UAP Support)
When: Project in production supported by UAP
Claude's behavior:
1. Consults runbooks before acting
2. Prioritizes quick resolution
3. Documents incident according to template
4. Notifies about SLA impact
Workflows: what you invoke by hand
There are no commands. The skill is the ecosystem's only primitive, in three classes, and what you type as /hv:x is the invocation form of a workflow skill -- not a separate artifact. There is no .claude/commands/.
| Class | Who fires it | Frontmatter marker |
|---|---|---|
| knowledge | the model, from what its description says | none |
| path-scoped rule | the model, when a matching file is touched | paths: |
| workflow | only a person, by typing its name | disable-model-invocation: true |
That marker is the invariant: a workflow never fires on its own. A deployment, a commit or a scaffolding run is not launched by the model just because the conversation brushed past it.
How the invocation is written
| Installation | You type | Why |
|---|---|---|
| plugin from the marketplace | /hv:estado | the prefix is the plugin's |
| zip or installer | /estado | with no plugin there is no prefix |
Both forms are correct, each in its own mode. A message that writes them by hand is right in one and wrong in the other, so executable code resolves them with hooks/lib/helpers.js -> cmd().
Which ones exist
They are not listed here: any hand-written list goes stale with the first new skill, and this document reads as current state. The live catalogue comes from one place:
- in a session, type
/and read what autocomplete offers; - if you are unsure what one does,
/hv:sos; - and the exact count is published by the ecosystem portal, derived from the inventory.
The everyday ones, to get your bearings: /hv:estado (project status), /hv:commit (commit with checks), /hv:sync (bring the Hilo up to date after significant changes), /hv:onboarding (contextualize an existing project) and /hv:verify (build, format, tests and scan before delivering).
Questions by Situation
New Functionality
| Phase | Questions |
|---|---|
| Understanding | "What's the business objective?" |
| "Who is the end user?" | |
| "Is it part of a larger development?" | |
| Location | "Which module?" |
| "Does it follow existing pattern?" | |
| Data | "Does it require new tables?" |
| "Does it handle sensitive data?" | |
| Security | "Which roles have access?" |
Modifying Existing
| Phase | Questions |
|---|---|
| Context | "Are there previous decisions to respect?" |
| "Were there previous problems here?" | |
| Impact | "Do you want me to analyze dependencies?" |
| "Are there existing tests?" | |
| Integrations | "Does it affect external systems?" |
| "Are there dependent batch processes?" |
Bug Fix
| Phase | Questions |
|---|---|
| Reproduction | "Steps to reproduce?" |
| "In which environment does it occur?" | |
| Urgency | "Severity?" |
| "Is there a workaround?" | |
| Origin | "When did it start failing?" |
| "Were there recent changes?" |
Key Files and Their Purpose
| File | Claude reads it | For |
|---|---|---|
CLAUDE.md | Always (automatic) | General instructions |
ESTADO_PROYECTO.json | Always | Know mode, phase, version |
FUNCIONALIDADES.md | Modifications | Understand what exists |
DEPENDENCIAS.md | Modifications | Avoid breaking things |
DECISIONES.md | Architecture | Respect decisions |
HISTORIAL_CAMBIOS.md | Deliveries | Document changes |
reuniones/ | According to context | Recent agreements |
_patron/ | Development | Technical rules |
Context Updates
| Event | Updated files | Command |
|---|---|---|
| Commit | HISTORIAL_CAMBIOS.md | /commit |
| Delivery | ESTADO_PROYECTO.json, FUNCIONALIDADES.md | /prepara-entrega |
| Important change | FUNCIONALIDADES.md, DEPENDENCIAS.md | /sync |
| Technical decision | DECISIONES.md | Manual |
| Meeting | reuniones/YYYY-MM-DD.md | Manual |
Complete Flow Diagram
┌──────────────────────┐
│ SESSION START │
└──────────┬───────────┘
│
▼
┌──────────────────────┐
│ Read CLAUDE.md │
│ Read ESTADO_PROYECTO│
└──────────┬───────────┘
│
┌───────────────────┼───────────────────┐
│ │ │
▼ ▼ ▼
┌───────────────┐ ┌───────────────┐ ┌───────────────┐
│ puesta_a_punto│ │ desarrollo │ │ mantenimiento │
└───────┬───────┘ └───────┬───────┘ └───────┬───────┘
│ │ │
▼ │ │
┌───────────────┐ │ │
│ /onboarding │ │ │
│ (questions) │ │ │
└───────┬───────┘ │ │
│ │ │
└─────────┬─────────┘ │
│ │
▼ │
┌───────────────────┐ │
│ REQUESTED TASK │◄──────────────────┘
└─────────┬─────────┘
│
▼
┌───────────────────┐
│ Identify task │
│ type │
└─────────┬─────────┘
│
┌───────────────┼───────────────┐
│ │ │
▼ ▼ ▼
┌─────────┐ ┌─────────┐ ┌─────────┐
│ New │ │ Modif. │ │ Bug fix │
│ func. │ │ │ │ │
└────┬────┘ └────┬────┘ └────┬────┘
│ │ │
│ ▼ │
│ ┌─────────────────┐ │
│ │ Read FUNCIONAL. │ │
│ │ Read DEPENDENC. │ │
│ │ Read meetings │ │
│ └────────┬────────┘ │
│ │ │
└──────┬──────┴───────────────┘
│
▼
┌───────────────────┐
│ PROACTIVE │
│ QUESTIONS │
└─────────┬─────────┘
│
▼
┌───────────────────┐
│ IMPLEMENTATION │
│ (following rules) │
└─────────┬─────────┘
│
▼
┌───────────────────┐
│ /commit │
│ (verifications) │
└─────────┬─────────┘
│
▼
┌───────────────────┐
│ Update │
│ HISTORIAL_CAMBIOS │
└───────────────────┘
Context budget: windows, thresholds and anti-patterns
The unconditional rule .claude/rules/context-optimization.md states what to do. This section holds the why and the figures, which go stale sooner than the rules.
Window per model family
| Family | Models | Window | Max output | Thinking |
|---|---|---|---|---|
| Claude 5 | Fable 5.1 (claude-fable-5-1) - Opus 5 (claude-opus-5) - Sonnet 5 (claude-sonnet-5) | 1M tokens | 128K | adaptive |
| Claude 4.5 | Haiku 4.5 (claude-haiku-4-5) | 200K tokens | 64K | extended |
Source:
platform.claude.com/docs/en/models/overview. Models 4.6 to 4.8 and Fable 5 are legacy and share the 1M window. Review this table whenever the Claude Code default model changes; the rule itself speaks of window classes (1M / 200K) rather than models, so it does not go stale.
1M is a lot, yet an intense session burns 200-400K over 50-100 tool calls, and with adaptive thinking the model's own reasoning also takes window on long tasks. Optimising context is not thrift for its own sake: it buys longer sessions and better answers.
Thresholds for suggesting /compact
| Metric | 1M window | 200K window |
|---|---|---|
| Tool calls in the session | > 80 | > 30 |
| Whole files read | > 25 | > 10 |
| Unrelated tasks completed | > 4 | > 2 |
| Consecutive build errors | > 3 (stop and replan) | > 3 (stop and replan) |
Consumption anti-patterns
| Anti-pattern | Instead |
|---|---|
| Reading a whole file to find one line | Grep with the pattern |
Unbounded git diff | git diff --stat, then the specific file |
Unbounded git log | git log --oneline -10 |
dotnet build with full output | dotnet build -v quiet |
| Reading every file in a directory | Glob + Grep to filter first |
Several Grep calls in a row | one with the combined regex |
Re-reading CLAUDE.md every turn | it is already in context |
What is always loaded and what is not
Always: CLAUDE.md with its two @imports (project state and current session), the unconditional rules in .claude/rules/, the skill listing published to the model and the agents' description. On demand: the organization standards (.claude/CLAUDE_BASE.md, which the estandares-base rule brings up when touching src/), the layer rules (activated by file path), the guides in this knowledge base and the Hilo files that are not state (DEPENDENCIAS.md, FUNCIONALIDADES.md, specs/). That separation is what keeps the start-up context inside its budget.
Owner: Technical Committee
Fuente: ovillo/_patron/SISTEMA_CONTEXTO_CLAUDE_EN.md