Tofie Dev Flow Automation #
Tofie is BonsAI’s automated development workflow system that connects Linear, n8n, GitHub, and Claude Code to streamline the software development lifecycle from planning to pull request submission.
Overview #
Tofie automates the entire development workflow by orchestrating multiple services:
- Linear - Project management and issue tracking
- n8n - Cloud automation and webhook orchestration
- GitHub - Code repository and pull request management
- Claude Code - AI-powered code generation and planning
- Coder Instance - EC2-based development environment with git worktrees
Quick Start #
For Team Members #
-
Create or find a Linear issue you want to work on
-
Mention Tofie in a comment with your request:
@Tofie plan this issue -
Wait for Tofie to respond - It will update the Linear issue status and add comments when complete
-
Review the generated plan in the Linear issue comments
-
Trigger implementation when ready:
@Tofie implement this -
Review the draft PR created by Tofie on GitHub
What Tofie Can Do #
| Command | Description | Linear Status Transition |
|---|---|---|
@Tofie plan |
Generate comprehensive implementation plan | Todo → Planning → Planned |
@Tofie implement |
Execute the plan and create code changes | Planned → In Progress → In Review |
@Tofie review |
Perform code review on changes | Any → Under Review |
@Tofie pr |
Submit pull request to GitHub | Any → PR Created |
Architecture #
graph TB
A[Linear Issue] -->|Webhook| B[n8n Automation]
B -->|SSH| C[Coder Instance]
C -->|Claude CLI| D[Claude Code]
D -->|Git Worktree| E[Isolated Branch]
E -->|Plan/Code| F[PLAN.md + Changes]
F -->|gh CLI| G[GitHub Draft PR]
G -->|Update| A
style A fill:#5e6ad2
style B fill:#ff6c5c
style D fill:#cc9b7a
style G fill:#238636
System Components #
-
Linear - Source of truth for issues and project management
- Issues contain requirements, comments, and acceptance criteria
- Webhooks notify n8n of comment mentions
- Status updates track workflow progress
-
n8n - Automation orchestrator
- Listens for Linear webhooks
- Parses Tofie commands from comments
- Executes Tofie scripts via SSH
- Updates Linear with results
-
Coder Instance - Development environment
- EC2 instance with main repository
- Git worktrees for isolated work
- Claude Code CLI installed
- All Tofie scripts and configurations
-
Claude Code - AI development assistant
- Generates implementation plans
- Writes code changes
- Reviews code quality
- Creates PR descriptions
-
GitHub - Code hosting and collaboration
- Receives pull requests from Tofie
- All PRs created as drafts
- Links back to Linear issues
Key Features #
Automated Planning #
- Comprehensive implementation plans using Context Engineering framework
- Analysis of Linear issue comments and requirements
- Risk assessment and success criteria
- Stored in
.plans/PLAN.mdwith Linear collapsible sections
Isolated Development #
- Each issue gets its own git worktree
- No interference with main branch or other work
- Clean separation of concerns
AI-Powered Implementation #
- Claude Code generates code following project patterns
- Respects existing architecture and conventions
- Runs quality checks (lint, format, tests)
- Creates conventional commit messages
Draft Pull Requests #
- All PRs created as drafts for review
- Generated PR descriptions reference the plan
- Links to Linear issue automatically
- Includes implementation summary and testing notes
Workflow Stages #
1. Planning Stage #
Trigger: User comments @Tofie plan in Linear issue
What Happens:
- Linear status →
Planning - n8n receives webhook
- Creates git worktree from
mainbranch - Generates
linear-metadata.jsonwith full issue context - Claude creates comprehensive
PLAN.md - Plan posted to Linear issue comments
- Linear status →
Planned
Output: .plans/PLAN.md with implementation roadmap
2. Implementation Stage #
Trigger: User comments @Tofie implement in Linear issue
What Happens:
- Linear status →
In Progress - Reads
PLAN.mdfrom planning stage - Claude implements changes following the plan
- Runs
mise fix && mise cifor quality checks - Creates conventional commits
- Linear status →
In Review
Output: Code changes committed to feature branch
3. PR Submission Stage #
Trigger: User comments @Tofie pr or automatic after implementation
What Happens:
- Reviews all commits on the branch
- Generates PR title (conventional commit format)
- Creates PR description referencing plan
- Submits draft PR to GitHub
- PR URL posted to Linear issue
- Linear status →
PR Created
Output: Draft PR on GitHub
Metadata Files #
Tofie creates metadata files in .plans/ directory (gitignored):
linear-metadata.json #
{
"branchName": "john/eng-1144-feat-add-filtering",
"issueIdentifier": "ENG-1144",
"agentSessionId": "session-abc-123",
"project": {
"id": "proj-123",
"name": "BonsAI Core",
"key": "ENG"
},
"issue": {
"id": "issue-456",
"identifier": "ENG-1144",
"title": "Add date range filtering to invoice list",
"description": "Full issue description...",
"comments": [...]
},
"createdAt": "2025-11-03T10:00:00Z",
"updatedAt": "2025-11-03T10:00:00Z"
}
n8n-metadata.json #
{
"event_server_url": "https://sample.app.n8n.cloud/webhook/tofie",
"signing_key": "your-actual-key-here",
"createdAt": "2025-11-03T10:00:00Z"
}
pr-info.json #
{
"prNumber": 123,
"prUrl": "https://github.com/globalbpo-ai/bonsai/pull/123",
"prTitle": "feat(webapp): add date range filtering to invoice list",
"createdAt": "2025-11-03T12:00:00Z"
}
Git Worktree Structure #
Tofie uses git worktrees for isolated development:
/home/coder/
├── bonsai/ # Main repository
│ └── tools/local/scripts/tofie/ # Tofie scripts
└── trees/ # Worktrees directory
├── john-eng-1144/ # Worktree for ENG-1144
│ ├── .plans/ # Gitignored planning artifacts
│ │ ├── PLAN.md # Implementation plan
│ │ ├── linear-metadata.json
│ │ ├── n8n-metadata.json
│ │ └── pr-info.json
│ └── [source code...]
└── jane-eng-2205/ # Another parallel worktree
├── .plans/
└── [source code...]
Security & Authentication #
SSH Access #
- n8n connects to Coder instance via SSH
- Uses SSH key authentication
- Limited to executing Tofie scripts only
GitHub Token #
- Stored in Doppler secrets management
- Retrieved via
doppler secrets get GITHUB_TOKEN - Required for PR creation via
ghCLI
Linear API #
- Webhook verification using signing keys
- API tokens for status updates and comments
- Stored securely in n8n credentials
Error Handling #
Script Failures #
- All scripts return JSON output with success status
- Errors logged to stderr (captured by n8n)
- Linear issue updated with error status
- n8n can retry failed operations
Timeout Handling #
- Planning: 30 minute timeout
- Implementation: 60 minute timeout
- PR submission: 10 minute timeout
- Long operations run in background on Coder instance
Recovery #
- Worktrees can be reused if they exist
- Scripts detect existing branches
- Can resume from any stage
- Manual intervention possible via Coder instance
Best Practices #
For Users #
- Write clear issue descriptions - Better input = better output
- Provide acceptance criteria - Helps Tofie understand success
- Add comments with context - Tofie analyzes all comments
- Review plans before implementation - Catch issues early
- Test draft PRs thoroughly - Tofie creates drafts for your review
For Maintainers #
- Keep scripts idempotent - Safe to run multiple times
- Use JSON for input/output - Structured data for n8n
- Log to stderr, output to stdout - Clean separation
- Update Linear status transitions - Keep users informed
- Handle edge cases gracefully - Existing branches, missing files, etc.
Common Issues & Solutions #
“Worktree already exists” #
- Tofie will reuse existing worktree
- To start fresh: manually remove worktree first
- Check:
git worktree liston Coder instance
“PR already exists for branch” #
- submit-pr.sh detects existing PRs
- Returns existing PR info without creating duplicate
- Safe to run multiple times
“PLAN.md not found” #
- Planning stage may have failed
- Check Linear issue for error messages
- Can manually run planning script
“Claude CLI permission issues” #
- Scripts use
--dangerously-skip-permissionsfor subagents - Required for automated file writes
- Safe in isolated worktree environment
Documentation #
- Architecture Details - Deep dive into system design
- Planning Workflow - Planning process details
- Implementation Workflow - Implementation process
- Script Reference - All Tofie scripts documented
- Troubleshooting Guide - Common problems and solutions
- n8n Setup - n8n workflow configuration
- Linear Integration - Linear webhooks and API
- GitHub Integration - GitHub PR automation
Support #
For questions or issues:
- Check Troubleshooting Guide
- Review Examples for common scenarios
- Ask in #tofie-support Slack channel
- Contact DevOps team for infrastructure issues
Version History #
- v1.0 (2025-11-03) - Initial release with planning and implementation
- v1.1 (2025-11-03) - Added Linear collapsible sections support
- v1.2 (2025-11-03) - Draft PR creation, existence checking