# Patterns/state Machine

> State Machine Pattern pattern for C development

- Skill: `majiayu000/patterns-state-machine` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds add majiayu000/patterns-state-machine`
- Raw SKILL.md: https://api.skillmd.com/api/skills/majiayu000/patterns-state-machine/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: majiayu000 (https://skillmd.com/u/majiayu000)
- Updated: 2026-09-09
- Page: https://skillmd.com/skills/majiayu000/patterns-state-machine

---


# State Machine Pattern

Model system behavior as discrete states with defined transitions. Current state determines which actions are valid and what state comes next.

## ikigai Application

**Input parser:** Tracks escape sequence state (normal, escape, CSI, etc.) to interpret terminal input bytes.

**Streaming response:** States like idle → requesting → streaming → complete → idle.

**Implementation:** Enum for states, switch or function pointer table for transitions:
```c
typedef enum { STATE_IDLE, STATE_STREAMING, STATE_ERROR } stream_state_t;
```

**REPL states:** Input mode, scrolling mode, command mode.

**Benefit:** Complex input handling becomes manageable. Each state handles its valid inputs.

