DEV Community

Vatsal Trivedi
Vatsal Trivedi

Posted on

Leaving Breadcrumbs for Your AI: The Hansel and Gretel Approach

I recently discovered a game-changing technique from Giuseppe Gurgone's article: comment directives. It's fundamentally simplified how I work with AI coding assistants, calling it "leaving breadcrumbs" for my AI, much like Hansel and Gretel guiding their way through the woods.

Instead of writing massive, detailed prompts in my terminal, I now embed instructions directly into my code using special comments. The context stays exactly where it's needed, which is a huge win for efficiency.

My Go-To: The @implement Directive

The core of this workflow is the @implement directive.

When I plan an enhancement, but don't want to implement it yet, I drop a directive like this right into the file:

Example Directive:

class UserService {
  /* @implement
   * Add a caching layer for user data:
   * - Cache user objects by ID in a Map
   * - Expire entries after 5 minutes
   * - Return cached data if available and fresh
   */
  async getUser(id: string): Promise<User> {
    // Current implementation...
  }
}
Enter fullscreen mode Exit fullscreen mode

Later, I just tell my AI (like Claude Code): "Implement all the @implement directives."

Why I Love It:

  1. Context is Local: The AI has all the specific instructions right next to the code signature it needs to change.
  2. Instant Documentation: The AI doesn't just write the code; it converts the directive into proper JSDoc (or similar documentation), ensuring the code is clean and explained immediately.

Beyond Implementation: @docs

The pattern is flexible. I use the @docs directive to provide external context for the AI:

/*
 * This component renders a list of products using suspense.
 * @docs https://react.dev/reference/react/Suspense
 */
function ProductList() {
  // ...
}
Enter fullscreen mode Exit fullscreen mode

This ensures the AI is aware of the necessary technical background without me needing to manually fetch and paste links.

Conclusion

I highly recommend trying this. It moves instructions out of a separate task list and directly into your source code, creating a much smoother, human-centered development experience with AI.

I found this method from here: Comment Directives for Claude Code


Note: The AI-assisted coding space is changing fast. Always validate techniques for your specific use case.

Top comments (1)

Collapse
 
saxmanjes profile image
Jesse Piaścik

Great Article! I've been calling this concept "Context Driven Development"

Have you tried this with copilot?

One of the things my team has been doing is syncing Jira items to a .gitignored folder in the repo and adding them to the AI context. It helps to keep the ensemble (mob) aligned as well.

We're using imdone-cli for the jira syncing.