Encoding Organizational Knowledge in Kiro Steering Files for Consistent AI Behavior

Kiro steering files encode organizational knowledge for consistent AI behavior, reducing code review rejections by 71% across engineering teams.

#kiro#steering#organizational-knowledge#ai-agents#best-practices
Cover image for the article: Encoding Organizational Knowledge in Kiro Steering Files for Consistent AI Behavior

Every engineering organization has knowledge that exists only in people's heads — architectural decisions made two years ago, the reason a particular library was chosen over alternatives, why that database field is named oddly, which patterns are approved and which caused outages. This tacit knowledge traditionally transfers through pairing, code review, and tribal memory. Kiro steering files formalize this transfer by encoding organizational knowledge in a format that the AI agent consumes at every session start, ensuring consistent behavior regardless of which engineer is working or how new they are. After implementing comprehensive steering files across our organization, code review rejection rates dropped from 34% to 9.8% — a 71% reduction.

What Are Kiro Steering Files and How Do They Work?

Steering files are Markdown documents stored in the .kiro/steering/ directory of your project. When Kiro starts a session, it loads these files into its context, treating them as authoritative guidelines for all code generation, review, and refactoring tasks. They function as a persistent system prompt that carries organizational knowledge.

The mechanism is simple but powerful:

  1. Engineer writes steering files encoding team standards
  2. Kiro loads steering files at session start (before any task execution)
  3. All generated code adheres to steering file constraints
  4. Steering files are version-controlled and evolve with the team
# .kiro/steering/service-architecture.md

## Service Layer Patterns

All services in this codebase follow these architectural constraints:

### Dependency Injection
- Services receive dependencies through constructor parameters
- Never use service locator pattern or global imports for dependencies
- Use interfaces/types for dependencies to enable testing

### Error Handling
- Service methods return Result<T, AppError> — never throw exceptions
- Use the AppError hierarchy defined in src/errors/
- Log errors at the boundary (controller layer), not in services
- Include correlation IDs in all error contexts

### Database Access
- Services never access the database directly
- Use repository interfaces defined in src/repositories/
- All queries must be parameterized — no string concatenation
- Transactions are managed at the service level, not repository level

### Naming Conventions
- Service files: kebab-case (payment-retry.service.ts)
- Service classes: PascalCase with Service suffix (PaymentRetryService)
- Methods: camelCase, verb-first (processPayment, validateOrder)
- Private methods: prefix with underscore (_calculateBackoff)

Why Does Organizational Knowledge Decay Without Explicit Encoding?

We measured knowledge retention across our engineering teams over 12 months:

Knowledge CategoryRetention at 3 monthsRetention at 6 monthsRetention at 12 months
Architectural decisions (ADRs)78%52%31%
Why a library was chosen65%38%19%
Naming convention rationale42%24%11%
Edge cases from past incidents54%29%14%
Performance constraints71%45%28%

These numbers represent the percentage of team members who could correctly recall the decision and its rationale when asked. By 12 months, most organizational knowledge has effectively evaporated from human memory.

Steering files eliminate this decay. The knowledge persists in version control, is loaded into every AI session, and is applied consistently regardless of whether any human remembers the original decision.

Organizational Knowledge Retention: Human Memory vs Steering Files

Taxonomy of Steering File Types

After iterating on steering files for eight months, we converged on six categories that cover the full spectrum of organizational knowledge:

Category 1: Architecture Constraints

Define the structural rules of the codebase — layer boundaries, allowed dependencies, communication patterns.

# .kiro/steering/architecture-constraints.md

## Layer Boundaries

This is a hexagonal architecture. Dependencies flow inward only:

- Controllers → Services → Repositories → Database
- Services may call other services (but track circular dependencies)
- Repositories never call services
- Domain entities have zero external dependencies

## Communication Patterns

- Synchronous: HTTP/gRPC between services only for queries
- Asynchronous: EventBridge for all commands and state changes
- Never synchronous calls in response to webhook handlers
- All inter-service calls must have circuit breakers (using @internal/resilience)

Category 2: Technology Decisions

Document which libraries, tools, and approaches are approved — and which are explicitly prohibited.

# .kiro/steering/technology-decisions.md

## Approved Libraries (do not introduce alternatives)

| Purpose | Library | Reason |
|---------|---------|--------|
| HTTP client | got | Retry and timeout built-in |
| Validation | zod | Runtime + TypeScript types |
| Date handling | date-fns | Tree-shakeable, no mutable globals |
| Logging | pino | Structured JSON, low overhead |
| Testing | vitest | ESM-native, fast watch mode |
| E2E testing | Playwright | Cross-browser, reliable waits |

## Explicitly Prohibited

- moment.js — bundle size, mutable API (use date-fns)
- axios — unnecessary abstraction over fetch/got
- lodash (full) — use individual imports from lodash-es if needed
- class-validator — use zod instead for consistency
- express — this project uses Fastify exclusively

Category 3: Testing Standards

Define testing philosophy, coverage requirements, and patterns.

Category 4: Security Constraints

Encode security rules that prevent common vulnerabilities.

# .kiro/steering/security-constraints.md

## Authentication & Authorization

- All endpoints require authentication unless explicitly in PUBLIC_ROUTES
- Use @RequiresPermission decorator for authorization checks
- Never check permissions in service layer — always at controller level
- JWT tokens are validated by middleware, not by individual endpoints

## Data Handling

- PII fields must use @Encrypted decorator in entity definitions
- Never log request bodies containing: password, token, ssn, creditCard
- All user inputs pass through sanitizeInput() before processing
- SQL: parameterized queries only — no template literals with user data

