[FEATURE] Ability to run slash command in CLAUDE.md

Status Fixed / completed
Maintainer reply None cached
Activity 5 comments · opened Nov 25, 2025 · closed Nov 25, 2025

Preflight Checklist

  • [x] I have searched existing requests and this feature hasn't been requested yet
  • [x] This is a single feature request (not multiple features)

Problem Statement

Claude does not always follow instructions in the CLAUDE.md file (loading skills, incorporating validation into all workflows, etc...).

Claude hooks do not allow running custom slash commands within Claude.

I always have to remind Claude to run the critical workflow from the CLAUDE.md file so that it has the context it needs to proceed.

Example of the start of every Claude session I run:

> Have you run the critical workflow within CLAUDE.md?

● No, I haven't. Let me run the critical workflow now:
  ⎿  Allowed 1 tools for this command

● Read(.claude/hooks/auto-validate.md)
  ⎿  Read 233 lines

> /setup-claude is running…

> The "git-management-skill" skill is running
  ⎿  Allowed 1 tools for this command

● I'm running the critical workflow. Let me wait for the /setup-claude command to complete so it can prompt you about
  which project to work on.

  The git-management-skill has loaded and I can see from your current branch
  (cnatis/feature/my-awesome-feature-phase1) that you're working on a feature task with phases.
  The skills are now loaded.

  Once /setup-claude completes, I'll:
  - Confirm the project you're working on (appears to be plx-web based on your branch and file changes)
  - Load that project's CLAUDE.md
  - Load the project resources
  - Be ready to help with your work

Proposed Solution

I'd like for Claude to run slash commands in the CLAUDE.md file so that I do not have to remember to tell Claude to load critical context before working.
This should run on every new session, and when context is cleared (whenever CLAUDE.md is loaded).

Example CLAUDE.md file:

# Required Instructions

- Always be very concise!

## Workflow

- **CRITICAL**: Run SlashCommand(/setup-claude) command
- **CRITICAL**: Load the skill tool for all the skills listed in this file under the `Skills` heading
- **CRITICAL**: After completing significant work, automatically run validation (see Auto-Validation Hook below)

## Instructions

1. Run SlashCommand(/setup-claude) command to understand what project(s) we are working in
2. Make sure that all Skills under the `Reference -> Skills` heading below have been loaded
3. Read the auto validation hook under the `Reference -> Auto-Validation Hook` heading
4. Ensure that project resources have been loaded for the project(s) we are working in see `Reference -> Workspace Structure` to understand

Alternative Solutions

I have tried to use hooks, but they cannot run slash commands.
I have tried to have CLAUDE.md run the slash command, but it never does.

Current workaround is to remind Claude to run the critical workflow at the start of every session and whenever context is cleared.

Priority

High - Significant impact on productivity

Feature Category

Configuration and settings

Use Case Example

  1. I am working in a Claude workspace that shares a common Claude configuration across multiple sub repositories
  2. I start a new Claude session
  3. Claude instantly asks me for context (because thats what my slash command does), so that I can tell it what sub repository I am working in, so that it can load resources from that sub repository (each sub repository contains the same resource folder structure)

Additional Context

_No response_

View original on GitHub ↗

5 Comments

github-actions[bot] · 10 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/2735
  2. https://github.com/anthropics/claude-code/issues/10282
  3. https://github.com/anthropics/claude-code/issues/10808

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

JuanCS-Dev · 10 months ago

Feature Analysis: Auto-Execute Slash Commands in CLAUDE.md

This is a well-thought-out feature request. Here's the technical approach and implementation path.

Problem Validation

Pain point confirmed: Users must manually run setup commands every session.

Current workarounds:

  • ❌ Hooks can't run slash commands
  • ❌ CLAUDE.md instructions ignored by Claude
  • ✅ Manual reminder (current solution)

Proposed Solution: AutoExec Block

In CLAUDE.md:

# Project Configuration

<!--AUTOEXEC
/setup-claude
/skill load validation-expert
/skill load architecture-reviewer
-->

## Instructions
... rest of your file ...

Parsing logic:

// src/config/ClaudeMdParser.ts

interface AutoExecBlock {
  commands: string[];
  trigger: 'session_start' | 'context_clear' | 'both';
}

