Skip to main content
This cookbook shows how to use SessionStart hooks to automatically prepare your development environment when Droid starts, saving time and ensuring consistency.

How it works

SessionStart hooks:
  1. Run at session start: Triggered when starting new sessions or resuming
  2. Load context: Add relevant project information to the conversation
  3. Setup environment: Configure paths, environment variables, tools
  4. Check dependencies: Verify required tools and packages are available
  5. Persist state: Set environment variables for the entire session

Prerequisites

Basic tools for automation:

Basic session automation

Load project context

Automatically provide Droid with project information. Create .factory/hooks/load-context.sh:
Add to .factory/hooks.json:

Setup development environment

Configure tools and paths automatically. Create .factory/hooks/setup-env.sh:

Advanced automation

Load recent Linear/GitHub issues

Provide Droid with context about current work. Create .factory/hooks/load-issues.sh:

Check and install dependencies

Automatically ensure dependencies are up-to-date. Create .factory/hooks/check-dependencies.sh:

Load custom project guidelines

Provide project-specific instructions automatically. Create .factory/AGENTS.md with project guidelines:
Create .factory/hooks/load-guidelines.sh:

Smart context based on Git branch

Load different context based on the current branch: Create .factory/hooks/branch-context.sh:

Real-world examples

Example 1: Monorepo workspace setup

Automatically switch to the right package: Create .factory/hooks/monorepo-setup.sh:

Example 2: Docker environment check

Ensure Docker services are running: Create .factory/hooks/check-docker.sh:

Best practices

1

Keep context concise

Only load essential information:
2

Cache expensive operations

Avoid repeated expensive checks:
3

Use DROID_ENV_FILE for environment

Persist environment variables correctly:
4

Handle missing tools gracefully

Check before using external commands:
5

Provide actionable suggestions

Tell users what to do next:

Troubleshooting

Problem: Too much information loaded Solution: Summarize and link to details:
Problem: Variables not available in Bash commands Solution: Verify DROID_ENV_FILE usage:
Problem: Session start takes too long Solution: Run expensive operations asynchronously:

See also