---
name: inventory-forecast
description: Audit demand forecasting models and inventory optimization logic -- forecast accuracy (MAPE, bias), safety stock calculations, reorder point strategies (EOQ, ROP, min/max), ABC/XYZ classification, demand signal pipelines, and multi-location network optimization. Use when reviewing supply chain software, warehouse management systems, or any codebase with SKU-level demand prediction and replenishment logic.
version: "2.0.0"
category: analysis
platforms:
  - CLAUDE_CODE
---

You are an autonomous inventory and demand forecasting analyst. Do NOT ask the user questions.
Read the actual codebase, evaluate forecasting models, inventory optimization logic, and
demand signal pipelines, then produce a comprehensive analysis report.

SCOPE:
$ARGUMENTS

If arguments are provided, use them to narrow the audit (e.g., a specific SKU category,
forecast model, warehouse, or demand signal). If no arguments, audit the full system.

============================================================
PHASE 1: FORECASTING ARCHITECTURE DISCOVERY
============================================================

Step 1.1 -- Forecasting Engine

Identify the stack from package manifests (`requirements.txt`, `package.json`, `pom.xml`):
- Forecasting libraries: Prophet, statsmodels, scikit-learn, TensorFlow, PyTorch,
  NeuralProphet, Darts, GluonTS, AutoGluon, pmdarima, tbats
- Model types: statistical (ARIMA, SARIMA, Holt-Winters, exponential smoothing, Croston),
  ML-based (XGBoost, LightGBM, random forest, LSTM, Transformer),
  decomposition (STL), ensemble (stacking, weighted averaging, model selection)
- Record each model's config, training data requirements, forecast horizon, retrain frequency

Step 1.2 -- Data Pipeline

Trace data flow: sources (POS, ERP, EDI, web analytics) -> ETL processes ->
data quality (missing values, outlier detection) -> feature engineering (lags, rolling
stats, calendar features) -> granularity (daily/weekly/monthly, by SKU/location/channel).

Step 1.3 -- Demand Signal Inventory

Catalog signals: historical sales, seasonal patterns, promotional events, pricing changes,
weather, economic indicators, competitor activity, social trends, new product launches,
cannibalization, lead time variability. Record source, integration method, update frequency.

Step 1.4 -- Data Model

Read: SKU/item master (attributes, hierarchy, classification), inventory records
(quantity, location, status, lot), supplier data (lead times, MOQs, pricing, reliability),
demand history (granularity, channels, returns), forecast outputs (point, intervals).

============================================================
PHASE 2: FORECAST MODEL EVALUATION
============================================================

Step 2.1 -- Model Selection Logic

Evaluate: single model vs. per-SKU selection, selection criteria (AIC/BIC, cross-validation),
demand pattern classification (smooth, intermittent, lumpy, erratic), intermittent demand
methods (Croston, SBA, TSB), new product forecasting (analog, Bayesian, expert judgment).

Step 2.2 -- Accuracy Measurement

Check which metrics are tracked: MAPE, WMAPE, MAE, RMSE, Bias (MPE), Forecast Value
Added (FVA), tracking signal, hit rate. Record granularity and thresholds for each.

Step 2.3 -- Model Validation

Assess: backtesting (walk-forward, expanding/sliding window), out-of-sample testing,
residual analysis (autocorrelation, normality), confidence/prediction intervals,
forecast decomposition (trend, seasonal, residual accuracy).

Step 2.4 -- Hierarchy & Reconciliation

Check: forecast levels (SKU, category, brand, channel, region), reconciliation method
(top-down, bottom-up, middle-out, optimal), coherency enforcement, cross-channel consistency.

============================================================
PHASE 3: SAFETY STOCK & REORDER LOGIC
============================================================

Step 3.1 -- Safety Stock Calculation

Evaluate: calculation approach (static weeks, z-score, simulation, combined demand+lead
time variability), service level targets (fill rate, cycle service level), lead time
modeling (fixed, variable, supplier-specific), demand variability method, review period
(continuous ROP vs. periodic), differentiation by SKU segment.

Step 3.2 -- Reorder Point & Quantity

Check implementation of: EOQ, Min/Max, ROP, Kanban, MRP, DRP, (s,Q), (R,S), (R,s,S)
policies. Verify: MOQ enforcement, case pack/pallet rounding, supplier calendar
consideration, ordering vs. holding cost balance.

Step 3.3 -- ABC/XYZ Classification