function parseClaudeMd(content: string): ClaudeMdConfig {
  const autoexecMatch = content.match(/<!--AUTOEXEC\n([\s\S]*?)\n-->/);
  
  if (!autoexecMatch) {
    return { autoexec: null };
  }
  
  const commands = autoexecMatch[1]
    .split('\n')
    .filter(line => line.trim().startsWith('/'))
    .map(line => line.trim());
  
  return {
    autoexec: {
      commands,
      trigger: 'both'  // Default: run on start and after /clear
    }
  };
}

Execution flow:

// src/session/SessionManager.ts

class SessionManager {
  async startSession() {
    // 1. Load CLAUDE.md
    const config = await loadClaudeMd();
    
    // 2. Execute autoexec commands
    if (config.autoexec) {
      for (const cmd of config.autoexec.commands) {
        await this.executeSlashCommand(cmd);
      }
    }
    
    // 3. Start normal session
    this.beginConversation();
  }
  
  async clearContext() {
    // When /clear is called
    this.messages = [];
    
    // Re-run autoexec
    const config = await loadClaudeMd();
    if (config.autoexec?.trigger !== 'session_start') {
      for (const cmd of config.autoexec.commands) {
        await this.executeSlashCommand(cmd);
      }
    }
  }
}

Security Considerations

Risk: Malicious CLAUDE.md could auto-execute harmful commands

Mitigation 1: Whitelist

// Only allow safe commands:
const SAFE_AUTOEXEC_COMMANDS = [
  '/skill',
  '/config',
  '/help',
  '/project'  
];

// Block dangerous ones:
const BLOCKED_COMMANDS = [
  '/exec',  // Arbitrary bash
  '/run',
  '/delete'
];

Mitigation 2: User Confirmation

Claude Code detected autoexec commands in CLAUDE.md:
  /setup-claude
  /skill load validation-expert

Execute these commands? [y/N]: _

Mitigation 3: Project Trust System

// src/security/ProjectTrust.ts

interface ProjectTrustLevel {
  path: string;
  trusted: boolean;
  autoexec_allowed: boolean;
}

// User must explicitly trust project:
$ claude --trust-project .
✓ Project trusted. CLAUDE.md autoexec will run automatically.

Alternative: Hook-Based Approach

Add new hook: SessionStart

# .claude/hooks/session-start.sh
#!/bin/bash

# This runs BEFORE first message
# Can execute slash commands via special syntax

echo "/setup-claude" >> $CLAUDE_COMMAND_QUEUE
echo "/skill load validator" >> $CLAUDE_COMMAND_QUEUE

Implementation:

// Queue commands from hook
const queue = readFile(process.env.CLAUDE_COMMAND_QUEUE);
for (const cmd of queue.split('\n')) {
  if (cmd.startsWith('/')) {
    await executeSlashCommand(cmd);
  }
}

Configuration Options

// ~/.claude/config.json
{
  "autoexec": {
    "enabled": true,
    "require_confirmation": true,  // Prompt before running
    "trusted_projects": [
      "/home/user/my-project"
    ]
  }
}

UI Feedback

When autoexec runs:

🤖 Auto-executing CLAUDE.md commands...
  ✓ /setup-claude
  ✓ /skill load validation-expert
  ✓ /skill load architecture-reviewer

Ready for input.
>

Related Feature: AutoLoad Resources

Extend to auto-load files:

<!--AUTOEXEC
/setup-claude
-->

<!--AUTOLOAD
docs/architecture.md
docs/api-spec.yaml
-->

Why this is powerful: Eliminates "context loading fatigue" entirely.

Implementation Priority

Phase 1: Basic autoexec with confirmation (1 week)
Phase 2: Project trust system (1 week)
Phase 3: Hook integration (1 week)
Phase 4: AutoLoad resources (2 weeks)

---

Verdict: This is a HIGH value feature for power users.
Suggest: Implement Phase 1 (basic autoexec) first, gather feedback, iterate.

cnatis · 10 months ago

https://github.com/anthropics/claude-code/issues/10808 is most similar to a solution that will work for my problem
@JuanCS-Dev please provide a feature analysis on https://github.com/anthropics/claude-code/issues/10808 since it will solve my problem and does not currently have a feature analysis

JuanCS-Dev · 10 months ago

@cnatis Done

github-actions[bot] · 10 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.