Prompt-based continuous learning is a parameter-efficient approach for adapting large-scale language models (LLMs) to task sequences. However, existing methods mostly rely on task-aware inference and continuously increase task-specific prompts, leading to two major problems: (1) significant performance degradation relative to previous tasks under task-agnostic inference, and (2) limited scalability due to prompt memory accumulation as task sequences increase. In this paper, we present GRID, an integrated framework designed to address these issues. GRID integrates a decoding mechanism that utilizes representative inputs to improve backward transfer, automatic task identification, and constrained decoding. Furthermore, it employs a gradient-based prompt selection strategy to compress less informative prompts into a single aggregated representation, ensuring scalable and memory-efficient continuous learning. Extensive experiments on long-sequence and negative transfer benchmarks demonstrate that GRID improves average accuracy and backward transfer, achieves competitive forward transfer, and substantially reduces prompt memory usage.