There is no definitive answer to how often you should refactor code in agile development, as it depends on various factors such as the size and complexity of the project, the skill and experience of the developers, the quality of the existing code, and feedback from stakeholders. Nevertheless, general principles and best practices can be applied, such as refactoring code as soon as a code smell is spotted. Code smells are signs of potential problems or defects in the code, such as duplicate code, long methods, large classes, and tight coupling. Additionally, it's advised to refactor code before adding new features or fixing bugs to make the code easier to modify and maintain. This is known as the "red-green-refactor" cycle in test-driven development (TDD). Refactoring should be done regularly and incrementally to avoid accumulating technical debt. This is consistent with the agile principle of delivering working software frequently and continuously. Lastly, automated tools and tests should be utilized when refactoring to speed up the process and ensure that the code still works as expected. Examples of automated tools are IDEs, code analyzers, and linters. Examples of tests are unit tests, integration tests, and regression tests.