> ## Documentation Index
> Fetch the complete documentation index at: https://kiro.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Managing assets with hooks

> We start automating common boilerplate tasks using Kiro hooks

This module assumes you have already launched the game locally, by
following [the setup instructions](https://kiro.dev/docs/guides/learn-by-playing/00-setup.md).

In previous modules we:

- [Wrote HTML and CSS to improve the homepage](https://kiro.dev/docs/guides/learn-by-playing/01-improve-the-homepage.md)
- [Fixed a physics bug in the core of the game's physics engine](https://kiro.dev/docs/guides/learn-by-playing/02-physics-bug.md)
- [Fixed an interactions bug through an logic refactor](https://kiro.dev/docs/guides/learn-by-playing/03-interactions-bug.md)
- [Did a DRY refactor across many components](https://kiro.dev/docs/guides/learn-by-playing/04-dry-code-refactor.md)
- [Built a more complex feature using specifications](https://kiro.dev/docs/guides/learn-by-playing/05-using-specs-for-complex-work.md)

Now we are going to use Kiro to setup an automation that will help 
remove boilerplate work involved with coding this game.

  
### Understand the problem

Open the file `client/src/systems/preloader-system.ts`.
    This file is a standalone system which ensures that all the
    game assets are preloaded prior to the game starting. It has 
    a few clever features like initiating the predownload while the
    user is still on the authentication screen, and detecting
    new assets to load via server events.
    
    But the preloader system also relies on a list of static assets
    that is imported from `/client/src/assets/index.ts`. The 
    preloader system is fully decoupled from the game components
    themselves. This is a clean design that ensures that individual
    game components don't have to manually implement calls to
    the preloader.

    However it introduces a potential issue: a developer could 
    add a new game component, with new asset(s), and forget to add them
    to the list of static assets for the preloader. Let's
    add an automated hook that can help avoid this, while also
    saving the game devs some time.

  
### Create an asset indexer hook

Click the ghost icon in your IDE sidebar to open the Kiro panel.
    Locate the "Agent Hooks" section and click the plus icon to
    start writing a new hook.

    Let's use a custom prompt for the hook. You can type in natural
    language to describe what you want to happen. For example:

    ```
    When a file is created in the assets folder, 
    ensure that the assets folder index.ts file is
    appropriately updated
    ```

    ![alt !!alt](https://kiro.dev/images/video-game-guide/create-hook.png)

    Kiro will expand your natural language query into an agent
    hook configuration for the behavior you described. The hook
    will be stored in your `.kiro/hooks` folder. It should
    look something like this:

    ![alt !!alt](https://kiro.dev/images/video-game-guide/asset-create.png)

    ```json
    ,
      "then": 
    }
    ```

  
### Create an asset removal hook

Now that we have an example template for an agent hook, you can also 
    create new hooks manually by just creating new files in the `.kiro/hooks` folder.

    Let's try this out by cloning the asset indexer hook and editing it into
    an asset removal hook. Copy the existing hook and paste it as `image-asset-remover.kiro.hook` with 
    content like this:

    ```json
    ,
      "then": 
    }
    ```

    ![alt !!alt](https://kiro.dev/images/video-game-guide/asset-delete.png)

    You should now have two hook configurations, and two hooks
    showing up under "Agent Hooks" in the Kiro panel.

  
### Test the hooks out

Drag and drop an image file into the `client/src/assets` folder.
    You will see the asset indexer hook go to work.

    ![alt !!alt](https://kiro.dev/images/video-game-guide/hook-run-create.png)

    Then delete that asset from the folder.

    ![alt !!alt](https://kiro.dev/images/video-game-guide/hook-run-delete.png)

    
**💡 Tip:** To view the agent messages for a hook, click the
      "Task list" button at the top of chat panel and click
      on an active "Current Task". Or you can click the 
      "History" button to go back and view the agent messages
      for a hook that has already completed.

In this module you learned how to create and configure agent hooks
to help automate common tasks in your project. These hooks
can be used both to save time, and increase accuracy of boilerplate
tasks.

Let's move on to the next task:

[Extending Kiro with MCP](https://kiro.dev/docs/guides/learn-by-playing/07-extending-kiro-with-mcp.md)