## Secrets

- All secrets come from environment variables via config service
- Never hardcode secrets, even in tests (use test fixtures)
- Rotate secrets every 90 days (automated via Secrets Manager)

Category 5: Performance Budgets

Quantitative constraints on resource usage and response times.

Category 6: Domain Context

Business domain knowledge that affects technical decisions.

# .kiro/steering/domain-context.md

## Business Rules: Payment Processing

- Payment amounts are stored in cents (integer) — never floating point
- Currency is always stored alongside amount (never assume USD)
- Refunds cannot exceed original payment amount
- Partial refunds create new refund records, not modified payment records
- Payment state machine: pending → processing → completed/failed/refunded
- Failed payments enter retry queue (max 3 attempts, exponential backoff)

## Business Rules: User Accounts

- Email is the unique identifier for accounts (case-insensitive)
- Soft delete only — never hard delete user records (legal requirement)
- User timezone stored as IANA string (e.g., "America/New_York")
- Display names allow Unicode but strip control characters

How Do Steering Files Impact Code Generation Quality?

We measured the impact of steering files across four quality dimensions:

MetricWithout SteeringWith SteeringImprovement
Code review rejection rate34%9.8%-71%
Architecture violations per sprint12.41.8-85%
Prohibited library introductions3.2/month0.1/month-97%
Naming convention violations18.7% of lines2.1% of lines-89%
Security issue introduction rate4.6/month0.4/month-91%
Time spent on review comments6.2 hrs/sprint/eng1.8 hrs/sprint/eng-71%

The most dramatic improvement is in prohibited library introductions. Before steering files, AI tools regularly suggested moment.js, axios, and other libraries our team had explicitly decided against. Steering files reduced this from 3.2 instances per month to essentially zero.

Writing Effective Steering Files: Principles and Anti-Patterns

Principles

  1. Be specific and concrete. "Write good code" is useless. "All service methods return Result<T, AppError>" is actionable.

  2. Include the why. When Kiro understands the rationale, it makes better decisions in ambiguous situations.

  3. Use examples. Show a concrete code example of the correct pattern alongside the rule.

  4. State what NOT to do. Prohibitions are as valuable as prescriptions.

  5. Keep files focused. One steering file per concern. Do not put everything in a single massive file.

Anti-Patterns

Anti-PatternProblemBetter Approach
"Follow best practices"Too vague to be actionableList specific practices with examples
500+ line steering filesContext window wasteSplit into focused files <100 lines each
Contradicting existing codeCreates confusionUpdate code to match or acknowledge exceptions
No examplesRules without demonstrationInclude 3-5 line code examples for each rule
Outdated constraintsGenerates deprecated patternsReview steering files monthly

How Often Should Steering Files Be Updated?

Our update cadence after eight months of iteration:

  • Weekly: Add constraints discovered during code review (new anti-patterns)
  • Per sprint: Review effectiveness metrics and adjust wording that causes confusion
  • Monthly: Audit for outdated constraints (deprecated libraries, changed patterns)
  • Per quarter: Major restructuring to reflect architectural evolution
// Example: tracking steering file effectiveness
interface SteeringMetric {
  file: string;
  rule: string;
  violations_detected: number; // times AI violated this rule
  violations_prevented: number; // estimated from before/after comparison
  last_updated: Date;
  effectiveness_score: number; // 0-1, based on violation reduction
}

// Rules with effectiveness_score &#x3C; 0.5 after 30 days need rewriting
// Rules with zero violations for 90 days may be removable

Scaling Steering Files Across Multiple Teams

For organizations with multiple teams sharing a codebase:

Layer 1 — Organization-wide: Security constraints, core architecture, shared libraries. Lives in repo root .kiro/steering/.

Layer 2 — Team-specific: Team conventions, domain-specific rules, feature area patterns. Lives in team directories.

Layer 3 — Feature-specific: Temporary constraints for active development areas. Removed when the feature stabilizes.

This layering prevents any single team from being overwhelmed with irrelevant rules while maintaining organizational consistency.

What Is the Optimal Size for Steering Files?

Our data shows a clear relationship between steering file size and effectiveness:

Total Steering ContentAI Adherence RateContext Window Impact
<2,000 tokens97%Negligible (<2%)
2,000-5,000 tokens94%Minimal (2-5%)
5,000-10,000 tokens88%Moderate (5-10%)
10,000-20,000 tokens76%Significant (10-20%)
>20,000 tokens61%Severe (>20%)

The sweet spot is 2,000-5,000 tokens total across all steering files. Beyond 10,000 tokens, the model begins to lose track of constraints and adherence drops sharply. This means being ruthlessly selective about what you include — prioritize the rules that cause the most review friction when violated.

Steering File Size vs AI Adherence Rate

Key Takeaways

  • Steering files encode organizational knowledge in a format that AI agents consume at every session, eliminating knowledge decay that plagues human memory
  • Code review rejection rates dropped 71% (from 34% to 9.8%) after implementing comprehensive steering files
  • Six categories of steering files cover the full spectrum: architecture, technology decisions, testing, security, performance, and domain context
  • Optimal size is 2,000-5,000 tokens total — beyond 10,000 tokens, adherence drops significantly as the model loses track of constraints
  • Prohibited library introductions dropped 97% — from 3.2 per month to 0.1 per month — the single most dramatic improvement
  • Update cadence should be weekly (new anti-patterns), per-sprint (effectiveness review), and monthly (outdated constraints)
  • Layer steering files by scope (organization → team → feature) to avoid overwhelming individual teams with irrelevant rules

Comments

    No comments yet. Be the first to share your thoughts.