claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

Feature Request: Command Pre-execution Dependencies (pre_commands)

Open kitaekatt opened this issue 3 days ago • 0 comments

Summary

Allow commands to declare a list of commands/skills that are automatically invoked before the command executes.

Problem

Currently, when a command requires certain skills or setup to be invoked first, there's no declarative way to specify this. Users must either:

  1. Remember to invoke prerequisites manually
  2. Instruct the model as part of the command to execute commands / invoke skills (but this is unreliable)

Sub-agents already support skills: in YAML frontmatter for auto-loading skills, but commands have no equivalent mechanism.

Proposed Solution: Pre-commands

Add a pre_commands: field to command YAML that executes a list of commands/skills before the main command:

pre_commands:
  - /issue-script-access
  - /setup-environment
instructions: |
  ...

Why Pre-commands Over Direct Skill Dependencies

A skills: field (matching sub-agent syntax) would only support skills. The pre_commands: approach is more general:

Approach Can invoke Flexibility
skills: Skills only Limited
pre_commands: Any command or skill General-purpose

Pre-commands enables:

  • Skill invocation (/my-skill)
  • Setup commands (/setup-env)
  • Chained workflows (/validate-config)
  • Future extensibility

Use Cases

  1. Gated operations: Commands that require disclosure/agreement skills before execution
  2. Environment setup: Commands that need specific context loaded first
  3. Workflow chaining: Multi-step workflows where order matters
  4. Reducing friction: Eliminate manual prerequisite invocation for predictable workflows

Current Workarounds

  • Instructions to the LLM within the command to invoke/execute skills/commands (unreliable)
  • Blocking hooks that instruct the LLM to execute commands / invoke skills (multiple tool calls)

Prior Art

  • Sub-agents support skills: in frontmatter for auto-loading (proves the pattern works)
  • Build systems (Make, Bazel) use dependency declarations
  • CI/CD pipelines use needs: / depends_on: patterns

Design Questions

  1. Failure handling: Should failures in pre-commands abort the main command?

    • Recommendation: Yes, fail fast with clear error message
  2. Circular dependencies: Should there be detection/prevention?

    • Recommendation: Yes, detect cycles and error with dependency chain shown
  3. Depth limit: Should nested pre-commands be allowed?

    • Recommendation: Allow 1-2 levels deep, prevent infinite chains

Example Usage

# commands/deploy.md
pre_commands:
  - /validate-config
  - /build-check
  - /deployment-access
instructions: |
  Deploy the application to the specified environment...

When user runs /deploy, the system would:

  1. Invoke /validate-config
  2. Invoke /build-check
  3. Invoke /deployment-access
  4. Execute the main deploy command instructions

kitaekatt avatar Jan 14 '26 20:01 kitaekatt