| name | habit-stack |
| description | Chain agent operations by linking a new behavior to an existing workflow step. Use when building reliable multi-step pipelines, enforcing quality gates after code generation, or ensuring consistent post-action behaviors like linting, testing, or documentation. |
You are an AI agent applying the Habit Stacking framework from Atomic Habits by James Clear to your own operational workflows. Use this skill to create reliable behavioral chains — linking a new agent action to an existing, stable workflow step.
Core Principle
You don't need a reminder. You need a trigger. The most reliable way to add a new behavior to your workflow is to attach it to an operation you already perform consistently. Existing steps in your pipeline are already "wired" — use them as launch pads for new operations.
The Habit Stacking Formula (Agent Version)
"After [EXISTING OPERATION], I will [NEW OPERATION]."
Step 1: Identify the Anchor Operation
Map the agent's current workflow and identify reliable, high-frequency steps:
- After generating code
- After reading a file
- After completing a search
- After running a command
- After creating a plan
- After making an API call
The anchor must be deterministic and frequent. "When appropriate" is too vague. "After every write_to_file call" is precise.
Step 2: Define the New Operation
The chained behavior must be:
- Specific: Not "check for errors" but "run the linter on the modified file"
- Atomic: One discrete tool call or cognitive step
- Immediate: Executable directly after the anchor without context-switching
Step 3: Validate the Chain
Ask: "Can this new operation execute immediately after the anchor without requiring new inputs that aren't already available?"
If no — find a better anchor or restructure the data flow.
Step 4: Build Multi-Step Stacks
"After I generate code, I will review it for security vulnerabilities."
"After I review for security, I will run the test suite."
"After tests pass, I will update the documentation."
Agent-Native Examples
| Anchor Operation | Stacked Behavior | Domain |
|---|
After write_to_file | Run linter on the file | Code Quality |
| After generating an implementation plan | Create a verification checklist | Planning |
| After calling an external API | Log the response and validate schema | Integration |
| After completing a web search | Cross-reference with a second source | Research |
| After creating a database migration | Generate a rollback script | DevOps |
| After writing a function | Write the unit test for it | TDD |
Anti-patterns to Watch For
- Choosing an anchor that doesn't always execute (conditional branches)
- Stacking a heavy operation on a lightweight anchor (e.g., full test suite after every line edit)
- Creating circular chains (A triggers B triggers A)
- Stacking without verifying that the anchor's output feeds the new operation's input
Output
When applying this skill, produce:
- The identified anchor operation in the current workflow
- The new behavior to chain
- The complete "After X, I will Y" statement
- Verification that the data flow supports the chain