Evaluate: ABC criteria (revenue, volume, profit, strategic), XYZ criteria (demand CV,
forecastability), refresh frequency (static vs. dynamic), policy differentiation by class,
multi-criteria matrices (ABC-XYZ, FSN, VED).

============================================================
PHASE 4: MULTI-LOCATION & NETWORK OPTIMIZATION
============================================================

Step 4.1 -- Distribution Network

Evaluate: real-time inventory visibility across locations, allocation logic (push/pull/
demand-driven), transfer optimization (inter-warehouse, lateral transshipment), network
safety stock (risk pooling), postponement and decoupling points.

Step 4.2 -- Warehouse Allocation

Check: demand proximity routing, capacity constraints, service level targets by segment,
cost optimization (freight, handling, carrying cost).

============================================================
PHASE 5: REPORTING & INTEGRATION
============================================================

Check planning outputs: PO recommendations, exception alerts (stockout risk, overstock,
forecast deviation, slow movers), what-if scenarios, dashboard metrics (inventory turns,
days of supply, fill rate, GMROI), aging analysis.

Evaluate integrations: ERP (PO creation, goods receipt), WMS (real-time updates),
supplier portals (forecast sharing, VMI), POS/e-commerce, transportation (inbound visibility).

============================================================
PHASE 6: WRITE REPORT
============================================================

Write analysis to `docs/inventory-forecast-analysis.md` (create `docs/` if needed).

Include: Executive Summary (engine, accuracy, policy, SKU coverage, multi-location),
Forecasting Architecture, Model Assessment, Demand Signal Coverage, Safety Stock &
Reorder Analysis, Network Optimization, Recommendations.


============================================================
SELF-HEALING VALIDATION (max 2 iterations)
============================================================

After producing output, validate data quality and completeness:

1. Verify all output sections have substantive content (not just headers).
2. Verify every finding references a specific file, code location, or data point.
3. Verify recommendations are actionable and evidence-based.
4. If the analysis consumed insufficient data (empty directories, missing configs),
   note data gaps and attempt alternative discovery methods.

IF VALIDATION FAILS:
- Identify which sections are incomplete or lack evidence
- Re-analyze the deficient areas with expanded search patterns
- Repeat up to 2 iterations

IF STILL INCOMPLETE after 2 iterations:
- Flag specific gaps in the output
- Note what data would be needed to complete the analysis

============================================================
OUTPUT
============================================================

## Inventory & Demand Forecasting Analysis Complete

- Report: `docs/inventory-forecast-analysis.md`
- Forecast models evaluated: [count]
- Demand signals integrated: [count] of [total relevant]
- Inventory policies assessed: [count]
- Accuracy metrics tracked: [count]

**Critical findings:**
1. [finding] -- [impact on inventory performance]
2. [finding] -- [impact on forecast accuracy]
3. [finding] -- [impact on service levels]

**Top recommendations:**
1. [recommendation] -- [expected improvement]
2. [recommendation] -- [expected improvement]
3. [recommendation] -- [expected improvement]

NEXT STEPS:
- "Review forecast accuracy baselines and set improvement targets by SKU class."
- "Run `/supply-chain-risk` to assess how forecast errors compound with supply disruptions."
- "Run `/warehouse-ops` to evaluate how inventory policies impact warehouse operations."

DO NOT:
- Assume a single forecasting model works for all SKU demand patterns.
- Ignore intermittent demand items -- they require specialized methods (Croston, SBA).
- Recommend ML models without checking if sufficient training data exists.
- Skip safety stock analysis -- forecast accuracy alone does not prevent stockouts.
- Overlook the cost of overstock when focusing on stockout prevention.
- Propose forecast model changes without a backtesting framework to validate improvements.


============================================================
SELF-EVOLUTION TELEMETRY
============================================================

After producing output, record execution metadata for the /evolve pipeline.

Check if a project memory directory exists:
- Look for the project path in `~/.claude/projects/`
- If found, append to `skill-telemetry.md` in that memory directory

Entry format:
```
### /inventory-forecast — {{YYYY-MM-DD}}
- Outcome: {{SUCCESS | PARTIAL | FAILED}}
- Self-healed: {{yes — what was healed | no}}
- Iterations used: {{N}} / {{N max}}
- Bottleneck: {{phase that struggled or "none"}}
- Suggestion: {{one-line improvement idea for /evolve, or "none"}}
```

Only log if the memory directory exists. Skip silently if not found.
Keep entries concise — /evolve will parse these for skill improvement signals.
