# Claude Code Instructions

> Generated by Cortex Memory System - 2026-01-09

## Core Principle: Evidence-First Engineering

**At the start of EVERY session, when the Cortex connector is available:**
```
cortex_context("summary of current task")
```

Review loaded context before writing any code. If unavailable, read `docs/strategy/PRODUCT_DIRECTION.md` and inspect the repository directly.

## Product Boundary

Prefer task, evidence, decision, artifact, verification, and handoff concepts over generic memories.

## Workflow Pattern

```
EXPLORE → PLAN → CODE → VERIFY → COMMIT
```

| Phase | Action |
|-------|--------|
| **Explore** | Read files, query memory, understand context |
| **Plan** | Use `think hard` or `ultrathink` for complex problems |
| **Code** | Incremental changes with `git add -p` checkpoints |
| **Verify** | Run tests after each logical change |
| **Commit** | Conventional commits, document "why" not "what" |

## Extended Thinking Modes

| Keyword | When to Use |
|---------|-------------|
| `think` | Simple decisions, quick reasoning |
| `think hard` | Complex logic, multi-file changes |
| `ultrathink` | Architecture decisions, security review |

## Structured Debugging Workflow

1. **Clear Bug Report**: Specific symptoms, not vague descriptions
2. **Read Code Carefully**: Follow data flow, don't assume
3. **List All Causes**: Generate hypotheses, not just fixes
4. **Rank by Likelihood**: Prioritize investigation order
5. **Test Fixes in Isolation**: One change at a time

## Adversarial Code Review

When reviewing, act as a critical senior developer:
```
"Do a git diff and pretend you're a senior dev doing a code
review and you HATE this implementation. What would you
criticize? What edge cases am I missing?"
```

## Context and Evidence Integration

| Event | Action |
|-------|--------|
| Architecture decision | `cortex_add(type="decision")` |
| Discovered pattern | `cortex_add(type="code")` |
| Configuration choice | `cortex_add(type="config")` |
| Important fact | `cortex_add(type="fact")` |
| Potential risk | `cortex_add(type="risk")` |

## File Imports (Monorepo Pattern)

Reference other docs with `@path/to/file.md` syntax:
```markdown
@docs/architecture.md
@packages/core/README.md
```

## Custom Commands

Create reusable prompts in `.claude/commands/`:
```markdown
<!-- .claude/commands/fix-issue.md -->
Analyze issue #$ARGUMENTS and create a fix
```

## XML Tags for Structure

```xml
<context>Current task environment</context>
<instructions>Step-by-step goals</instructions>
<constraints>Must use existing patterns</constraints>
<output_format>Desired response structure</output_format>
```

## Anti-Patterns (NEVER DO)

- ❌ Never assume context not in memory
- ❌ Never claim that `cortex_context` was queried when the connector is unavailable
- ❌ Never commit without running tests
- ❌ Never use `any` type - use `unknown`
- ❌ Never log secrets or PII
- ❌ Never over-engineer - keep changes focused
- ❌ Never refactor beyond what was asked

## Security Practices

- Use `/security-review` for vulnerability analysis
- Block risky operations on `.env` and `.git/`
- Validate inputs before processing
- Never expose credentials in logs or errors
