Path Inheritance
One of Porch’s most powerful features is its intelligent handling of working directories through path inheritance. This allows you to build complex workflows where commands naturally inherit and modify their working directory context.
How It Works
Porch uses a recursive dynamic programming approach to resolve working directories. Each command’s working directory is determined by combining its own working_directory setting with its parent’s resolved directory.
Resolution Rules
Porch resolves working directories using these rules:
- The top level workflow directory is “.”, the current directory where Porch is run.
- If the command’s
working_directoryis empty, it will use the parent’s resolved directory. - If the command’s
working_directoryis an absolute path, it will use that path directly. - If the command’s
working_directoryis a relative path and has a parent, it will be joined to its parent’s resolved directory.
This creates a hierarchical resolution system where child commands automatically inherit their parent’s working directory unless they specify otherwise.
Default Behavior: Relative Paths
By default, Porch uses relative paths for working directories. This means:
- Child commands inherit the parent’s working directory
- Relative paths are resolved against the parent’s directory
- The working directory “flows down” through the command hierarchy
Example: Relative Paths
In this example:
- The first command runs in
./project - The second command runs in
./project/packages/core - The third command runs in
.(going up two levels from./project)
Breaking Inheritance: Absolute Paths
If you specify a command with an absolute path, it will not inherit from the parent. The absolute path is used directly.
Example: Absolute Paths
In this example:
- First command: Uses
./frontend(inherited) - Second command: Uses
/home/user/projects/backend(absolute, breaks inheritance) - Third command: Uses
./frontend(back to inherited path)
Practical Examples
Monorepo Structure
Nested Serial Execution
Temporary Directory Workflow
Key Takeaways
- Relative paths are inherited: Child commands inherit parent’s working directory
- Absolute paths break inheritance: Use absolute paths when you need to “escape” the hierarchy
- Empty paths inherit: If you don’t specify a working directory, you get the parent’s
- Path joining is automatic: Relative paths are joined with parent’s path using
filepath.Join() - Resolution is recursive: The algorithm walks up the command tree to resolve the final path
This design makes it easy to:
- Build hierarchical workflows with natural directory context
- Override paths when needed with absolute paths
- Keep workflows portable using relative paths
- Avoid repetitive path specifications