When working on PRs, Claude Code was sometimes force pushing to branches. This adds simple git workflow guidelines that emphasize proper branch checkout and avoiding force pushes. ## Changes Added git workflow section to `CLAUDE.md`, `AGENTS.md`, and `.claude/docs/WORKFLOWS.md` with: - Instructions to fetch, checkout, and pull before working on PR branches - Note to avoid `git push --force` unless explicitly requested ## Examples of force push behavior Observed in recent PRs: - PR #21148: 7 commits including merge commit from iterative changes - PR #21150: 9 commits with multiple documentation iterations - PR #21182: 4 commits with iterative fixes - Force update on `feat/add-tasks-template-flag` branch: `9bf7980b9...f98cf44f7` The guidelines now make it clear to check out branches properly and push normally. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
9.0 KiB
Development Workflows and Guidelines
Quick Start Checklist for New Features
Before Starting
- Run
git pullto ensure you're on latest code - Check if feature touches database - you'll need migrations
- Check if feature touches audit logs - update
enterprise/audit/table.go
Development Server
Starting Development Mode
- Use
./scripts/develop.shto start Coder in development mode - This automatically builds and runs with
--devflag and proper access URL - ⚠️ Do NOT manually run
make build && ./coder server --dev- use the script instead
Development Workflow
- Always start with the development script:
./scripts/develop.sh - Make changes to your code
- The script will automatically rebuild and restart as needed
- Access the development server at the URL provided by the script
Code Style Guidelines
Go Style
- Follow Effective Go and Go's Code Review Comments
- Create packages when used during implementation
- Validate abstractions against implementations
- Test packages: Use
package_testnaming (e.g.,identityprovider_test) for black-box testing
Error Handling
- Use descriptive error messages
- Wrap errors with context
- Propagate errors appropriately
- Use proper error types
- Pattern:
xerrors.Errorf("failed to X: %w", err)
Naming Conventions
- Names MUST tell what code does, not how it's implemented or its history
- Follow Go and TypeScript naming conventions
- When changing code, never document the old behavior or the behavior change
- NEVER use implementation details in names (e.g., "ZodValidator", "MCPWrapper", "JSONParser")
- NEVER use temporal/historical context in names (e.g., "LegacyHandler", "UnifiedTool", "ImprovedInterface", "EnhancedParser")
- NEVER use pattern names unless they add clarity (e.g., prefer "Tool" over "ToolFactory")
- Abbreviate only when obvious
Comments
- Document exported functions, types, and non-obvious logic
- Follow JSDoc format for TypeScript
- Use godoc format for Go code
Database Migration Workflows
Migration Guidelines
-
Create migration files:
- Location:
coderd/database/migrations/ - Format:
{number}_{description}.{up|down}.sql - Number must be unique and sequential
- Always include both up and down migrations
- Location:
-
Use helper scripts:
./coderd/database/migrations/create_migration.sh "migration name"- Creates new migration files./coderd/database/migrations/fix_migration_numbers.sh- Renumbers migrations to avoid conflicts./coderd/database/migrations/create_fixture.sh "fixture name"- Creates test fixtures for migrations
-
Update database queries:
- MUST DO: Any changes to database - adding queries, modifying queries should be done in the
coderd/database/queries/*.sqlfiles - MUST DO: Queries are grouped in files relating to context - e.g.
prebuilds.sql,users.sql,oauth2.sql - After making changes to any
coderd/database/queries/*.sqlfiles you must runmake gento generate respective ORM changes
- MUST DO: Any changes to database - adding queries, modifying queries should be done in the
-
Handle nullable fields:
- Use
sql.NullString,sql.NullBool, etc. for optional database fields - Set
.Valid = truewhen providing values
- Use
-
Audit table updates:
- If adding fields to auditable types, update
enterprise/audit/table.go - Add each new field with appropriate action (ActionTrack, ActionIgnore, ActionSecret)
- Run
make gento verify no audit errors
- If adding fields to auditable types, update
Database Generation Process
- Modify SQL files in
coderd/database/queries/ - Run
make gen - If errors about audit table, update
enterprise/audit/table.go - Run
make genagain - Run
make lintto catch any remaining issues
API Development Workflow
Adding New API Endpoints
- Define types in
codersdk/package - Add handler in appropriate
coderd/file - Register route in
coderd/coderd.go - Add tests in
coderd/*_test.gofiles - Update OpenAPI by running
make gen
Testing Workflows
Test Execution
- Run full test suite:
make test - Run specific test:
make test RUN=TestFunctionName - Run with Postgres:
make test-postgres - Run with race detector:
make test-race - Run end-to-end tests:
make test-e2e
Test Development
- Use table-driven tests for comprehensive coverage
- Mock external dependencies
- Test both positive and negative cases
- Use
testutil.WaitLongfor timeouts in tests - Always use
t.Parallel()in tests
Git Workflow
Working on PR branches
When working on an existing PR branch:
git fetch origin
git checkout branch-name
git pull origin branch-name
Then make your changes and push normally. Don't use git push --force unless the user specifically asks for it.
Commit Style
- Follow Conventional Commits 1.0.0
- Format:
type(scope): message - Types:
feat,fix,docs,style,refactor,test,chore - Keep message titles concise (~70 characters)
- Use imperative, present tense in commit titles
Code Navigation and Investigation
Using LSP Tools (STRONGLY RECOMMENDED)
IMPORTANT: Always use LSP tools for code navigation and understanding. These tools provide accurate, real-time analysis of the codebase and should be your first choice for code investigation.
Go LSP Tools (for backend code)
-
Find function definitions (USE THIS FREQUENTLY):
mcp__go-language-server__definition symbolName- Example:
mcp__go-language-server__definition getOAuth2ProviderAppAuthorize - Quickly jump to function implementations across packages
-
Find symbol references (ESSENTIAL FOR UNDERSTANDING IMPACT):
mcp__go-language-server__references symbolName- Locate all usages of functions, types, or variables
- Critical for refactoring and understanding data flow
-
Get symbol information:
mcp__go-language-server__hover filePath line column- Get type information and documentation at specific positions
TypeScript LSP Tools (for frontend code in site/)
-
Find component/function definitions (USE THIS FREQUENTLY):
mcp__typescript-language-server__definition symbolName- Example:
mcp__typescript-language-server__definition LoginPage - Quickly navigate to React components, hooks, and utility functions
-
Find symbol references (ESSENTIAL FOR UNDERSTANDING IMPACT):
mcp__typescript-language-server__references symbolName- Locate all usages of components, types, or functions
- Critical for refactoring React components and understanding prop usage
-
Get type information:
mcp__typescript-language-server__hover filePath line column- Get TypeScript type information and JSDoc documentation
-
Rename symbols safely:
mcp__typescript-language-server__rename_symbol filePath line column newName- Rename components, props, or functions across the entire codebase
-
Check for TypeScript errors:
mcp__typescript-language-server__diagnostics filePath- Get compilation errors and warnings for a specific file
Investigation Strategy (LSP-First Approach)
Backend Investigation (Go)
- Start with route registration in
coderd/coderd.goto understand API endpoints - Use Go LSP
definitionlookup to trace from route handlers to actual implementations - Use Go LSP
referencesto understand how functions are called throughout the codebase - Follow the middleware chain using LSP tools to understand request processing flow
- Check test files for expected behavior and error patterns
Frontend Investigation (TypeScript/React)
- Start with route definitions in
site/src/App.tsxor router configuration - Use TypeScript LSP
definitionto navigate to React components and hooks - Use TypeScript LSP
referencesto find all component usages and prop drilling - Follow the component hierarchy using LSP tools to understand data flow
- Check for TypeScript errors with
diagnosticsbefore making changes - Examine test files (
.test.tsx) for component behavior and expected props
Troubleshooting Development Issues
Common Issues
- Development server won't start - Use
./scripts/develop.shinstead of manual commands - Database migration errors - Check migration file format and use helper scripts
- Audit table errors - Update
enterprise/audit/table.gowith new fields - OAuth2 compliance issues - Ensure RFC-compliant error responses
Debug Commands
- Check linting:
make lint - Generate code:
make gen - Clean build:
make clean
Development Environment Setup
Prerequisites
- Go (version specified in go.mod)
- Node.js and pnpm for frontend development
- PostgreSQL for database testing
- Docker for containerized testing
First Time Setup
- Clone the repository
- Run
./scripts/develop.shto start development server - Access the development URL provided
- Create admin user as prompted
- Begin development